<!-- Lazu · Claude Code with a custom API: ANTHROPIC_BASE_URL setup · https://lazu.ai/blog/claude-code-custom-api -->

# Claude Code with a custom API: ANTHROPIC_BASE_URL setup

2026-09-30 · Lazu team

Short answer: set `ANTHROPIC_BASE_URL` to `https://api.lazu.ai` and `ANTHROPIC_AUTH_TOKEN` to your Lazu key, and Claude Code runs on pay-as-you-go API billing instead of a Claude subscription. You get the same key for GPT, Gemini and DeepSeek, and Lazu never trains on your data.

## The fast way: one line

In [Console › API Keys](https://lazu.ai/console/token), pick a key, click **Connect**, choose Claude Code and copy the one-line script:

```bash
curl -fsSL https://api.lazu.ai/setup/claude-code | sh -s -- --model claude-sonnet-5-5 --opus claude-opus-5-5 --light claude-haiku-4-5-20251001
```

The script asks for the key in the terminal, so it stays out of your shell history. It writes `~/.claude/settings.json`, and the next Claude Code session picks it up. On Windows, use the PowerShell version in the same dialog.

## Manual setup

Add an `env` block to `~/.claude/settings.json`:

```json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.lazu.ai",
    "ANTHROPIC_AUTH_TOKEN": "sk-lazu-...",
    "ANTHROPIC_MODEL": "claude-sonnet-5-5",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5-5",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5-5",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-4-5-20251001",
    "CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1",
    "CLAUDE_CODE_ATTRIBUTION_HEADER": "0"
  }
}
```

| Variable | What it does |
| --- | --- |
| `ANTHROPIC_BASE_URL` | Sends requests to Lazu. No `/v1`; Claude Code adds the path |
| `ANTHROPIC_AUTH_TOKEN` | Your Lazu key |
| `ANTHROPIC_MODEL` | The default model |
| `ANTHROPIC_DEFAULT_*_MODEL` | What `/model opus`, `/model sonnet` and `/model haiku` switch to, and which model runs background tasks |
| The last two | Compatibility settings the Connect dialog always writes; keep them. The first stops Claude Code from sending experimental beta headers, which some upstreams reject outright |

Shell `export` lines in `~/.zshrc` work too. `settings.json` has the advantage of applying only to Claude Code.

## Switching models with /model

With the three `DEFAULT_*` variables set, `/model opus` in Claude Code switches to `claude-opus-5-5`. To use another version, such as `claude-fable-5-1`, change the matching variable. Every Claude model ID is in the [model catalog](/models).

## Saving with the discount lane

Claude models on Lazu have two lanes:

- **Stable lane**: runs on the official Anthropic API at the official list price, and suits every use.
- **Discount lane**: a reverse-engineered route. A third-party supplier serves the model through the official client; it is not the official API. It costs far less, and we recommend it only inside Claude Code. Availability varies, a failed request does not fall back to the stable lane, and the supplier may add its own system prompt.

You switch in the console, not in the config: edit the key and set the Claude model's lane to **Discount**. Keep your own code on the stable lane. Current prices on both lanes:


### [claude-sonnet-5-5](https://lazu.ai/models/anthropic/claude-sonnet-5-5)

USD per million tokens

| Lane | Input | Output | Cache read | Cache write 5m |
| --- | --- | --- | --- | --- |
| Anthropic official price | $2.00 | $10.00 | $0.20 | $2.50 |
| Lazu Stable · Same as official | $2.00 | $10.00 | $0.20 | $2.50 |
| Lazu Discount · −57% | $0.86 | $4.30 | $0.086 | $1.07 |

A dash means no price is recorded, not free usage. The request receipt is the final billing record.


### [claude-opus-5-5](https://lazu.ai/models/anthropic/claude-opus-5-5)

USD per million tokens

| Lane | Input | Output | Cache read | Cache write 5m |
| --- | --- | --- | --- | --- |
| Anthropic official price | $4.00 | $20.00 | $0.20 | $5.00 |
| Lazu Stable · Same as official | $4.00 | $20.00 | $0.20 | $5.00 |
| Lazu Discount · −57% | $1.72 | $8.60 | $0.086 | $2.15 |

A dash means no price is recorded, not free usage. The request receipt is the final billing record.

## Check that it works

```bash
claude -p "Introduce yourself in one sentence"
```

If it answers, you're connected. The console's usage log shows each request's model, lane, tokens and charge.

## Troubleshooting

**You were logged in with a Claude subscription**: run `/logout` in Claude Code first, so it doesn't keep sending requests on the subscription.

**401**: the key is wrong, or `settings.json` isn't valid JSON (a trailing comma is the usual culprit).

**400 about an unsupported beta**: check that `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS` is `"1"`.

**Model not found**: the ID is wrong, or the key is limited to other models.

## Next

- [Codex custom provider setup](/blog/codex-custom-provider)
- [Pricing and lanes](https://lazu.ai/docs/models/pricing)
- [Model catalog](/models)

