> ## Documentation Index
> Fetch the complete documentation index at: https://docs.inworld.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Use with Claude Code

> Route Claude Code requests through Inworld Router for failover, cost optimization, and observability

## Overview

[Claude Code](https://docs.anthropic.com/en/docs/claude-code) is Anthropic's agentic coding tool that runs in your terminal. By routing Claude Code through Inworld Router, you get automatic failover, cost optimization, and unified observability — all without changing how you use Claude Code.

## Why Route Claude Code Through Inworld Router?

* **Failover**: If Anthropic is rate-limited or down, Inworld Router automatically fails over to another provider.
* **Cost control**: Use `model: "auto"` with cost-optimized routing to reduce API spend on simpler coding tasks.
* **Observability**: Track all Claude Code requests, token usage, and costs in the Inworld Portal.
* **Multi-model access**: Use `auto` to let Inworld Router pick the best model, or route to OpenAI, Google, or other providers through the same Anthropic-compatible interface.

## Setup

Claude Code uses the Anthropic SDK under the hood. Redirect it to Inworld Router by setting environment variables.

Add these to your shell configuration file (e.g., `~/.zshrc` or `~/.bashrc`):

```bash theme={"system"}
export ANTHROPIC_BASE_URL=https://api.inworld.ai
export ANTHROPIC_AUTH_TOKEN=YOUR_INWORLD_API_KEY
```

<Note>
  `ANTHROPIC_AUTH_TOKEN` sends your key as `Authorization: Bearer`, which is how Inworld Router authenticates.
</Note>

Then reload your shell and run Claude Code:

```bash theme={"system"}
source ~/.zshrc
claude
```

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

### Per-Session Override

For a quick test without changing your global config:

```bash theme={"system"}
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 Router, you can override the model to use intelligent routing:

```bash theme={"system"}
claude --model auto
```

This lets Inworld Router select the best available model based on your routing configuration (cost, latency, or intelligence priorities).

## Using a Specific Model

You can route to any model supported by Inworld Router:

```bash theme={"system"}
# Use a specific Anthropic model
claude --model anthropic/claude-opus-4-6

# Use an OpenAI model through the Anthropic interface
claude --model openai/gpt-5

# Use a Google model
claude --model google-ai-studio/gemini-2.5-flash
```

## Using a Custom Router

If you've created a custom router (e.g., a cost-optimized or failover router), reference it by ID:

```bash theme={"system"}
claude --model inworld/failover-system
```

## Comparison: Anthropic Direct vs Inworld Router

| Feature               | Anthropic Direct            | Via Inworld Router                                                            |
| :-------------------- | :-------------------------- | :---------------------------------------------------------------------------- |
| **Base URL**          | `https://api.anthropic.com` | `https://api.inworld.ai`                                                      |
| **Models**            | Claude models only          | 50+ models across OpenAI, Google, Anthropic, Groq, and more                   |
| **Auto routing**      | Not available               | `model: "auto"` with configurable sort criteria (cost, latency, intelligence) |
| **Custom routers**    | Not available               | `model: "inworld/your-router"` with CEL conditions, variants, weights         |
| **Failover**          | None — single provider      | Automatic failover across providers                                           |
| **Observability**     | Anthropic Console           | Inworld Portal with routing metadata, attempt history, latency breakdown      |
| **Cost optimization** | Fixed pricing               | Dynamic routing to cheaper models for simple tasks                            |

## Verifying the Setup

To confirm Claude Code is routing through Inworld Router, check the Inworld Portal's **Observability** tab after making a request. You should see the request logged with routing metadata, including which model was selected and the latency breakdown.

## Troubleshooting

### "Unauthorized" errors

Ensure `ANTHROPIC_AUTH_TOKEN` is set to your **Inworld API Key**. You can find your API key in the [Inworld Portal](https://platform.inworld.ai) under **Workspace Settings** > **Integrations**.

### Model not found

Ensure you're using a valid model identifier:

* `auto` — Inworld Router 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

* [Anthropic Compatibility](/router/anthropic-compatibility) for full API reference and feature matrix.
* [Cost Optimizer](/router/guides/cost-optimizer) to reduce Claude Code API costs.
* [Failover System](/router/guides/failover-system) for high availability.
