A Claude Code API key is a Claude Console key that Claude Code bills per token instead of drawing on a subscription. Create one at platform.claude.com, then either export it as ANTHROPIC_API_KEY or run /login and choose the Console account. Every request is then charged at API rates: Opus 5.5, the default model, costs $4 / $20 per million input / output tokens, so a one-hour task of about 80 model calls comes to roughly $3.76, or $1.88 on Sonnet 5.5.
Claude Code also runs on Amazon Bedrock, Google Cloud's Agent Platform (formerly Vertex AI), Microsoft Foundry and Claude Platform on AWS, billed by the cloud provider. And Claude Code Router, an open-source local gateway, sends its requests to other makers' models for a fraction of the price, outside Anthropic's support. Everything below was checked on 5 November 2026 against Claude Code 2.1.318 and claude-code-router 3.1.3.
Every way to pay for Claude Code without a plan
| Route | How Claude Code connects | Who bills you | Opus 5.5 per 1M tokens | Supported by Anthropic |
|---|---|---|---|---|
| Claude Console API key | /login (Console) or ANTHROPIC_API_KEY | Anthropic, prepaid | $4 / $20 | Yes |
| Amazon Bedrock | CLAUDE_CODE_USE_BEDROCK=1 | AWS | $4 / $20 global, $4.40 / $22 regional | Yes |
| Google Cloud's Agent Platform | CLAUDE_CODE_USE_VERTEX=1 | Google Cloud | $4 / $20 global, $4.40 / $22 US multi-region | Yes |
| Microsoft Foundry | CLAUDE_CODE_USE_FOUNDRY=1 | Azure | Azure's price list | Yes |
| Claude Platform on AWS | CLAUDE_CODE_USE_ANTHROPIC_AWS=1 | AWS Marketplace, at Anthropic's rates | $4 / $20 | Yes |
| A non-Claude model with an Anthropic-format endpoint | ANTHROPIC_BASE_URL | That provider | Not a Claude model | No |
| claude-code-router | A local gateway that launches Claude Code | Each upstream provider | Depends on the upstream | No |
The plans (Pro $20, Max $100, Ultra $200 a month) are covered in the Claude Code pricing guide.
How to set up a Claude Code API key
You need a Console account with prepaid usage and a key; the Claude API key guide covers that, and the install guide covers Claude Code itself. Then hand the key over in one of three ways.
Option 1: sign in with /login
Run /login in Claude Code, or claude auth login --console in your shell, and choose the Anthropic Console account. From version 2.1.242 you then pick "Sign in with your Console account" (recommended: an OAuth login that refreshes itself, no key stored) or "Create an API key" (legacy).
The first Console sign-in creates a workspace called "Claude Code" in the Console. You can't create other keys in it, but you can give it a workspace spend limit, the simplest cap on Claude Code spend.
Option 2: the ANTHROPIC_API_KEY environment variable
export ANTHROPIC_API_KEY=sk-ant-... # a key from platform.claude.com
claude
In an interactive session Claude Code asks once whether to use the key and remembers the answer; the "Use custom API key" toggle in /config changes it later. With claude -p, the key is always used.
An approved key wins over a logged-in plan, which Anthropic's docs warn about: a key left in ~/.zshrc, approved once at a prompt, moves a Max subscriber onto API billing. unset ANTHROPIC_API_KEY goes back to the plan.
Option 3: apiKeyHelper in settings.json
To keep the key out of shell profiles, point the apiKeyHelper setting at a command that prints it. On macOS, store the key in the Keychain once (the trailing -w makes security prompt for it):
security add-generic-password -a "$USER" -s anthropic-api-key -w
Then add the helper to ~/.claude/settings.json:
{
"apiKeyHelper": "security find-generic-password -s anthropic-api-key -w"
}
Claude Code sends the output as both the X-Api-Key and Authorization: Bearer headers, caches it for five minutes (CLAUDE_CODE_API_KEY_HELPER_TTL_MS changes that) and reruns the command after a 401 or 403, so it also works for short-lived tokens from a vault. Don't use the env block of a settings file for the key: the settings reference warns that env values are plain text and reach every subprocess.
Which credential Claude Code uses
When several credentials are present, Claude Code takes the first in a fixed order:

