Environment Variables

How to configure environment variables so Claude Code, Codex, Gemini, and other AI coding tools connect to QCode.cc: core variables, a per-tool table, where to set them, and how to verify

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.

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. Haven't installed your tools yet? See Installation.

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

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

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.

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
ANTHROPIC_AUTH_TOKEN
https://api.qcode.cc/api
cr_your_key
Anthropic SDK (Python/JS) ANTHROPIC_BASE_URL
ANTHROPIC_AUTH_TOKEN
https://api.qcode.cc/api
cr_your_key
Codex CLI base_url in ~/.codex config https://api.qcode.cc/openai
OpenAI-compatible tools OPENAI_BASE_URL
OPENAI_API_KEY
https://api.qcode.cc/openai/v1
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.
  • 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):

  • Claude models: claude-opus-4-8, claude-opus-4-7 (both 1M context), claude-sonnet-5 (1M, new-gen balanced), claude-sonnet-4-6 (1M), claude-fable-5 (1M, top-tier flagship), 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
  • 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-4-8, claude-sonnet-4-6, claude-sonnet-5 and claude-fable-5.

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:

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:

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:

# macOS / Linux, per-session
export ANTHROPIC_BASE_URL="https://api.qcode.cc/api"
export ANTHROPIC_AUTH_TOKEN="cr_your_key"
# 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 (Hong Kong node, geographically closest, lowest latency):

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.

5. Verify

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

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):

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.

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

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-4-6","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 — enter your cr_ key to view them.


💡 Don't have a key yet, or want to understand per-model billing? Check the QCode.cc pricing page and pick a plan that fits.

Related Documents

Codex Quick Start
Get Codex CLI installed and configured in 5 minutes -- start AI-powered coding with QCode.cc
Endpoints & API Paths
QCode.cc's three API protocols (Anthropic / OpenAI / Google Gemini), four access domains, and how to fill in BASE_URL
Quick Start
Learn Claude Code essentials in 5 minutes
🚀
Get Started with QCode — Claude Code & Codex
One plan for both Claude Code and Codex, Asia-Pacific low latency
View Pricing Plans → Create Account
Team of 3+?
Enterprise: dedicated domain + sub-key management + ban protection, from ¥250/person/mo
Learn Enterprise →