# Environment Variables

> ⚡ Not set up yet? One command does it all: `curl -fsSL https://qcode.cc/install/claude-code.sh | bash` (Windows: `irm https://qcode.cc/install/claude-code.ps1 | iex`). See [One-Click Setup Script](/docs/getting-started/one-click-install).

Almost every AI coding tool uses **environment variables** to decide "which service to connect to, and which key to use." Point those two pieces of information at QCode.cc and your tool will send requests to us. This page explains which variables to set, where to set them, and how to verify.

> 📖 Not sure whether `BASE_URL` should end in `/api` or another prefix? Which of the access domains to pick? Start with [Endpoints & API Paths](/docs/getting-started/endpoints-and-api-paths). Haven't installed your tools yet? See [Installation](/docs/getting-started/installation).

## 1. The Two Core Variables (Claude Code & Anthropic SDK)

Connecting to the Claude family of models needs just two environment variables:

```bash
export ANTHROPIC_BASE_URL="https://api.qcode.cc/api"
export ANTHROPIC_AUTH_TOKEN="cr_your_key"
```

- **`ANTHROPIC_BASE_URL`** — the access address, ending at the `/api` prefix. The SDK automatically appends `/v1/messages`.
- **`ANTHROPIC_AUTH_TOKEN`** — your QCode.cc key, starting with `cr_`, created in the [QCode.cc dashboard](https://qcode.cc/dashboard).

> **About `AUTH_TOKEN`**: this is the house convention for the relay key — the relay key always goes in `ANTHROPIC_AUTH_TOKEN` (rather than `ANTHROPIC_API_KEY`, which is for direct official access). Claude Code sends it as a Bearer token. If your tool only recognizes `ANTHROPIC_API_KEY`, putting the same `cr_` key there works too.

> **⚠️ No trailing slash**: use `https://api.qcode.cc/api`, **not** `https://api.qcode.cc/api/`. The SDK appends `/v1/messages`, so an extra slash becomes `//v1/messages` and returns 404.

These two variables work for both Claude Code and the official Anthropic SDKs (Python / TypeScript) — the SDK reads `ANTHROPIC_BASE_URL` as well, or you can pass `base_url=` when constructing the client.

## 2. Per-Tool Table

Different tools read different environment variables. Match yours below:

| Tool | Environment Variables | Value |
|------|----------------------|-------|
| Claude Code | `ANTHROPIC_BASE_URL`<br>`ANTHROPIC_AUTH_TOKEN` | `https://api.qcode.cc/api`<br>`cr_your_key` |
| Anthropic SDK (Python/JS) | `ANTHROPIC_BASE_URL`<br>`ANTHROPIC_AUTH_TOKEN` | `https://api.qcode.cc/api`<br>`cr_your_key` |
| Codex CLI | `base_url` in `~/.codex` config | `https://api.qcode.cc/openai` |
| OpenAI-compatible tools | `OPENAI_BASE_URL`<br>`OPENAI_API_KEY` | `https://api.qcode.cc/openai/v1`<br>`cr_your_key` |
| Gemini / Antigravity | base URL | `https://api.qcode.cc/gemini` |

A few notes:

- **Codex CLI** does not read `OPENAI_BASE_URL` to locate the upstream; it uses the `base_url` in the `~/.codex` config file (ending at `/openai`, using the OpenAI Responses protocol). For the exact syntax see [Endpoints & API Paths](/docs/getting-started/endpoints-and-api-paths).
- **OpenAI-compatible tools** (the official OpenAI SDK, LangChain, generic clients) read `OPENAI_BASE_URL` and `OPENAI_API_KEY`, with base ending at `/openai/v1`.
- **Gemini / Antigravity**: the base ends at `/gemini`; the SDK appends `/v1beta/` itself. The same `cr_` key works.

> **One key works across all three protocols**: your `cr_` key is protocol-agnostic — `/api` is Anthropic, `/openai/v1` is OpenAI, `/gemini` is Google Gemini. Switching tools only means switching the BASE_URL; the key stays the same.

### Available Models

Once connected, pick a model name per your tool's protocol (more detail in [Endpoints & API Paths](/docs/getting-started/endpoints-and-api-paths)):

- **Claude models** (daily default is the 5 line): `claude-sonnet-5` (1M, balanced), `claude-opus-5` (1M, current flagship), `claude-fable-5` (1M, top tier), `claude-sonnet-4-6` / `claude-opus-4-8` / `claude-opus-4-7` (previous gen, still on sale), `claude-haiku-4-5` (200K)
- **GPT family**: `gpt-5.6-terra` (recommended), `gpt-5.6-sol`, `gpt-5.6-luna`, `gpt-5.5`, `gpt-5.4`, `gpt-5.6-mini`, `gpt-5.6-nano`
- **Gemini family**: `gemini-2.5-pro`, `gemini-3.5-flash`, `gemini-2.5-flash`
- **China-family** (GLM / Kimi / DeepSeek / Qwen): `glm-5.3`, `kimi-k3`, `deepseek-v4-pro`, `qwen3.8-max`, and siblings — see [China-family models](/docs/usage/cn-models)
- **Image**: `gpt-image-2` (endpoint `https://api.qcode.cc/qcode-img/v1`)

> **Claude Code context length**: Claude Code defaults to a **200K** window; the **1M context** opt-in is supported by `claude-opus-5`, `claude-sonnet-5`, `claude-fable-5`, `claude-opus-4-8` and `claude-sonnet-4-6`.

## 3. Where to Set Them

Where you set an environment variable determines its scope. Three common approaches:

**① Shell rc file (persistent, global)** — write it into `~/.zshrc` (macOS / zsh) or `~/.bashrc` (Linux / bash) so every new terminal picks it up automatically:

```bash
echo 'export ANTHROPIC_BASE_URL="https://api.qcode.cc/api"' >> ~/.zshrc
echo 'export ANTHROPIC_AUTH_TOKEN="cr_your_key"' >> ~/.zshrc
source ~/.zshrc
```

bash users replace `~/.zshrc` with `~/.bashrc`.

**② Project `.env` (persistent, per-project)** — drop a `.env` file in the project root; it applies to that project only, handy for using different keys per project:

```bash
ANTHROPIC_BASE_URL=https://api.qcode.cc/api
ANTHROPIC_AUTH_TOKEN=cr_your_key
```

> A `.env` holds your key — remember to add it to `.gitignore` and never commit it.

**③ Tool's own settings (per-tool)** — some tools have their own config file or UI, e.g. Codex CLI's `~/.codex`, or an editor plugin's settings panel. Such settings apply only to that tool.

**Persistent vs per-session**: all three above are **persistent**. If you only want to try something in the **current terminal session**, just `export` (macOS/Linux) or `$env:` (Windows PowerShell) — it disappears when you close the terminal:

```bash
# macOS / Linux, per-session
export ANTHROPIC_BASE_URL="https://api.qcode.cc/api"
export ANTHROPIC_AUTH_TOKEN="cr_your_key"
```

```powershell
# Windows PowerShell, per-session
$env:ANTHROPIC_BASE_URL = "https://api.qcode.cc/api"
$env:ANTHROPIC_AUTH_TOKEN = "cr_your_key"
```

> **Precedence note**: environment variables read at process startup take precedence over config files. After editing a shell rc file, remember to `source` it or open a new terminal; when the same variable is set in several places, the one the process actually inherits wins.

## 4. 🇨🇳 Note for CN Users

Users in mainland China should swap the BASE_URL host from `api.qcode.cc` to `asia.qcode.cc` (Asia node, nearest of HK/JP, geographically closest, lowest latency):

```bash
export ANTHROPIC_BASE_URL="https://asia.qcode.cc/api"
export ANTHROPIC_AUTH_TOKEN="cr_your_key"
```

The same applies to other protocols: OpenAI-compatible tools use `https://asia.qcode.cc/openai/v1`, Codex uses `https://asia.qcode.cc/openai`, and Gemini uses `https://asia.qcode.cc/gemini`. All four access domains serve identical capabilities; the same key works across them, so switch back to `api.qcode.cc` (global Route 53 routing) if `asia` is unstable. See [Endpoints & API Paths](/docs/getting-started/endpoints-and-api-paths).

## 5. Verify

After setting the variables, first confirm the values are correct:

```bash
echo $ANTHROPIC_BASE_URL
echo $ANTHROPIC_AUTH_TOKEN
```

Then use curl to confirm the access address is reachable (**without a key** — testing only path and network):

```bash
curl -s -o /dev/null -w '%{http_code}' \
  -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  https://api.qcode.cc/v1/models
# → 200 = network, path and key all good
```

**Interpretation**: `200` means network, endpoint and key are all set. `401` means the key is invalid or not sent correctly (check the `cr_` prefix was copied in full); `404` usually means a wrong path prefix. Note: accessing the endpoint **without a key** returns an HTML intro page (HTTP 200) rather than an error — if you see that page, your key wasn't attached. Full curl self-tests: [Endpoints & API Paths](/docs/getting-started/endpoints-and-api-paths).

Run an end-to-end test with your real key:

```bash
curl -X POST https://api.qcode.cc/api/v1/messages \
  -H "x-api-key: $ANTHROPIC_AUTH_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"claude-sonnet-5","max_tokens":64,"messages":[{"role":"user","content":"ping"}]}'
```

A normal JSON response means your environment variables are configured and you're ready to go.

> Want to inspect the model, context length, and usage of each request? Every access domain reports to [probe.qcode.cc](https://probe.qcode.cc) — enter your `cr_` key to view them.

## 6. Gateway-relevant variables

When Claude Code talks to a third-party gateway (QCode included), these official variables matter. Definitions from the [environment variables reference](https://code.claude.com/docs/en/env-vars) and the [gateway connection guide](https://code.claude.com/docs/en/llm-gateway-connect) (checked 2026-09-18):

| Variable | When it matters |
|---|---|
| `ANTHROPIC_DEFAULT_MODEL` | Sets the **default model for new sessions** (since 2.1.236, 2026-08-19). Unlike `ANTHROPIC_MODEL`: an in-session `/model` choice overrides it and persists across restarts, while `ANTHROPIC_MODEL` is re-applied on every launch |
| `CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1` | Lets the `/model` picker read the gateway's model list (off by default upstream, since shared-key gateways may list models you cannot use). Against QCode the list shows the **Claude-family ids** (only names containing `claude` / `anthropic` are picked up); **Chinese models never appear** — keep setting `ANTHROPIC_MODEL` / `ANTHROPIC_DEFAULT_MODEL` for them |
| `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` | Strips the `anthropic-beta` header and beta tool fields. Turn it on when the gateway answers `Unexpected value(s) … anthropic-beta` with a 400 |
| `CLAUDE_CODE_DISABLE_ARTIFACT=1` | Disables the Artifact tool (once set, no settings UI can turn it back on). Claude Code 2.1.265–2.1.267 sent a tool schema that strict gateways reject outright (400); the official fix is upgrading to ≥2.1.268 — this variable is the stopgap |
| `CLAUDE_CODE_ATTRIBUTION_HEADER=0` | Official meaning: removes the attribution block (client version + prompt fingerprint) at the top of the system prompt. **We have not tested** whether turning it off is beneficial, and this page does not recommend it — read the official docs and decide |

---

> 💡 Don't have a key yet, or want to understand per-model billing? Check the [QCode.cc pricing page](https://qcode.cc/pricing) and pick a plan that fits.