# Claude Code setup: point it at a custom Anthropic base URL

> Run Claude Code on prepaid credits: set ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN, pin Opus, Sonnet and Haiku model ids, then verify with /status.

Source: https://oneaiapikey.com/docs/guides/claude-code

Base URL: `https://api.oneaiapikey.com`

Claude Code speaks the Anthropic Messages API, and so does our gateway. That means no proxy scripts, no wrappers and no patched binaries: you set two environment variables and Claude Code sends its requests to us instead of to Anthropic. Usage is deducted from your prepaid balance at the published per-model rates.

## What you need

- Claude Code installed and working in your terminal (any recent version).
- An account with a positive balance (top-ups start at $3). [Create an account](https://oneaiapikey.com/console/sign-up) if you don’t have one.
- An API key from the [API keys page](https://oneaiapikey.com/console/keys). Keys start with `sk-`. Copy it once and keep it somewhere safe.

## Step 1: set the base URL and token

Claude Code reads `ANTHROPIC_BASE_URL` to decide where requests go and `ANTHROPIC_AUTH_TOKEN` for the credential, which it sends as an `Authorization: Bearer` header. Use the gateway origin **without** `/v1`: Claude Code appends `/v1/messages` itself.

Start with a quick test in a single terminal session:

macOS / Linux / Git Bash:

```bash
export ANTHROPIC_BASE_URL=https://api.oneaiapikey.com
export ANTHROPIC_AUTH_TOKEN=sk-your-key-here
```

Windows PowerShell:

```powershell
$env:ANTHROPIC_BASE_URL = "https://api.oneaiapikey.com"
$env:ANTHROPIC_AUTH_TOKEN = "sk-your-key-here"
```

Then run `claude` from that same terminal so it inherits the variables.

## Step 2: make it permanent with settings.json

Shell variables vanish when the terminal closes, and editors launched from a dock or Start menu never see them. For a setup that works everywhere, put the values in the `env` block of your user settings file: `~/.claude/settings.json` on macOS and Linux, `%USERPROFILE%\.claude\settings.json` on Windows.

~/.claude/settings.json:

```json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.oneaiapikey.com",
    "ANTHROPIC_AUTH_TOKEN": "sk-your-key-here",
    "ANTHROPIC_MODEL": "claude-sonnet-5",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5-5",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-4-5"
  }
}
```

If the file already exists, merge the `env` keys into it rather than replacing the whole file. When a shell variable and the settings file disagree, the settings file wins.

> Never put your key in a project’s `.claude/settings.json`. That file is usually committed to git and shared with everyone who clones the repository. Use the user-level file, or a project’s `.claude/settings.local.json` that is listed in your gitignore.

Using the Claude Code extension for VS Code? Add the same two variables under `claudeCode.environmentVariables` in your VS Code user settings, because the extension checks credentials there before it starts.

## Step 3: choose your models

`ANTHROPIC_MODEL` sets the default for the session. The three `ANTHROPIC_DEFAULT_*_MODEL` variables decide what Claude Code uses when you (or a sub-agent) pick the Opus, Sonnet or Haiku slot in `/model`. The Haiku slot also handles lightweight background work such as session titles, so pointing it at the fast model keeps those calls cheap.

Over the Anthropic route we serve Claude models only, which is also the only combination Claude Code is designed for. Current rates (USD per 1M tokens):

| Model id | Good for | Input | Output |
| --- | --- | --- | --- |
| `claude-opus-5-5` | Agentic coding, Large refactors, Complex reasoning | $4.40 | $22 |
| `claude-sonnet-5` | Daily coding, Code review, Writing | $2.20 | $11 |
| `claude-haiku-4-5` | Sub-agents, Extraction, Chat | $1.10 | $5.50 |

A practical default: Sonnet for everyday work, switch to Opus with `/model` for a hard refactor, and leave Haiku on background and sub-agent duty. See the full list on the [models page](https://oneaiapikey.com/models).

## Step 4: verify it works

First, test the key and URL directly, outside Claude Code. A JSON reply containing `"content"` means the gateway accepted your key:

curl:

```bash
curl -sS "$ANTHROPIC_BASE_URL/v1/messages" \
  -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"claude-haiku-4-5","max_tokens":16,"messages":[{"role":"user","content":"Say hi"}]}'
```

PowerShell:

```powershell
Invoke-RestMethod -Method Post -Uri "$env:ANTHROPIC_BASE_URL/v1/messages" `
  -Headers @{ "Authorization" = "Bearer $env:ANTHROPIC_AUTH_TOKEN"; "anthropic-version" = "2023-06-01" } `
  -ContentType "application/json" `
  -Body '{"model":"claude-haiku-4-5","max_tokens":16,"messages":[{"role":"user","content":"Say hi"}]}'
```

Then start `claude`, send any prompt, and run `/status`. The **Anthropic base URL** line should show `https://api.oneaiapikey.com`, and an **Auth token** line should name `ANTHROPIC_AUTH_TOKEN`. If both are there and the prompt got an answer, you’re done. Your console’s usage log will show the request within a few seconds.

## Troubleshooting

**401 Unauthorized.** The key is wrong, revoked, or was sent in a header the gateway didn’t expect. Re-copy the key from the console, check for stray spaces or quotes, and confirm you used `ANTHROPIC_AUTH_TOKEN`. If you set `ANTHROPIC_API_KEY` instead, Claude Code asks you once to approve it; a previously declined key is silently ignored until you enable it again under `/config`.

**Claude Code still asks me to log in.** The variables didn’t reach the process. Put them in `~/.claude/settings.json` (the user-level file is read before first-run setup) or export them in the same terminal you launch `claude` from. If you also have a saved claude.ai login, startup may warn about two credential sources: run `/logout` to use the gateway key only.

**404 or “not found” on every request.** Almost always a doubled path. `ANTHROPIC_BASE_URL` must be `https://api.oneaiapikey.com` with no trailing `/v1` and no trailing slash; otherwise requests go to `/v1/v1/messages`.

**Model not found / no available channel.** The id is misspelled or isn’t served on the Anthropic route. Use the exact ids from the table above, all lowercase. Non-Claude models (GPT, Grok, DeepSeek) are available through our OpenAI-compatible endpoint, not through Claude Code.

**Timeouts or a request cut off after about 100 seconds.** Claude Code streams by default, which keeps long generations alive. If you call the API from your own scripts, send `"stream": true` for long outputs; proxies along the way drop idle non-streaming requests at roughly 100 seconds.

**Out of balance.** Requests fail once credits hit zero. [Top up](https://oneaiapikey.com/console/billing) from the console; your keys and settings keep working, no restart needed.

## Next steps

Want to use the same key elsewhere? The [quickstart](https://oneaiapikey.com/docs/quickstart) covers raw API calls and SDKs, and the other [tool guides](https://oneaiapikey.com/docs/guides) cover OpenAI-format tools like Codex CLI and Cursor. Check current [pricing](https://oneaiapikey.com/pricing) before a long agentic session, and keep an eye on the usage log in the console.
