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_URLshould end in/apior 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/apiprefix. The SDK automatically appends/v1/messages.ANTHROPIC_AUTH_TOKEN— your QCode.cc key, starting withcr_, created in the QCode.cc dashboard.
About
AUTH_TOKEN: this is the house convention for the relay key — the relay key always goes inANTHROPIC_AUTH_TOKEN(rather thanANTHROPIC_API_KEY, which is for direct official access). Claude Code sends it as a Bearer token. If your tool only recognizesANTHROPIC_API_KEY, putting the samecr_key there works too.⚠️ No trailing slash: use
https://api.qcode.cc/api, nothttps://api.qcode.cc/api/. The SDK appends/v1/messages, so an extra slash becomes//v1/messagesand 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_URLANTHROPIC_AUTH_TOKEN |
https://api.qcode.cc/apicr_your_key |
| Anthropic SDK (Python/JS) | ANTHROPIC_BASE_URLANTHROPIC_AUTH_TOKEN |
https://api.qcode.cc/apicr_your_key |
| Codex CLI | base_url in ~/.codex config |
https://api.qcode.cc/openai |
| OpenAI-compatible tools | OPENAI_BASE_URLOPENAI_API_KEY |
https://api.qcode.cc/openai/v1cr_your_key |
| Gemini / Antigravity | base URL | https://api.qcode.cc/gemini |
A few notes:
- Codex CLI does not read
OPENAI_BASE_URLto locate the upstream; it uses thebase_urlin the~/.codexconfig 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_URLandOPENAI_API_KEY, with base ending at/openai/v1. - Gemini / Antigravity: the base ends at
/gemini; the SDK appends/v1beta/itself. The samecr_key works.
One key works across all three protocols: your
cr_key is protocol-agnostic —/apiis Anthropic,/openai/v1is OpenAI,/geminiis 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(endpointhttps://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-5andclaude-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
.envholds your key — remember to add it to.gitignoreand 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
sourceit 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.