Running Claude Code on an API key: rates and real costs

Claude Code runs perfectly well against an API key instead of a subscription. It is usually more expensive and occasionally the only option that works, and the distinction is about the shape of your usage rather than its size.

By the Continuum team. We build a workbench that runs Claude Code, Codex, and their peers, so the model rates quoted here are the ones our own cost analytics ship with.

The short version

On an API key, Claude Code bills per token with no usage windows: Opus 5 at $5 in and $25 out per million, Sonnet 5 at $3 and $15 standard, Haiku 4.5 at $1 and $5, as of August 2026. Cache reads cost 0.1x base input, a five-minute cache write 1.25x, and a one-hour write 2x. Anthropic reports an average of about $13 per developer per active day and $150 to $250 per developer per month across enterprise deployments. A key wins for CI, automation, spiky use, and weeks when a subscription cap is exhausted.

What you need to know
  • No windows, no caps, no ceiling on the bill. That is the trade in both directions.
  • Cache reads cost 0.1x base input, the single most important number for agent workloads.
  • The default cache lifetime on a key is five minutes, against an hour on a subscription.
  • Anthropic's own metered average is $150 to $250 per developer per month, more than Max 5x.
  • Set a workspace spend limit in the Claude Console on day one. It is the only real guardrail.
  • CI, scheduled jobs, and anything you ship must use a key. A subscription is not licensed for it.

The rates

Per-million token rates for the models Claude Code uses, read from Anthropic in August 2026.

ModelInput5m cache write1h cache writeCache readOutput
Claude Opus 5$5.00$6.25$10.00$0.50$25.00
Claude Sonnet 5 (from 1 Sep 2026)$3.00$3.75$6.00$0.30$15.00
Claude Sonnet 5 (through 31 Aug 2026)$2.00$2.50$4.00$0.20$10.00
Claude Haiku 4.5$1.00$1.25$2.00$0.10$5.00

The cache lifetime is the trap

On a subscription the cache lifetime is an hour. On an API key or a cloud provider it is five minutes by default. That difference is not cosmetic for agent work: park a 150k-token session while you go to a meeting, come back, ask one more question, and you have just reprocessed 150k tokens at full input price. On Sonnet 5 standard rates that is $0.45 for a question you thought was free.

What is not a modifier any more

Long context used to carry a premium above a threshold. It does not on current models: Claude 4.6 and later include the full 1 million token context window at standard pricing, so a 900k-token request bills at the same per-token rate as a 9k one. The Batch API still takes 50 percent off both input and output, but batch is asynchronous and therefore irrelevant to an interactive Claude Code session.

Two lanes on one clock: after a 25 minute break the subscription cache is still warm and the next turn is a cheap cache read, while the API key cache expired at five minutes and the next turn reprocesses the whole context at full price010m20m30m40msubscription1 hourcache warm0.1x readabout $0.05API key5 minutescache expired1x reprocessabout $0.45you come back 25 minutes laterSame session, same gap. Only the lifetime differs, and it costs ten times more.

How to connect Claude Code to a key

01

Create the key in a workspace you can cap

In the Claude Console, create an API key inside a workspace you can put a spend limit on. Do not use a personal default workspace for agent work; you want the spend isolated and capped.

02

Set the spend limit before you use it

Workspace spend limits and alerts are the only thing standing between a runaway loop and a large invoice. Set both a warning threshold and a hard limit. If you have custom organization rate limits, set a workspace rate limit too, so Claude Code cannot starve your production traffic.

03

Point Claude Code at it

Claude Code uses the key when one is present in the environment.
export ANTHROPIC_API_KEY="sk-ant-..."
claude
04

Confirm which billing you are on

Run /status inside Claude Code. It reports the active credential. This is worth checking before every long run: a stray ANTHROPIC_API_KEY left in a shell profile is the single most common cause of both surprise invoices and unexplained 429s.

Two seconds now, or a reconciliation later.
echo "$ANTHROPIC_API_KEY"    # non-empty means metered billing
unset ANTHROPIC_API_KEY     # for shells where you want the subscription
05

Find the auto-created workspace

When you first authenticate Claude Code with a Claude Console account, a workspace called "Claude Code" is created automatically. You cannot create API keys inside it; it exists for centralized Claude Code cost tracking. Set a spend limit and, if your organization has custom rate limits, a workspace rate limit on it.

When the key genuinely wins

SituationWhy a key is right
CI pipelinesNo interactive session exists. A subscription cannot apply.
Scheduled and unattended runsSame. Also nobody to clear a limit at 3am.
A product you shipSubscriptions are not licensed for redistribution.
Spiky useA quiet month costs nothing rather than $100.
A blocked weekNo usage windows, so an exhausted weekly cap stops mattering.
Very high parallelismThroughput limits are per minute, not a weekly quota.
Bedrock, Google Cloud, or Microsoft Foundry shopsBilling already lives in the cloud account.

