Claude Code
Last updated
Point Claude Code at Anthropic directly and it only ever talks to Claude models; that's hardcoded into how Claude Code's client works. Point it at Tempr Gateway instead and Claude Code can run GPT-5, Gemini, DeepSeek, or any other model on your gateway allowlist, through the exact same Claude Code interface you already use. Tempr speaks Anthropic's Messages API natively at /v1/messages, so nothing about Claude Code itself changes, only where it connects and which model you tell it to use.
Claude Code has no built-in way to use a non-Anthropic model. Once it's pointed at Tempr, ANTHROPIC_MODEL (or the /model command inside a session) accepts any model id on your allowlist. Swap between Claude, GPT-5, and Gemini mid-project without leaving Claude Code or touching its config beyond the model name.
On an anthropic/… model, Tempr passes Claude Code's requests to Anthropic unchanged and relays the answers as they come back. Extended thinking, web search, prompt caching, and the beta features Claude Code turns on through anthropic-beta all work exactly as they do against Anthropic directly.
On a non-Anthropic model, Tempr translates each request to that provider's API and back. Claude Code's thinking setting becomes the model's own reasoning setting, and the reasoning a model returns shows up as Claude Code's thinking, but Anthropic's server tools, such as web search, aren't available there. Streaming responses also report a placeholder 0 for input tokens in the very first event: the real count is used for billing and shows up once the response finishes, but Claude Code's automatic context compaction can trigger later than usual on very long sessions.
-
Create a virtual key
In the Portal, create a Gateway virtual key. Keys are prefixed
tvk_and shown once at creation. -
Add a provider key
Gateway is BYOK: add a key for at least one provider (typically Anthropic, though any model on your key's allowlist works) from the supported list.
-
Point Claude Code at Tempr
Set
ANTHROPIC_BASE_URLto Tempr's API origin (no/v1suffix; Claude Code appends the path itself) andANTHROPIC_AUTH_TOKENto your virtual key.
Environment variables
# bash / zsh
export ANTHROPIC_BASE_URL="https://api.temprhq.io"
export ANTHROPIC_AUTH_TOKEN="tvk_..."
# optional: run Claude Code on a model that isn't Claude at all
export ANTHROPIC_MODEL="openai/gpt-5"
openai/gpt-5 needs an OpenAI key in the Portal, and Claude Code's own Claude models need an Anthropic key or your Claude plan. Or use any model from GET /v1/models.
Or: ~/.claude/settings.json
If you'd rather not export environment variables in every shell, the same configuration works as a settings file:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.temprhq.io",
"ANTHROPIC_AUTH_TOKEN": "tvk_..."
},
"model": "openai/gpt-5"
}
Model ids: not just Claude
Use the fully-qualified provider/model form: anthropic/claude-sonnet-4-5 for an actual Claude model, but also openai/gpt-5, google/gemini-3.1-pro-preview, or any other id from GET /v1/models. Only models on your virtual key's allowlist (if one is set) will resolve. Claude Code has no opinion about which provider a model belongs to, since as far as it knows it's still just talking to "Claude."
Use your Claude plan
If you pay for Claude Pro, Max, Team or Enterprise, Claude Code can keep its claude.ai sign-in and still go through Tempr, so your plan pays for Claude rather than an API key. Set only the base URL, and send your virtual key in its own header:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.temprhq.io",
"ANTHROPIC_CUSTOM_HEADERS": "x-tempr-key: tvk_..."
}
}
Don't set ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY: either one replaces your sign-in. This is the setup Anthropic's own gateway docs describe for subscriptions.
- Your sign-in stays yours. Tempr forwards it to Anthropic with each request, along with Claude Code's own headers, and never stores or logs it. Token refresh goes from Claude Code straight to Anthropic.
- Your plan's usage still shows. Anthropic's plan-usage headers come back to Claude Code, and Tempr records the usage on each request too.
- Your key still applies. Requests are logged and checked against your key's limits, model allowlist and guardrails like any other. The cost shows as $0, with what the tokens would have cost at API prices beside it.
- Other models work too. Pick an
openai/…or other model with/model, and Tempr uses your stored keys for it. Your Claude sign-in only ever goes to Anthropic. - Organizations. Personal keys accept a sign-in sent this way by default. An organization's keys accept it once an owner or admin turns it on.
Anthropic's Claude Code terms allow you to use your own subscription with Claude Code, but bar third parties from routing Pro or Max plan credentials on their users' behalf, or from handling claude.ai session tokens. They don't say how that applies to a gateway that forwards your own unmodified Claude Code, and Anthropic may act on its terms without notice. Read them for your plan before you rely on this, especially on Pro or Max.
Behind any gateway, Claude Code turns off Remote Control, and gateway model discovery doesn't work with a subscription sign-in. Coding plans from other vendors (Z.AI, Kimi, MiniMax and others) are providers of their own, and Claude Code runs on them too: see Your AI plans.
On a coding plan
To run Claude Code on a coding plan, such as the Z.AI GLM Coding Plan or Kimi Code, use one of the plan's models, named by the plan: zai-coding/glm-5.3. Tempr can get the plan's key two ways:
- Stored in Tempr. Add the plan's key under Provider keys in the Portal, and keep Claude Code's settings as they are, with your virtual key.
- Sent with each request. Send the plan's key as
ANTHROPIC_AUTH_TOKENand your virtual key inANTHROPIC_CUSTOM_HEADERS, and point every model slot at the plan, since Claude Code's quick background calls would otherwise ask for a Claude model: Tempr sends the plan's key only to that plan, and never stores it. An organization's keys take a key sent this way once an owner or admin turns on Plan logins.
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.temprhq.io",
"ANTHROPIC_AUTH_TOKEN": "<the plan's key>",
"ANTHROPIC_CUSTOM_HEADERS": "x-tempr-key: tvk_...",
"ANTHROPIC_MODEL": "zai-coding/glm-5.3",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "zai-coding/glm-5.3",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "zai-coding/glm-5.3",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "zai-coding/glm-5.3-flash"
}
}
Where the plan has an Anthropic-compatible endpoint (its entry on Coding plans lists Messages), Claude Code's requests reach it as they are. With the key stored in Tempr instead, put your virtual key in ANTHROPIC_AUTH_TOKEN and leave out the custom header. More in Your AI plans.
Several plans are sold only for the coding tools they support, and some refuse other tools, telling them apart by the identity each tool sends. Tempr passes Claude Code's own along and never sends another, so check which tools each plan supports before you subscribe.
Ask Claude Code about your Gateway
Claude Code can also read your Gateway through the Gateway's own MCP server: usage and cost, request logs and one request's routing, keys, plan, and providers cooling down. Ask it "why did my last few requests fail?" or "which key spent the most this week?" in the middle of a session. It comes with the Gateway Pro, Scale and Enterprise plans.
The quickest way is to sign in. Add the server, then run /mcp in Claude Code and choose it to sign in to Tempr in the browser:
claude mcp add --transport http --scope user \
tempr-gateway https://api.temprhq.io/mcp/admin
Signed in this way, Claude Code reads your own Gateway, or your organization's if you're an owner or admin. To let it make changes too, tick Also let it make changes on Tempr's consent page.
To give it a management key instead, for scripts or CI:
-
Create a management key
In the Portal, under Gateway → Keys → Management keys (or Organization → Org keys for an organization's Gateway). A management key reads and manages the Gateway but can't call models, so it's separate from the
tvk_virtual key Claude Code uses for its model. Tick what Claude Code may do: Read usage, Read request logs and List keys to read; Create, change and revoke keys as well if it may change keys. -
Add the server with the key
Send the key as a bearer token:
claude mcp add --transport http --scope user \
tempr-gateway https://api.temprhq.io/mcp/admin \
--header "Authorization: Bearer tmk_..."
To share the setup with your team in a project's .mcp.json, keep the key out of the file and let each person's environment supply it:
{
"mcpServers": {
"tempr-gateway": {
"type": "http",
"url": "https://api.temprhq.io/mcp/admin",
"headers": { "Authorization": "Bearer ${TEMPR_MANAGEMENT_KEY}" }
}
}
}
- The key's permissions decide the tools. Without Read request logs, Claude Code gets the usage, plan and key tools but not the logs.
/mcplists what it has. - Changes also need the account to allow them: turn on Changes by AI agents on the Portal's MCP connectors page. Claude Code can then make changes that only tighten, such as creating a key that expires within 90 days or revoking one, and propose any that would loosen, such as a higher budget, for you to approve in the Portal, and asks you before it does. A new key's secret never reaches it: it gets a one-time Portal link for you to copy the key from.
What's next
- The Gateway's MCP server: every tool, what it returns, and how text from your apps is marked.
- Authentication & virtual keys: scoping keys with model allowlists, budgets, and rate limits.
- Models, limits & logs: request logs and analytics apply identically whether traffic comes in via
/v1/chat/completionsor/v1/messages.