# Claude Code

NezhaGate serves the same Messages API as Anthropic, so Claude Code's tool use, thinking and prompt caching all work unchanged. Set two environment variables and start.

> https://nezhagate.com/en/docs/integrations/claude-code

## Before you start

- A NezhaGate API key (create one on the API Keys page of the console).

- Claude Code installed. If it is not, run this (Node.js 18 or later):

```
npm install -g @anthropic-ai/claude-code
```

## Step 1: set the environment variables

Set them in the terminal where you will run `claude`. `ANTHROPIC_AUTH_TOKEN` is your NezhaGate key; `ANTHROPIC_MODEL` is the model used by default.

```
export ANTHROPIC_BASE_URL=https://nezhagate.com/anthropic
export ANTHROPIC_AUTH_TOKEN=YOUR_API_KEY
export ANTHROPIC_MODEL=claude-sonnet-5
export ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-sonnet-5
claude
```

```
$env:ANTHROPIC_BASE_URL = "https://nezhagate.com/anthropic"
$env:ANTHROPIC_AUTH_TOKEN = "YOUR_API_KEY"
$env:ANTHROPIC_MODEL = "claude-sonnet-5"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL = "claude-sonnet-5"
claude
```

These last only for the current terminal; a new terminal needs them again. To make them stick, use settings.json in the next step.

## Step 2 (recommended): put them in settings.json

Write the same settings into Claude Code's user settings file and every terminal picks them up. The file is `~/.claude/settings.json` on macOS / Linux and `%USERPROFILE%\.claude\settings.json` on Windows; create it if it does not exist.

```
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://nezhagate.com/anthropic",
    "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
    "ANTHROPIC_MODEL": "claude-sonnet-5",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-sonnet-5"
  }
}
```

## Step 3: start and check

Run `claude` in your project folder, then type `/status` to see the current settings and check that the base URL is `https://nezhagate.com/anthropic`.

## Choose a model

Claude Code can only use Claude models (the /anthropic endpoint accepts Claude models only). Available now:

| Model ID | Input | Output | Cache read |
| --- | --- | --- | --- |
| `claude-sonnet-4-6` | $1.50 | $7.50 | $0.15 |
| `claude-opus-5` | $4.00 | $20.00 | $0.40 |
| `claude-fable-5` | $8.00 | $40.00 | $0.80 |
| `claude-sonnet-5` | $1.00 | $5.00 | $0.10 |

Prices in US dollars per million tokens.

Type `/model` followed by a model ID to switch during a session, for example `/model claude-opus-5`. Which model the Opus and Sonnet entries of the `/model` menu use is set by `ANTHROPIC_DEFAULT_OPUS_MODEL` and `ANTHROPIC_DEFAULT_SONNET_MODEL`.

### The background model

Claude Code hands small background jobs (such as naming a conversation) to a small model and asks for Claude Haiku by default. NezhaGate does not offer Haiku, so point `ANTHROPIC_DEFAULT_HAIKU_MODEL` at one of the models above, or those background requests come back 404.

## Billing and caching

Billed per token, at the same prices as the /v1 endpoints. Prompt-cache hits are billed at the cache-read price in the table above, far below the input price. Claude Code sends the same system prompt and project context every turn, so it usually hits the cache every turn.

## Common errors

**401 or "Invalid API key"**

The key is mistyped, has a stray space, or has been disabled. Check it in the console and set it again.

**404 "model: …"**

The model asked for is not on NezhaGate's list, most often the Haiku the background jobs ask for by default. Set `ANTHROPIC_MODEL` and `ANTHROPIC_DEFAULT_HAIKU_MODEL` as shown above.

**402 insufficient balance**

The account is out of balance, or the key has reached the budget you set. Top up in the console or raise the key's limit.

**The settings do not seem to apply**

Set the environment variables before starting `claude`, in the same terminal; after editing settings.json, restart Claude Code. `/status` shows the base URL in use.

**429 or "overloaded"**

Every line for this model is busy for the moment. Retry in a few seconds; nothing is billed.