- Cloud provider credentials, when
CLAUDE_CODE_USE_BEDROCK,CLAUDE_CODE_USE_VERTEXorCLAUDE_CODE_USE_FOUNDRYis set. ANTHROPIC_AUTH_TOKEN, sent as a Bearer token, for gateways.ANTHROPIC_API_KEY.apiKeyHelperoutput.CLAUDE_CODE_OAUTH_TOKEN, the one-year plan token fromclaude setup-token.- An Anthropic profile or Workload Identity Federation credentials.
- The plan login from
/login.
Run /status to check, or claude auth status, whose authMethod field reads api_key, api_key_helper, claude.ai or third_party. Claude Desktop and cloud sessions ignore these variables and sign in with OAuth.
What a Claude Code session costs with an API key
Each step Claude Code takes is one model call that resends the conversation so far. Most of it is a cache read, at 5% of the input price on Opus 5.5 and Sonnet 5.5; the new part is a cache write at 1.25 times the input price.
The worked session is about an hour of focused work: 80 calls, 60,000 tokens of context per call, 92% read from the cache and 8% written, and 600 output tokens per call. Prices per million tokens come from Anthropic, the AWS Price List for us-east-1 and DeepSeek.
| Route and model | Cache read | Cache write (or uncached input) | Output | One session |
|---|---|---|---|---|
| API key, Opus 5.5 | $0.20 | $5.00 | $20.00 | $3.76 |
| API key, Sonnet 5.5 | $0.10 | $2.50 | $10.00 | $1.88 |
| API key, Haiku 5.5 | $0.01 | $0.125 | $0.50 | $0.12 |
Bedrock, Opus 5.5, us. profile | $0.22 | $5.50 | $22.00 | $4.14 |
DeepSeek deepseek-flash, peak | $0.006 | $0.30 | $1.20 | $0.20 |
DeepSeek deepseek-flash, off-peak | $0.003 | $0.15 | $0.60 | $0.10 |