What is not on that list is the most common reason people end up on a key: they arrived through the developer docs and never saw the plan page. For daily interactive coding, Anthropic's own metered average of $150 to $250 per developer per month is one and a half to two and a half times what Max 5x costs for the same work.

Sizing rate limits for a team

Spend is not the only thing to size on a key. Claude Code is bursty and parallel, and an organization that provisions throughput per user the way it would for a web app will 429 constantly. Anthropic publishes per-user recommendations that scale down with headcount, because fewer people use the agent concurrently in a larger org.

Anthropic's per-user TPM and RPM recommendations for Claude Code, by team size.

Team sizeTPM per userRPM per user
1 to 5 users200k to 300k5 to 7
5 to 20 users100k to 150k2.5 to 3.5
20 to 50 users50k to 75k1.25 to 1.75
50 to 100 users25k to 35k0.62 to 0.87
100 to 500 users15k to 20k0.37 to 0.47
500+ users10k to 15k0.25 to 0.35

Multiply through: 200 users at 20k TPM each is 4 million TPM at the organization level. The limits apply org-wide, not per person, so individual developers can temporarily exceed their calculated share when others are idle. Budget higher for events where everyone runs at once, like a training session.

Keeping the bill sane

  1. Workspace spend limits in the console. Non-negotiable. Set them before the first run, not after the first surprise.
  2. Default to Sonnet or Haiku. Opus output is five times Haiku. Escalate per task, not per default, and use model: haiku for simple subagents.
  3. Keep sessions short and topical. Context carries forward and you pay for it on every request. /clear costs nothing; /compact reads the whole conversation it summarizes, so it is itself a large request.
  4. Mind the five-minute cache window. Coming back to a parked session after lunch reprocesses everything at full input price on a key.
  5. Filter tool output before the model sees it. A PreToolUse hook that greps a test run for failures turns tens of thousands of tokens into hundreds.
  6. Cap autonomous runs and agent teams. Agent teams use roughly 7x the tokens of a standard session in plan mode and are off by default. Leave them off unless you mean it.
  7. Review spend weekly. Monthly is too late to change anything.

Where per-user numbers actually come from

The Console dashboard shows spend and accepted lines per member, and the Claude Code Analytics API returns the same daily per-user metrics with an Admin API key. On Bedrock, Google Cloud, or Microsoft Foundry none of that applies, because Claude Code does not send metrics from your cloud back to Anthropic; there the options are OpenTelemetry export from each machine, a self-hosted Claude apps gateway, or an LLM gateway that tracks spend per key.

Questions people ask

Per million tokens: Opus 5 at $5 in and $25 out, Sonnet 5 at $3 and $15 standard ($2 and $10 on introductory pricing through 31 August 2026), Haiku 4.5 at $1 and $5. Cache reads cost 0.1x base input, which matters enormously for agent sessions.

Rarely, for interactive coding. Anthropic reports an average of $150 to $250 per developer per month on metered billing, against $100 for Max 5x. The API wins on shape rather than price: CI, automation, spiky use, and anything you ship.

Set ANTHROPIC_API_KEY in the environment before launching, then run /status inside Claude Code to confirm which credential is active. Unset it in shells where you want subscription billing.

Yes. Claude Console workspaces support spend limits and alerts, and Claude Code gets an auto-created workspace on first sign-in. Set both a warning threshold and a hard limit before your first agent run; a runaway loop is the failure mode they exist for.

Claude Code manages caching as part of how it constructs requests, so you do not configure it per call. You benefit most when a session has a large stable prefix, which is the normal shape of agent work. Watch the lifetime: five minutes by default on a key, an hour on a subscription.

Yes, but only one is active per session and which one depends on your environment. Check /status before a long run rather than assuming. A stray ANTHROPIC_API_KEY is the usual cause of unexpected metered spend.

That is a per-minute throughput limit, not a quota. Run /status to confirm the active credential is the one you meant, check your provider console for the current tier, then lower CLAUDE_CODE_MAX_TOOL_USE_CONCURRENCY and avoid large parallel subagent fan-outs.

No. Claude 4.6 and later include the full 1 million token context window at standard pricing. The relevant change is the tokenizer on 4.7-generation models, which produces about 30 percent more tokens for the same text.

Sources

Every figure above was read from these pages on August 2026. Vendors reprice without notice; if you find a stale number, tell us.

  1. Anthropic API pricing
  2. Anthropic plans and pricing
  3. Claude Code documentation
Try it

Know the number
before the invoice.

Continuum prices every session from the files the CLI already writes, so API spend by repo and by day is visible the same day it happens.

free app · your subscriptions · local-first