Environment variables and config keys for a custom API endpoint
I run qcode.cc, an independent API service (not official Anthropic, OpenAI or Google). The examples use QCode paths; swap the host for any compatible gateway.
A compact reference for pointing Claude Code, Codex CLI, Gemini CLI and OpenCode at a third-party endpoint. This is not a copy of every official variable — only the keys that matter for a custom Base URL, auth header, model id, timeout or proxy. Full lists stay on the official pages, which win if anything here drifts.
I run qcode.cc, an independent API service. QCode values are a worked example at the end.
Claude Code
Official source: code.claude.com/docs/en/env-vars (checked 2026-12-05). Variables can be set in the shell or under the env key in ~/.claude/settings.json, .claude/settings.json, or .claude/settings.local.json. In a settings file, values are copied as written — ~ and $HOME are not expanded, so paths must be absolute. When the same variable is set in the shell and in a settings env block, the settings file value applies in most sessions.
# shell (this session)
export ANTHROPIC_BASE_URL="https://gateway.example.com"
export ANTHROPIC_AUTH_TOKEN="YOUR_API_KEY"
# or ~/.claude/settings.json — applied however claude is launched
{
"env": {
"ANTHROPIC_BASE_URL": "https://gateway.example.com",
"ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY"
}
}
| Variable / key | What official docs say |
|---|---|
ANTHROPIC_BASE_URL | Override the API endpoint to route requests through a proxy or gateway. As of v2.1.196, Remote Control is disabled when this points at a host other than api.anthropic.com. Claude Code appends /v1/messages — do not put /v1 on the value unless your gateway documents that. |
ANTHROPIC_AUTH_TOKEN | Custom value for the Authorization header; Claude Code prefixes it with Bearer . |
ANTHROPIC_API_KEY | API key sent as X-Api-Key. When set, this key is used instead of a Claude subscription (always in -p mode; in interactive mode after you approve the key once). unset ANTHROPIC_API_KEY to use the subscription again. |
ANTHROPIC_MODEL | Name of the model setting to start with. --model and /model override it. Official docs: for this variable, the environment value is read first and the model settings key is used only when the variable is unset. |
ANTHROPIC_CUSTOM_MODEL_OPTION | Model ID to add as a custom entry in the /model picker (optional name, description and capabilities variables also exist). Useful for a gateway-specific ID. |
API_TIMEOUT_MS | Milliseconds each attempt has to receive response headers (default 600000). Does not limit how long a stream may run after headers. Set 0 to remove this limit (v2.1.305+). |
API_FORCE_IDLE_TIMEOUT | Override the 5-minute body-idle abort on streamed responses. 0 turns it off (useful when a slow gateway pauses between chunks); 1 keeps it on for every provider. |
CLAUDE_BYTE_STREAM_IDLE_TIMEOUT_MS | Byte-level streaming idle watchdog, 10 seconds to 30 minutes (v2.1.210+). Official docs also refer to CLAUDE_STREAM_IDLE_TIMEOUT_MS for the event-level watchdog. |
CLAUDE_CODE_MAX_RETRIES | Retry count for failed API requests (default 10; later versions also document CLAUDE_CODE_RETRY_WATCHDOG). |
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS | Set to 1 to strip pre-release anthropic-beta headers and related body fields — use when a gateway rejects those with "Unexpected value(s)" or "Extra inputs are not permitted". |
CLAUDE_CODE_DISABLE_NONSTREAMING_FALLBACK | Set to 1 to disable the non-streaming fallback after a mid-stream failure (can prevent duplicate tool execution through a proxy). |
HTTPS_PROXY / https_proxy | Documented as read by Claude Code (see CLAUDE_CODE_DISABLE_PROXY_SCHEME_REPAIR, which can stop startup on a bare host:port value). Prefer a full URL such as http://proxy.example.com:8080. |
Related official variables for cloud providers (not a third-party OpenAI-style relay) include ANTHROPIC_BEDROCK_BASE_URL, ANTHROPIC_VERTEX_BASE_URL, ANTHROPIC_FOUNDRY_BASE_URL, and CLAUDE_CODE_USE_BEDROCK / Vertex / Foundry flags. See the official list rather than mixing them with ANTHROPIC_BASE_URL.
Codex CLI
Official sources: Advanced configuration and configuration reference (checked 2026-12-05). User-level file: ~/.codex/config.toml. Project-local .codex/config.toml is loaded only in a trusted project and, per the official reference, cannot override model_provider, model_providers, or openai_base_url — put a custom provider in the user-level file.
# ~/.codex/config.toml
model_provider = "mygateway"
model = "MODEL_ID"
[model_providers.mygateway]
name = "mygateway"
base_url = "https://gateway.example.com/v1"
wire_api = "responses"
env_key = "MYGATEWAY_API_KEY"
| Key | What official docs say |
|---|---|
model_provider | Id of the provider to use (must match a [model_providers.<id>] table, or a built-in id). |
model | Model id sent to that provider. |
model_providers.<id>.name | Display name. |
model_providers.<id>.base_url | API base URL. Codex sends POST {base_url}/responses. |
model_providers.<id>.wire_api | Protocol. Official reference: responses is the only supported value, and the default if omitted. |
model_providers.<id>.env_key | Environment variable that supplies the API key. |
model_providers.<id>.requires_openai_auth | Provider uses OpenAI authentication (default false). Some gateways pair this with ~/.codex/auth.json and OPENAI_API_KEY. Do not combine with env_key or command-backed auth. |
model_providers.<id>.http_headers / env_http_headers | Static headers, or headers filled from environment variables when present. |
model_providers.<id>.request_max_retries | HTTP request retries (default 4). |
model_providers.<id>.stream_max_retries | Retries after an SSE interruption (default 5). |
model_providers.<id>.stream_idle_timeout_ms | Idle timeout for SSE streams in milliseconds (default 300000). |
Reserved provider IDs: openai, ollama, lmstudio, amazon-bedrock, amazon-bedrock-runtime, gcp. Pick a different id for a custom gateway.
Gemini CLI (and Antigravity CLI)
Official source for Gemini CLI: docs/reference/configuration.md in the google-gemini/gemini-cli repository (checked 2026-12-05). Environment variables override settings files; CLI flags override both. Gemini CLI also loads .env files (cwd, then parents, then ~/.env).
export GOOGLE_GEMINI_BASE_URL="https://gateway.example.com"
export GEMINI_API_KEY="YOUR_API_KEY"
# HTTPS required except for localhost / 127.0.0.1 / [::1]
| Variable | What official docs say |
|---|---|
GOOGLE_GEMINI_BASE_URL | Overrides the default base URL for Gemini API requests when using gemini-api-key authentication. Must be a valid URL; HTTPS is required unless the host is localhost, 127.0.0.1 or [::1]. |
GEMINI_API_KEY | API key for the Gemini API. Set in the shell or a .env file. |
GEMINI_MODEL | Default model id; overrides the hardcoded default. |
GOOGLE_GENAI_API_VERSION | API version string (for example v1) when you need to override the SDK default. |
GOOGLE_VERTEX_BASE_URL | Base URL for Vertex AI requests (Vertex authentication only). Same HTTPS rule as GOOGLE_GEMINI_BASE_URL. |
GOOGLE_API_KEY | Google Cloud API key, required for Vertex AI express mode — not a substitute for GEMINI_API_KEY on a Gemini-API-key custom endpoint. |
The official Gemini CLI / @google/genai clients append /v1beta themselves, so the Base URL should stop before that segment. Putting /v1beta on the value produces /v1beta/v1beta/… and a 404. Antigravity CLI (agy) uses the same GOOGLE_GEMINI_BASE_URL + GEMINI_API_KEY pair; see the Antigravity page for settings.json display names. agy does not load .env files and ignores GOOGLE_API_KEY (documented on that page).
OpenCode
Official source: opencode.ai/docs/providers (checked 2026-12-05). Current docs use a providers object and override settings.baseURL to send a catalog provider through a proxy. settings is package-specific — a field only applies if the selected package supports it.
{
"$schema": "https://opencode.ai/config.json",
"providers": {
"anthropic": {
"settings": { "baseURL": "https://gateway.example.com/anthropic" }
},
"openai": {
"settings": { "baseURL": "https://gateway.example.com/v1" }
},
"google": {
"settings": { "baseURL": "https://gateway.example.com/v1beta" }
}
}
}
| Key | What official docs say |
|---|---|
providers.<id>.settings.baseURL | Endpoint override for a catalog provider (anthropic, openai, google, or a custom id). |
providers.<id>.env | Ordered environment variable names that can supply the credential (custom providers). |
providers.<id>.package | Runtime package, for example @opencode/ai/providers/openai-compatible or @opencode/ai/providers/anthropic. |
providers.<id>.headers / body | Extra HTTP headers, or JSON fields merged into every request body. |
Older OpenCode configs (and some third-party integration guides) used a provider object with options.baseURL. If you are on a current V2 build, follow the official providers / settings.baseURL shape above. For QCode's google provider the baseURL must include /v1beta (OpenCode does not append it): https://api.qcode.cc/gemini/v1beta. See the OpenCode page.
QCode worked example (one key, three prefixes)
From docs.qcode.cc endpoints. Swap the hostname for asia.qcode.cc or us.qcode.cc if you need a closer route; the path stays the same.
| Client | Setting | Value |
|---|---|---|
| Claude Code | ANTHROPIC_BASE_URL | https://api.qcode.cc/api |
| Codex CLI | base_url | https://api.qcode.cc/openai |
| OpenAI SDK / Cursor / Cline OpenAI Compatible | base_url / Base URL | https://api.qcode.cc/openai/v1 |
Gemini CLI, Antigravity CLI, @google/genai | GOOGLE_GEMINI_BASE_URL | https://api.qcode.cc/gemini |
OpenCode google provider | settings.baseURL | https://api.qcode.cc/gemini/v1beta |
Related pages
Troubleshooting · Cursor and Cline · Setup cheat sheet · Base URL guide
Facts checked against docs.qcode.cc on 2026-12-05. I run qcode.cc. Pricing: qcode.cc/pricing (no free quota). Contact: hi@qcode.cc.