On Opus 5.5 the session splits into $0.88 of cache reads, $1.92 of cache writes and $0.96 of output. Cache writes are 8% of the tokens and half the bill. With an API key, Claude Code caches the main conversation for only five minutes, so the first message after a break rewrites the whole context. "promptCacheTtl": "1h" in settings keeps it for an hour, at $8 instead of $5 per million written tokens on Opus 5.5.
Real sessions vary: OpenRouter's dataset of Claude Code sessions to 18 October put the median session of 10 to 49 turns at $1.39 on Opus 5.5, $0.60 on Sonnet 5.5 and $0.05 on Haiku 5.5. To redo the math with your own numbers, take the token counts from the Session block of /usage:
def session_cost(calls, context, write_price, read_price, out_price,
write_share=0.08, output_tokens=600):
"""US$ for one session; prices are US$ per 1M tokens."""
per_call = (context * (1 - write_share) * read_price
+ context * write_share * write_price
+ output_tokens * out_price) / 1e6
return round(calls * per_call, 2)
print(session_cost(80, 60_000, 5.00, 0.20, 20.00)) # Opus 5.5: 3.76
print(session_cost(80, 60_000, 2.50, 0.10, 10.00)) # Sonnet 5.5: 1.88
print(session_cost(80, 60_000, 0.125, 0.01, 0.50)) # Haiku 5.5: 0.12
Each Console usage tier has a monthly spend cap ($500 Start, $1,000 Build, $200,000 Scale), past which requests return 429 until 00:00 UTC on the 1st. For scripts, claude -p --max-budget-usd 5.00 "..." stops a run at an estimated amount, though spend can pass it.
Claude Code on Bedrock, Vertex AI and other official routes
On a cloud provider, Claude Code is billed per token to your cloud account, and spend shows up in your cloud's billing console, not Anthropic's.
Amazon Bedrock
Run claude and choose "3rd-party platform", then Amazon Bedrock, or run /setup-bedrock. The wizard finds your AWS credentials, checks which Claude models you can invoke, and writes the settings to ~/.claude/settings.json. The manual equivalent:
export CLAUDE_CODE_USE_BEDROCK=1
export AWS_REGION=us-east-1
export ANTHROPIC_BEDROCK_REGION_PREFIX=global # global profiles cost about 10% less
export ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-5-5
# with a Bedrock API key instead of AWS credentials:
# export AWS_BEARER_TOKEN_BEDROCK=your-bedrock-api-key
Two of those lines save money. In a US region Claude Code defaults to us. inference profiles, and AWS prices global profiles about 10% lower: Opus 5.5 is $4.40 / $22 at the regional rate and $4 / $20 on global. Setting the prefix to global switches, unless your data must stay in one geography. And on Bedrock the sonnet alias still points to Sonnet 4.5 at $3 / $15, more than Sonnet 5.5's $2 / $10, so pin it. Opus already defaults to Opus 5.5. The WebSearch tool isn't available on Bedrock.
Google Cloud's Agent Platform, formerly Vertex AI
export CLAUDE_CODE_USE_VERTEX=1
export CLOUD_ML_REGION=global
export ANTHROPIC_VERTEX_PROJECT_ID=your-project-id
export ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-5-5
Enable the Claude models in Model Garden first. Google's partner model pricing matches Anthropic's on the global endpoint and adds 10% on the US and EU multi-region endpoints. Here too, sonnet defaults to Sonnet 4.5.
Microsoft Foundry and Claude Platform on AWS
Foundry takes CLAUDE_CODE_USE_FOUNDRY=1, ANTHROPIC_FOUNDRY_RESOURCE and an API key or Microsoft Entra ID. Its default model is Sonnet 4.5 and it has no startup model check, so pin every alias to a deployment you have.
Claude Platform on AWS is Anthropic's own API with AWS sign-in and AWS Marketplace billing, so it gets Anthropic's models and features on Anthropic's schedule, billed at standard rates as Claude Consumption Units of $0.01 each. It creates a new Anthropic organization, separate from any Console account.
Claude Code with other models through an Anthropic-compatible endpoint
Some model makers expose Anthropic's Messages format and document Claude Code setup themselves, so no router is needed. DeepSeek's guide sets these variables (abbreviated):
export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
export ANTHROPIC_AUTH_TOKEN=your-deepseek-api-key
export ANTHROPIC_MODEL='deepseek-flash[1m]'
export ANTHROPIC_DEFAULT_OPUS_MODEL='deepseek-flash[1m]'
export ANTHROPIC_DEFAULT_SONNET_MODEL='deepseek-flash[1m]'
export ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek-flash
export CLAUDE_CODE_SUBAGENT_MODEL=deepseek-flash
deepseek-flash is DeepSeek V4.1 Flash (17 October build) at $0.30 / $1.20 at peak and half that off-peak. Peak runs 01:00 to 04:00 and 06:00 to 10:00 UTC on weekdays, so the US Eastern working day is off-peak. Pin every alias as above: DeepSeek maps any claude-opus model name to deepseek-v4-pro and bills it at that model's higher price.
Z.ai does the same for its GLM Coding Plan (https://api.z.ai/api/anthropic, GLM-5.3), a subscription from $18 a month with its own 5-hour and weekly limits. Anthropic doesn't support routing Claude Code to non-Claude models through any gateway: these setups work because the provider imitates Anthropic's API.
What Claude Code Router is
Claude Code Router (claude-code-router on npm and GitHub, CCR for short) is an MIT-licensed local gateway by musistudio, at version 3.1.3 (9 October 2026) with about 38,000 GitHub stars. Claude Code talks to it at http://127.0.0.1:3456 as if it were Anthropic's API, and CCR translates each request for the provider you choose. It's the tool for providers that speak only OpenAI's Chat Completions format.
CCR speaks OpenAI Chat and Responses, Anthropic Messages and Gemini, with presets for OpenRouter, DeepSeek, SiliconFlow, Moonshot, Kimi Code, Mistral, Z.AI and Bailian, plus custom endpoints and local servers such as llama.cpp.
How to set up claude-code-router
The desktop app for macOS, Windows and Linux is the recommended install. The CLI needs Node.js 22 or later:
npm install -g @musistudio/claude-code-router
ccr ui # management UI at http://127.0.0.1:3458
Then, in the management UI:
- Under Providers, add a preset or "Other / custom API endpoint" with a name, base URL and key; CCR detects the protocol and models.
- Under API Keys, create a CCR client key for the gateway.
- Under Server, start the gateway.
- Under Agent Config, add a Claude Code profile with a model, plus optional Opus, Sonnet, Haiku and Fable tier overrides.
- Launch it with
ccr "Claude Code - Work"and check Request logs for which provider served each call.
Version 3 keeps its settings in ~/.claude-code-router/config.sqlite and reads config.json only once, as a migration source, so older guides that edit config.json no longer apply. Tier overrides can put a strong model on Opus and a low-cost one on Haiku, and routing rules can fall back to another model on failure.
The risks of routing Claude Code to other models
- Nobody supports the combination. Each Claude Code release can send something a translation layer doesn't handle: CCR issue #1912 (22 October) reports that a
defer_loadingflag Claude Code puts on one built-in tool makes some upstreams reject every request. - Context limits go wrong. Behind a gateway Claude Code can't detect a model's real window, and issue #1911 reports it assuming 200,000 tokens for unknown models. Set
CLAUDE_CODE_AUTO_COMPACT_WINDOWto the real limit. - The cost shown is wrong. Claude Code estimates session cost from Anthropic's prices and guesses for names it doesn't know. Read the provider's bill or CCR's logs.
- Subscription logins are off limits. CCR can import a local Claude Code login as a provider, but Anthropic's legal page bars third parties from intermediating Claude.ai credentials and allows enforcement without notice. Route API keys only.
- Remote Control is disabled when
ANTHROPIC_BASE_URLisn'tapi.anthropic.com, and Anthropic's HIPAA configuration excludes gateways. - Quality drops on hard work. On Vals AI's Terminal-Bench 4.0 (66 long tasks, mini-swe-agent harness, updated 29 October):
| Model | Tasks passed | Cost per attempt |
|---|---|---|
| Claude Opus 5.5 | 65.2% | $13.20 |
| Claude Sonnet 5.5 | 64.1% | $16.51 |
| GLM 5.3 | 38.9% | $9.37 |
| Claude Haiku 5.5 | 36.4% | $3.12 |
| DeepSeek V4.1 Flash (17 Oct build) | 31.8% | $0.54 |
| Kimi K3 | 17.2% | $12.48 |
For cost per passing task across more models, see Claude alternatives for coding.
Plan vs API key vs routed models: what a month costs
Take 75 sessions like the worked one, about 6,000 model calls or four sessions on most weekdays:
| Option | A month of 75 sessions | What limits it |
|---|---|---|
| Pro plan | $20 | 5-hour and weekly limits; this load likely needs Max |
| Max plan | $100 | 5x Pro |
| Ultra plan | $200 | 10x Pro weekly, no 5-hour limit once verified |
| API key, Opus 5.5 | $282.24 | Tier spend cap ($500 or $1,000) |
| API key, Sonnet 5.5 | $141.12 | Tier spend cap |
| API key, Haiku 5.5 | $8.71 | Weaker on hard tasks |
Bedrock, Opus 5.5, us. profile | $310.46 | Your AWS quotas |
DeepSeek deepseek-flash | $7.47 off-peak, $14.95 peak | Unofficial; lower pass rates |
| Z.ai GLM Coding Plan | From $18 | Its own 5-hour and weekly limits |
For daily use, a plan costs less than any per-token Claude route, as long as its limits hold your work. An API key pays off for occasional use, for CI jobs, and when the bill must land on AWS, Google Cloud or Azure.
Before routing to another maker's model to save money, try Haiku 5.5. It's official, costs about the same per session as DeepSeek ($0.12 against $0.10 to $0.20), and passed more Terminal-Bench 4.0 tasks than DeepSeek V4.1 Flash. A practical mix is Opus or Sonnet in the main session and Haiku for subagents, with CLAUDE_CODE_SUBAGENT_MODEL=claude-haiku-5-5.
What developers report
- "anything it does not recognise falls back to an assumed 200000 tokens" (claude-code-router issue #1911, 22 Oct 2026, link)
- "nothing gets to fully line things up (double-translated tool names for example)" (a Hacker News commenter on proxying OpenAI-format Claude into Claude Code, 22 Jan 2026, link)
- On 9 January 2026, Claude Max logins stopped working in OpenCode; the Hacker News thread "Anthropic blocks third-party use of Claude Code subscriptions" reached 625 points (Hacker News, link; OpenCode issue #7410, link).
- OpenRouter found Claude Code's own cost figure reported $0.16 to $0.31 for routed Haiku sessions that cost about half a cent, and overstated Opus sessions by about 50% (OpenRouter, 30 Oct 2026, link).
If Claude Code then fails to start from an editor with "process exited with code 1", this guide walks through every cause and fix.
Where Aight fits
Claude Code can't use Aight directly: it speaks Anthropic's Messages API, and Aight documents an OpenAI-compatible Chat Completions API. Through claude-code-router, Aight can be added as an OpenAI-compatible provider:
Provider: Other / custom API endpoint
Name: aight
API endpoint: https://api.getaight.ai/v1
API key: sk-aight-...
Protocol: OpenAI Chat
Models: claude-sonnet-5-5, claude-opus-5-5
Treat that as untested. Claude Code needs tool calls on almost every step, and Aight's API reference documents only model, messages and stream for chat completions, so check tool calls and caching with your own key first.
If it works, the saving is small. Aight prices Claude Sonnet 5.5 at Anthropic's $2 / $10, and a $100 recharge adds $110 of balance for $103, so the 75-session Sonnet month comes to about $132.14 instead of $141.12. Max at $100 costs less if its limits hold your work. For DeepSeek, DeepSeek's own endpoint costs half as much off-peak, while Aight charges V4.1 Flash at the peak price around the clock. Aight fits better around Claude Code, for scripts that need a monthly cap and a model list per key; the Claude API pricing guide has the per-token rates.
FAQ
Can Claude Code use an API key and a subscription at the same time?
Not for the same request: an approved ANTHROPIC_API_KEY outranks the plan login. To keep both, give each its own config directory, for example CLAUDE_CONFIG_DIR=~/.claude-work claude for a second login and settings.
How does Claude Code switch from an API key back to a plan?
Run unset ANTHROPIC_API_KEY, remove any apiKeyHelper from your settings files, and turn off "Use custom API key" in /config if it shows. Then check /status.
Is the Claude Code API different from the Claude API?
No. With a key, Claude Code calls Anthropic's Messages API at standard rates, under a "Claude Code" workspace in the Console. The Claude API pricing guide lists every model's rates.
Is claude-code-router safe to use?
It's open source and runs locally, but it sees every prompt and stores your provider keys under ~/.claude-code-router, so protect that folder, keep the management UI on 127.0.0.1, and don't import a Claude subscription login into it.
Why does Claude Code on Bedrock use Sonnet 4.5?
Claude Code's aliases on Bedrock and Agent Platform lag the Anthropic API, so sonnet resolves to Sonnet 4.5 there. Set ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-5-5, or choose the full model name with /model.
Sources
- Claude Code docs: Authentication, Settings, Settings reference, Environment variables, CLI reference, Manage costs, Prompt caching, Model configuration
- Claude Code docs: Enterprise deployment overview, Amazon Bedrock, Google Cloud's Agent Platform, Microsoft Foundry, Claude Platform on AWS, Other LLM gateways, Gateway compatibility guide, Legal and compliance
- Anthropic, API pricing, Rate limits and spend caps, Plans and pricing; @anthropic-ai/claude-code on npm
- AWS, Amazon Bedrock pricing, AWS Price List for Bedrock foundation models, Global cross-Region inference
- Google Cloud, Partner models pricing
- DeepSeek, Integrate with Claude Code, Using the Anthropic API, Models and pricing
- Z.ai, GLM Coding Plan overview, Claude Code setup
- Claude Code Router: GitHub repository, releases, npm package, docs on install, CLI, providers, Claude Code profiles, routing and configuration file; issues #1911 and #1912
- Vals AI, Terminal-Bench 4.0
- OpenRouter, How much does Claude Code cost?
- Hacker News, comment of 22 Jan 2026 and Anthropic blocks third-party use of Claude Code subscriptions; OpenCode, issue #7410
- AWS Developers on YouTube, Running Claude Code on Amazon Bedrock
- Aight, Models and pricing, API reference, Refund policy
Checked on 5 November 2026. Updated 17 November 2026: Aight's current model list; Claude Code 2.1.326 changes nothing else compared here.