Realtime TTS-2 is live. Built for realtime conversation that feels human. Read the Realtime TTS-2 announcement

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/model ID, such as anthropic/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):

bash
export ANTHROPIC_BASE_URL=https://api.inworld.ai
export ANTHROPIC_AUTH_TOKEN=YOUR_INWORLD_API_KEY

Claude 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:

bash
source ~/.zshrc
claude

All requests from Claude Code will now route through Inworld Inference.

Per-Session Override

For a quick test without changing your global config:

bash
ANTHROPIC_BASE_URL=https://api.inworld.ai \
ANTHROPIC_AUTH_TOKEN=YOUR_INWORLD_API_KEY \
  claude

Using 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:

bash
claude --model auto

Inworld 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:

bash
claude --model anthropic/claude-opus-4-6

Models 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:

bash
claude --model inworld/failover-system

What 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: thinking blocks in earlier turns are dropped, so reasoning signatures do not carry across tool calls.

  • Documents: PDF and other document blocks are dropped.

  • Token counting: Claude Code also calls /v1/messages/count_tokens to size its context, for example for /context. That endpoint needs a specific model, so with auto or inworld/<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 as auto, 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. Set CLAUDE_CODE_MAX_CONTEXT_TOKENS to the real window before you start Claude Code. For auto or a router, use the smallest window among the models it can route to. Each model's window is spec.contextLength in 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

FeatureAnthropic DirectVia Inworld Inference
Base URLhttps://api.anthropic.comhttps://api.inworld.ai
ModelsClaude modelsModels from several providers. See the model catalog
Auto routingNot available--model auto with the default ranking, or a router that ranks by price, latency, coding and other criteria
Custom routersNot available--model inworld/<router-id>, with conditions, variants and weights
FallbacksClaude Code's own --fallback-model or fallbackModel setting: up to three Claude models, tried in order when the primary is overloaded or unavailableFallbacks 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 trackingAnthropic ConsolePortal Manage > Usage, per model
Thinking history, PDFs, server toolsSupportedNot carried over. See What works differently

Verifying the Setup

To confirm Claude Code is routing through Inworld Inference:

  1. Run /status in Claude Code. Anthropic base URL should show https://api.inworld.ai.
  2. 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 model
  • anthropic/claude-opus-4-6 — Specific model with provider/model format
  • inworld/your-router-id — Custom router

Connection issues

Verify the base URL is https://api.inworld.ai (no trailing slash, no path suffix).

Next Steps