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

# Connect Claude Code through LiteLLM

> Use Claude Code with the Fortytwo API: Claude Code needs the Anthropic Messages API, so run a local LiteLLM proxy that translates it to Chat Completions.

[Claude Code ](https://code.claude.com/) speaks only the Anthropic Messages API. The Fortytwo API serves Chat Completions, so Claude Code connects through a local [LiteLLM ](https://docs.litellm.ai/) proxy that translates between the two. This setup needs Python, Node.js and a terminal. Anthropic does not support Claude Code with models other than Claude.

> [!NOTE]
>
> **Before you start:** create a Fortytwo API key and buy credits — see [Quickstart, step 1](https://docs.fortytwo.network/docs/quickstart.md#1-create-an-api-key). Give each agent its own key with a **Spend limit**.
>
> | Setting | Value |
> | - | - |
> | Base URL | `https://api.fortytwo.network/v1` |
> | Model ID | `qwen/qwen3.8-27b` in this guide, or another ID from [Models](https://docs.fortytwo.network/docs/models.md) |

**1. Install LiteLLM and Claude Code**

```bash theme={null}
pip install "litellm[proxy]==1.106.6"
npm install -g @anthropic-ai/claude-code
```

The LiteLLM version is pinned. Upgrade it on purpose: a new release can change how LiteLLM translates Messages requests.

**2. Configure LiteLLM**

Create `litellm.yaml`:

```yaml litellm.yaml theme={null}
model_list:
  - model_name: qwen/qwen3.8-27b
    litellm_params:
      model: custom_openai/qwen/qwen3.8-27b
      api_base: https://api.fortytwo.network/v1
      api_key: os.environ/FORTYTWO_API_KEY

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
```

Use the `custom_openai/` prefix: with `openai/`, LiteLLM sends Messages requests to the Responses API, which the Fortytwo API does not serve. The same file works for the [Codex guide](https://docs.fortytwo.network/agents/codex.md).

**The master key** is a password for your local LiteLLM proxy; LiteLLM does not start without it. You do not get it anywhere: **make up any string that starts with `sk-`, or let the command in the next step create a random one**. Claude Code sends it to LiteLLM; LiteLLM sends your Fortytwo key to Fortytwo.

**3. Start LiteLLM**

```bash theme={null}
export FORTYTWO_API_KEY="<your Fortytwo key>"
export LITELLM_MASTER_KEY="sk-$(openssl rand -hex 24)"
echo $LITELLM_MASTER_KEY
litellm --config litellm.yaml --port 4000
```

The `echo` line prints the master key: copy it for the next step. Keep this terminal open while you use Claude Code.

**4. Start Claude Code**

In a second terminal, in your project folder:

```bash theme={null}
export ANTHROPIC_BASE_URL="http://localhost:4000"
export ANTHROPIC_AUTH_TOKEN="<the master key from step 3>"
export ANTHROPIC_MODEL="qwen/qwen3.8-27b"
export ANTHROPIC_DEFAULT_OPUS_MODEL="qwen/qwen3.8-27b"
export ANTHROPIC_DEFAULT_SONNET_MODEL="qwen/qwen3.8-27b"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen/qwen3.8-27b"
export CLAUDE_CODE_SUBAGENT_MODEL="qwen/qwen3.8-27b"
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=262144
claude
```

* `ANTHROPIC_AUTH_TOKEN` replaces the sign-in: Claude Code does not ask for an Anthropic account.
* The `ANTHROPIC_DEFAULT_*` and `CLAUDE_CODE_SUBAGENT_MODEL` lines send Claude Code's background tasks and subagents to the same model. Without them, Claude Code asks LiteLLM for Claude models that it does not have.
* `CLAUDE_CODE_MAX_CONTEXT_TOKENS` sets the model's context window. Without it, Claude Code does not recognise the model and assumes 200,000 tokens.

*Another model works the same way: take its ID, context window and max output from [Models](https://docs.fortytwo.network/docs/models.md).*

On the first start, Claude Code asks for a text style and whether you trust the folder.

LiteLLM passes the model's reasoning to Claude Code as thinking. More options: [Claude Code LLM gateways ](https://code.claude.com/docs/en/llm-gateway), [LiteLLM: Claude Code with non-Anthropic models ](https://docs.litellm.ai/docs/tutorials/claude_non_anthropic_models).

***

Something not working with your agent, or using one we have not listed? Tell us in the platform: [Feedback](https://docs.fortytwo.network/docs/support.md#ideas-feedback-and-small-bugs) for ideas and small bugs, [Contact support](https://docs.fortytwo.network/docs/support.md#support-account-api-billing-credits-errors) if it blocks your work, or [Report a security issue](https://docs.fortytwo.network/docs/support.md#security-issue).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.