Integrations
Use with Claude Code
Route Claude Code requests through Inworld Inference for fallbacks, routing by price or latency, and usage tracking in Portal
Overview
Claude Code is Anthropic's coding agent for the terminal. Route its requests through Inworld Inference to get fallbacks across providers and models, routing by price or latency, and per-model usage in Portal, without changing how you use Claude Code.
Why use Inworld Inference with Claude Code?
- Fallbacks: with a router that lists fallback models, or a bare model name that several providers serve, Inworld Inference tries the next model or provider when one fails. A
provider/modelID, such asanthropic/claude-opus-4-6, runs only on that provider. - Cost control: a router can pick models by price, or send simpler requests to cheaper models with conditional routing.
- Usage tracking: Claude Code's token usage appears per model in Portal under Manage > Usage, with estimated cost when your account shows costs. Enterprise accounts may see usage without costs.
- Multi-model access: use models from other providers, such as OpenAI or Google, through the same Anthropic-compatible interface.
Setup
Claude Code uses the Anthropic SDK. Set environment variables to send its requests to Inworld Inference.
Add these to your shell configuration file (e.g., ~/.zshrc or ~/.bashrc):
export ANTHROPIC_BASE_URL=https://api.inworld.ai
export ANTHROPIC_AUTH_TOKEN=YOUR_INWORLD_API_KEYClaude Code sends ANTHROPIC_AUTH_TOKEN as Authorization: Bearer <key>. Inworld Inference accepts your API key in a Bearer header as well as Basic, so no other setup is needed. Don't use ANTHROPIC_API_KEY.
Then reload your shell and run Claude Code:
source ~/.zshrc
claudeAll requests from Claude Code will now route through Inworld Inference.
Per-Session Override
For a quick test without changing your global config:
ANTHROPIC_BASE_URL=https://api.inworld.ai \
ANTHROPIC_AUTH_TOKEN=YOUR_INWORLD_API_KEY \
claudeUsing Auto Routing
By default, Claude Code sends requests to a specific Claude model. With Inworld Inference, you can override the model to use intelligent routing:
claude --model autoInworld Inference then picks from the whole catalog with its default ranking. Claude Code can't send the sort or models fields, so to rank models by price, latency or coding, or to limit the candidates, save those settings in a custom router and use it instead. See auto selection for the sort criteria.
Using a Specific Model
Pass any model ID from Inworld Inference as provider/model:
claude --model anthropic/claude-opus-4-6Models from other providers work the same way. Find their IDs in the model catalog or with the List models API: each model's id is the value to pass to --model. Claude Code calls /v1/messages and relies on tool calling, so choose a model whose endpoints includes /v1/messages and whose capabilities.functionCalling is true.
Using a Custom Router
If you've created a custom router (e.g., a cost-optimized or fallback router), reference it by ID:
claude --model inworld/failover-systemWhat works differently
Claude Code talks to Inworld Inference through the Anthropic-compatible Messages API, which translates each request for the selected model. Text, streaming, images, and the tools Claude Code runs itself are translated, so they work with any model that supports them. Some Anthropic-only features do not carry over:
-
Server tools: tools that Anthropic runs on its side, such as web search, are passed to the model as ordinary tools and are not run. Claude Code features that depend on them may not work.
-
Reasoning history:
thinkingblocks in earlier turns are dropped, so reasoning signatures do not carry across tool calls. -
Documents: PDF and other
documentblocks are dropped. -
Token counting: Claude Code also calls
/v1/messages/count_tokensto size its context, for example for/context. That endpoint needs a specific model, so withautoorinworld/<router-id>it returns an error, and Claude Code estimates the count locally instead. Requests still run, but the context numbers Claude Code shows are approximate. -
Context window: Claude Code knows the window of the Claude models it recognizes, including ids such as
anthropic/claude-opus-4-6. For any other model id, such asauto,inworld/<router-id>or a non-Claude model, it assumes 200K tokens and compacts the conversation there. If the model's window is smaller, a long session can exceed it before compaction starts, and requests can fail with a context-length error. SetCLAUDE_CODE_MAX_CONTEXT_TOKENSto the real window before you start Claude Code. Forautoor a router, use the smallest window among the models it can route to. Each model's window isspec.contextLengthin the List models response.bash export CLAUDE_CODE_MAX_CONTEXT_TOKENS=128000
See supported and unsupported features for the full list.
Comparison: Anthropic direct versus Inworld Inference
| Feature | Anthropic Direct | Via Inworld Inference |
|---|---|---|
| Base URL | https://api.anthropic.com | https://api.inworld.ai |
| Models | Claude models | Models from several providers. See the model catalog |
| Auto routing | Not available | --model auto with the default ranking, or a router that ranks by price, latency, coding and other criteria |
| Custom routers | Not available | --model inworld/<router-id>, with conditions, variants and weights |
| Fallbacks | Claude Code's own --fallback-model or fallbackModel setting: up to three Claude models, tried in order when the primary is overloaded or unavailable | Fallbacks on Inworld's side, across models and providers: fallback models from a router, or other providers of a bare model name. Claude Code's own fallback setting still works on top |
| Usage tracking | Anthropic Console | Portal Manage > Usage, per model |
| Thinking history, PDFs, server tools | Supported | Not carried over. See What works differently |
Verifying the Setup
To confirm Claude Code is routing through Inworld Inference:
- Run
/statusin Claude Code. Anthropic base URL should showhttps://api.inworld.ai. - Send a prompt, then open Manage > Usage in Portal. The model you used appears in the per-model usage.
Troubleshooting
"Unauthorized" errors
Ensure ANTHROPIC_AUTH_TOKEN is set to your Inworld API Key. Create a standard key, not a Realtime-only one, in Portal under Manage > API Keys, and copy its full credential with Copy key when it is created. See API keys.
ANTHROPIC_API_KEY is not supported: Claude Code sends it as an x-api-key header, which Inworld Inference does not read. If it is set, unset it and use ANTHROPIC_AUTH_TOKEN instead.
Model not found
Ensure you're using a valid model identifier:
auto— Inworld Inference selects the best modelanthropic/claude-opus-4-6— Specific model withprovider/modelformatinworld/your-router-id— Custom router
Connection issues
Verify the base URL is https://api.inworld.ai (no trailing slash, no path suffix).
Next Steps
- Anthropic Compatibility for full API reference and feature matrix.
- Cost Optimizer to reduce Claude Code API costs.
- Failover System for high availability.