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

# Claude Code

> Use Anthropic's Claude Code CLI with Openference.

# Claude Code

Claude Code speaks the Anthropic Messages API (`POST /v1/messages`). Openference accepts **Bearer** authentication.

**Use `ANTHROPIC_AUTH_TOKEN`** — not `ANTHROPIC_API_KEY`, which sends an `x-api-key` header that Anthropic's API expects directly.

## Quick setup (shell)

```bash theme={null}
export ANTHROPIC_BASE_URL="https://api.openference.com"
export ANTHROPIC_AUTH_TOKEN="YOUR_API_KEY"
```

Claude Code appends `/v1/messages` to the base URL itself, so do **not** include `/v1` in `ANTHROPIC_BASE_URL` (otherwise requests go to `/v1/v1/messages` and fail). The settings.json example below follows the same convention.

Then run `claude` as usual.

## Persistent configuration (`settings.json`)

For a config that survives new shells, edit `~/.claude/settings.json`:

```json theme={null}
{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
    "ANTHROPIC_BASE_URL": "https://api.openference.com",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "DeepSeek-V4-Flash",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL_NAME": "DeepSeek-V4-Flash",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "DeepSeek-V4-Pro",
    "ANTHROPIC_DEFAULT_SONNET_MODEL_NAME": "DeepSeek-V4-Pro",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "GLM-5.2",
    "ANTHROPIC_DEFAULT_OPUS_MODEL_NAME": "GLM-5.2",
    "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1"
  },
  "model": "sonnet",
  "theme": "auto"
}
```

Replace model IDs with exact values from the [Models page](https://openference.com/models) or `GET /v1/models`. The haiku / sonnet / opus env vars map Claude Code's tier picker (`/model`) to Openference model IDs.

Set `CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY` to `1` so Claude Code discovers models from your gateway instead of Anthropic's catalog.

## Model tiers

Claude Code labels models as haiku, sonnet, or opus. Map each tier to an Openference model:

| Env var                          | Tier               |
| -------------------------------- | ------------------ |
| `ANTHROPIC_DEFAULT_HAIKU_MODEL`  | Fast / lightweight |
| `ANTHROPIC_DEFAULT_SONNET_MODEL` | Balanced (default) |
| `ANTHROPIC_DEFAULT_OPUS_MODEL`   | Most capable       |

Use the matching `*_MODEL_NAME` vars for display names in the UI.

## Chinese models

GLM, DeepSeek, Kimi, and Qwen work through `/v1/messages` — use exact IDs from the catalog. See [Chinese LLM Models](/integrations/chinese-models).

## One key, many tools

The same API key works in Cursor, Codex, Cline, and OpenAI SDK scripts. See the [Compatibility Matrix](/integrations/compatibility-matrix).
