Claude Code
Two environment variables. Same tool, same models, live prices.
What you need
- Claude Code installed (`claude` on your PATH).
- An UplinkSwitch key from the console, with a balance loaded.
Two variables
ANTHROPIC_API_KEY works in place of ANTHROPIC_AUTH_TOKEN. Set one, not both.
export ANTHROPIC_BASE_URL="https://api.uplinkswitch.com/v1"
export ANTHROPIC_AUTH_TOKEN="sk-uplink-live-..."
claudeANTHROPIC_BASE_URLpoints Claude Code at UplinkSwitch. Paste it with the/v1; the gateway accepts the path Claude Code builds from it.ANTHROPIC_AUTH_TOKENsends the key asAuthorization: Bearer.ANTHROPIC_API_KEYsends it asx-api-key. UplinkSwitch reads either header. A request that carries two different keys is refused with a400.- The base URL alone is not enough. Without one of the key variables, Claude Code keeps using a saved claude.ai login (Claude Code's gateway docs).
Make it stick
Add them to ~/.claude/settings.json under env. The model variables take any chat model id from the Models page. Claude Code speaks Anthropic's API format, and every chat model is served in it here, GPT, Gemini, DeepSeek, Kimi and the uncensored builds included.
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.uplinkswitch.com/v1",
"ANTHROPIC_AUTH_TOKEN": "sk-uplink-live-...",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5-5",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5-5",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-5-5",
"ANTHROPIC_CUSTOM_HEADERS": "HTTP-Referer: https://uplinkswitch.ai\nX-Title: Claude Code"
}
}~/.claude/settings.jsonapplies to every project..claude/settings.local.jsonapplies to one project.- Keep the key out of a project's
.claude/settings.json. That file is meant to be committed and shared. - When a shell export and a settings file set the same variable, the settings file wins.
ANTHROPIC_CUSTOM_HEADERS(Claude Code 2.1.227 or later) adds theHTTP-RefererandX-Titleheaders the usage log files requests under. It is optional: without it, usage shows under Claude Code from its user agent. Put your own app name inX-Titleto file the usage under that instead.- The VS Code extension checks credentials from its own setting,
claudeCode.environmentVariables, in VS Code's user settings:
{
"claudeCode.environmentVariables": [
{ "name": "ANTHROPIC_BASE_URL", "value": "https://api.uplinkswitch.com/v1" },
{ "name": "ANTHROPIC_AUTH_TOKEN", "value": "sk-uplink-live-..." },
{ "name": "ANTHROPIC_CUSTOM_HEADERS", "value": "HTTP-Referer: https://uplinkswitch.ai\nX-Title: Claude Code" }
]
}Picking a model
The opus, sonnet and haiku aliases resolve to whatever the three ANTHROPIC_DEFAULT_*_MODEL variables name. Setting the Haiku one also moves background work such as session titles to that model. Switch in a session with /model, at start with claude --model claude-opus-5-5, or for one session with ANTHROPIC_MODEL.
Any chat id works in the same variables: a GPT, Gemini, DeepSeek or uncensored id sent in the Anthropic format is served on its own route and answered as a Messages response, tool calls included. The same ids also run in OpenCode and Cline, and Claude Code Router still works for per-task routing.
What Claude Code costs on this key
The three models the opus, sonnet and haiku aliases resolve to, per million tokens, live from GET /v1/catalog (Dec 3, 12:41 PM UTC). The struck figure is Anthropic's published list price for the same model.
| Model | Input | Cache read | Output |
|---|---|---|---|
| Claude Opus 5.5 | |||
| Claude Sonnet 5.5 | |||
| Claude Haiku 5.5 | $0.01 |
USD per million tokens, both columns from the live catalog. Every Claude model on the key is on the Claude API pricing hub.
One turn late in a session, 125,000 tokens read back from the cache plus 2,000 fresh input and 1,500 output tokens, is $0.0394 on Claude Opus 5.5 here against $0.063 at Anthropic's list; a 200-turn day is $7.87 against $12.60. The Claude Code price page keeps the same arithmetic live for a month of work, and the Claude API pricing hub has every Claude model on the key.
Tested 2026-11-27: two abliterated models in Claude Code
We ran Claude Code 2.1.332 itself, not a script imitating it, on glm-5.3-abliterated and deepseek-v4.1-flash-1017-abliterated: one session of 20 small coding asks per model in a scratch folder, with Claude Code reading, editing and writing the files. The setup came down to this block, with the id in all four model variables:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.uplinkswitch.com/v1",
"ANTHROPIC_AUTH_TOKEN": "sk-uplink-live-...",
"ANTHROPIC_MODEL": "deepseek-v4.1-flash-1017-abliterated",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek-v4.1-flash-1017-abliterated",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-v4.1-flash-1017-abliterated",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "deepseek-v4.1-flash-1017-abliterated"
}
}ANTHROPIC_BASE_URL worked both as https://api.uplinkswitch.com and with /v1 on the end. Claude Code warns that it does not recognise the id and assumes a 1M-token window; CLAUDE_CODE_MAX_CONTEXT_TOKENS set to the window in our catalog (131072 for GLM 5.3 Abliterated) removed the warning in our run. Check it with one line, which printed ok on both ids:
claude -p "Reply with the single word ok." < /dev/null
# okPrompt cache: on GLM 5.3 Abliterated 41 of the 41 calls after the first read from the cache, and 96.2% of all prompt tokens in the session were cache reads; on DeepSeek V4.1 Flash Abliterated it was 52 of 52 and 99.1%. Both models cache the repeated prefix on their own, so Claude Code's cache_control marks are accepted but not needed, and no response reported cache writes. One exception the same hour: two shorter DeepSeek sessions read nothing from the cache on any of 14 calls, so look at cache_read_tokens on your own first requests.
Tool calls, tested separately the same day with 840 requests (20 per case on every route that serves each id): one tool on auto, two tools in one turn, a strict nested schema, the turn after a tool result, a streamed call and the Anthropic format passed 360 of 360 on GLM and 359 of 360 on DeepSeek, the one miss a dropped connection. A forced tool_choice was ignored by some GLM routes, and the gateway now sends such a request again to the next route. Parallel calls while streaming and prompts far longer than about 7,000 tokens were not part of the test.
| Model | Priced at | 20-turn session |
|---|---|---|
| GLM-5.3 Abliterated | this API | $0.7023 |
| DeepSeek V4.1 Flash 1017 Abliterated | this API | $0.1505 |
| Claude Sonnet 5.5 | developer list | $0.2028 |
| Claude Opus 5.5 | developer list | $0.4056 |
The GLM session above (32,753 uncached input, 825,472 cache-read and 5,476 output tokens over 42 calls) at today's catalog rates, the same token counts for every row.
On that profile Claude Sonnet 5.5 at list costs 1.35 times and Claude Opus 5.5 at list costs 2.69 times what DeepSeek V4.1 Flash Abliterated costs here. GLM 5.3 Abliterated costs more than Claude Sonnet 5.5 at list on a session this cache-heavy: its cache-read rate is the larger part of the bill. The numbers follow the live catalog; the token counts are from 2026-11-27. Anthropic's own gateway page says Anthropic does not support Claude Code on non-Claude models through a gateway; the sessions above are what we saw, not their support.
Check it
List the models your key can call:
curl https://api.uplinkswitch.com/v1/models \
-H "x-api-key: $ANTHROPIC_AUTH_TOKEN" \
-H "HTTP-Referer: https://uplinkswitch.ai" \
-H "X-Title: Claude Code"Send one small message. -i prints the headers: x-uplink-request-id names the request and x-uplink-charge is what it cost in USD.
curl -i https://api.uplinkswitch.com/v1/messages \
-H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-H "HTTP-Referer: https://uplinkswitch.ai" \
-H "X-Title: Claude Code" \
-d '{"model": "claude-haiku-5-5", "max_tokens": 16, "messages": [{"role": "user", "content": "Say ok."}]}'Then run claude. The request shows in the console within seconds. Inside Claude Code, /status shows an Anthropic base URL line with the UplinkSwitch address and an Auth token or API key line naming the variable you set. If the base URL line is missing, the variable did not reach the session.
Caching and billing
Claude Code sends the whole conversation on every turn and marks it for the prompt cache. Tokens read from the cache bill at the cached rate on each model page, a fraction of the input rate. The cache lasts five minutes by default, so a turn after a longer break pays the input rate for the whole context once.
The cost Claude Code shows is its own estimate at Anthropic's list price. What you paid is on the console's Usage page. For one request, look it up by its id; it lands in the log within about a minute:
curl https://api.uplinkswitch.com/v1/requests/REQUEST_ID \
-H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN"The answer lists input_tokens, cache_read_tokens, output_tokens and charge_usd. A cache_read_tokens above zero means caching worked. The Claude Code cost breakdown works a day of use through at live prices.
Credit is prepaid from $10 in the console, with no subscription, and each top-up locks your prices for 30 days. Bonus credit on larger top-ups: +5% from $50, +10% from $100, +15% from $120.
Errors and fixes
invalid_api_key(401): the key is wrong or revoked, or it is in a variable Claude Code did not read. Check/status.insufficient_balance(402): top up in the console.monthly_limit_reached(402) means the key hit the monthly spend limit set on it.model_not_found(404): the id is not on the Models page. Check the model variables for typos.- Claude Code asks you to log in although the curl test works: set the key in a shell export or in
~/.claude/settings.json. A project settings file applies only after the first-run setup and the trust prompt. - A startup warning naming two credential sources: a saved login and the variable are both active. Run
/logoutto keep only the key. ANTHROPIC_API_KEYset but ignored: it needs a one-time approval. Turn on Use custom API key under/config, or useANTHROPIC_AUTH_TOKEN.
Add the MCP server
The same key also works as an MCP server, so Claude Code can read live prices, estimate a request and check the daily proof as tools. One command:
claude mcp add --transport http uplinkswitch https://api.uplinkswitch.com/mcp \
--header "Authorization: Bearer sk-uplink-live-..."{
"mcpServers": {
"uplinkswitch": {
"type": "http",
"url": "https://api.uplinkswitch.com/mcp",
"headers": { "Authorization": "Bearer ${UPLINK_API_KEY}" }
}
}
}Or put the project form in .mcp.json with the key in a variable of your own name (Claude Code reads ANTHROPIC_AUTH_TOKEN as empty inside a remote server's headers). The tools are list_models, list_media_models, media_model, estimate and proof (no key needed), then chat, compare, search, embed, rerank, transcribe, media_quote, generate, generation and generations on the key: every model on the catalog is a tool, compare asks two to five models the same question side by side, and generate runs any image, video, speech, music or 3D model and hands the files back to Claude, a finished image inline. Each run is billed to the key like any other request; a failed one is refunded. The server card is at https://api.uplinkswitch.com/mcp/server-card.
Good to know
- MCP tool search is off on a non-Anthropic host;
ENABLE_TOOL_SEARCH=trueturns it on. - Prompt caching works; cached input bills at the cached rate.
- Remote Control and voice dictation need a claude.ai login, so they are off while a key variable is set.
- To switch back:
unset ANTHROPIC_BASE_URL ANTHROPIC_AUTH_TOKEN, and remove them fromsettings.jsonif you put them there.