Claude API vs Claude Code: Which One to Use and How You Pay
The Claude API bills your own code per token; Claude Code runs on Pro, Max or an API key. Max's new monthly API credits don't cover interactive Claude Code.
On this page

The Claude API and Claude Code run the same Claude models, but they sit at different layers and get billed in different ways. The API is raw model access: your code sends a request to api.anthropic.com and you pay per token through a Claude Console account. Claude Code is Anthropic's agentic coding tool. It reads your repo, edits files and runs commands, and it can run on a Pro or Max subscription or on API or cloud credentials. You don't need to buy API credits to use Claude Code. Pro at $20 a month already includes it.
What changed as of October 8, 2026: since October 7, Max and Team plans include monthly API credits ($100 on Max 5x, $200 on Max 20x). They pay for your own API calls, the Agent SDK and claude -p run on a key from a linked Console organization, but not for interactive Claude Code. Sonnet 5.5 and Haiku 5.5 are also new on the API price list.
The working rule still holds: when you are the one coding, use Claude Code on your subscription. When your software is the one calling Claude, use the API with a key, which a Max or Team plan now partly funds. When you ship an agent to other people, it has to authenticate with API keys or cloud credentials, not with your Pro or Max login.
Same models, different layer
Claude Code is not a separate model. When you pick Sonnet 5.5 or Opus 5.5 inside Claude Code, it sends requests to the same models the API serves, and the tokens are charged to whichever credential the session is using. What differs is everything around the model.
| Claude API | Claude Code | |
|---|---|---|
| What it is | Programmatic access through the Messages API and client SDKs | An agent that works in your codebase: reads files, edits them, runs commands, uses your dev tools |
| Where you use it | Your own code, in any language that can make an HTTP request | Terminal, VS Code, JetBrains, the desktop app, the browser |
| Who builds the agent loop | You: prompts, tool definitions, running the tools, retries | Built in: tools, permissions, sessions, hooks, context management |
| How it's paid | Per token on Console billing (Max and Team monthly API credits are spent first), or through Amazon Bedrock, Google Cloud's Agent Platform or Microsoft Foundry | Pro, Max, Team or Enterprise plan usage, or per token when it runs on an API key or cloud credentials |
| Terms that apply | Commercial Terms | Consumer Terms on Free, Pro and Max; Commercial Terms on Team, Enterprise and API |
| Where usage shows up | Console Usage page | Plan usage bars in /usage, or the Console Usage page when on a key |
"Claude Code API" gets used for two different things. Some people mean running Claude Code billed through an API key. Others mean calling Claude Code from a program. Both exist. The first is a question of which credential pays, covered in the credential section below. The second is claude -p and the Agent SDK, covered after that.
Pick the surface by the job
Anthropic's own Agent SDK overview splits Claude tooling into four surfaces: the Claude Code CLI, the Agent SDK, the client SDKs for the API, and Managed Agents. The table below maps common jobs to those surfaces and adds what each one can authenticate with, where the cost lands, and the line you can't cross.
| Your job | Use | Credentials that work | Where the cost lands | Boundary to know |
|---|---|---|---|---|
| Write, refactor and debug in your own repo | Claude Code CLI or IDE extension | Pro/Max login (the default), Team/Enterprise login, Console login or ANTHROPIC_API_KEY, or a cloud provider | Your plan's usage pool, shared with chat; or per token on Console or cloud billing | The Free plan doesn't include Claude Code. An approved ANTHROPIC_API_KEY outranks your login. Max and Team monthly API credits never pay for interactive sessions |
| Scripted task or CI job on your own code | claude -p, or the Agent SDK in Python or TypeScript | ANTHROPIC_API_KEY or apiKeyHelper; CLAUDE_CODE_OAUTH_TOKEN from claude setup-token on Pro, Max, Team or Enterprise; cloud credentials | Per token (on Max or Team, monthly API credits first when the key is from the linked org), or your plan's pool when using the OAuth token | In -p, a key that is present is always used. --bare never reads OAuth, so it needs a key |
| Add a Claude feature to your app: chat, summaries, extraction, classification | Messages API through a client SDK | Console API key, or a cloud provider | Per token on Console or cloud billing | Plan usage limits can't pay for this. Max and Team monthly API credits can, through the linked Console org |
| Ship an agent with file and shell tools to other people | Agent SDK inside your own service | API key or cloud credentials | Per token, on your account | No claude.ai login for your users, and no routing their requests through a Pro or Max plan |
| Let Anthropic host the agent for your product | Managed Agents | Claude API key; the agent is configured through the API | Claude API billing, which Max and Team monthly API credits also cover | Anthropic runs the agent loop; sessions run in its cloud sandbox or a self-hosted one |
| Offer Claude Code itself inside your product, such as in a hosted sandbox | The unmodified Claude Code binary | Each end user's own API key, subscription or cloud credential | The end user's own account | Commercial Terms; you can't pay for, resell or intermediate their usage |

Two rows cause most of the confusion.
The CI row is where subscriptions and keys meet. A CLAUDE_CODE_OAUTH_TOKEN generated by claude setup-token lets a pipeline run on your Pro or Max plan, which is fine for your own repos. The catch is that the token only works outside bare mode, and Anthropic says --bare "will become the default for -p in a future release." A pipeline that depends on the subscription token should be ready to switch to an API key when that default changes. On Max or Team, that switch now costs less than it used to: a key from the Console organization linked to your plan draws the monthly API credits first, as long as you run claude -p yourself. Runs started by the Claude Code GitHub Action count as Claude Code usage, so the credits don't cover them, even with -p.
The "ship an agent" row is a policy line, not a technical one. Anthropic's legal and compliance page says developers building products or services, including with the Agent SDK, "should use API key authentication through Claude Console or a supported cloud provider," and that third parties may not offer Claude.ai login or "route requests through Free, Pro, or Max plan credentials on behalf of their users." The same page makes clear what is still allowed: an end user signing in to the unmodified Claude Code binary with their own subscription, and a company configuring its own API keys for its own authorized users. Anthropic says it may enforce these rules without prior notice.
For hosted agents specifically, Claude Managed Agents compares the hosted runtime with a Messages API loop and the Agent SDK.
Do you need the API to use Claude Code?
No. Every paid Claude plan includes Claude Code. The prices below come from Anthropic's Pro and Max help pages as of October 8, 2026, and the annual Pro option from claude.com/pricing:
| Plan | Price | Claude Code | Monthly API credits |
|---|---|---|---|
| Free | $0 | Not included | None |
| Pro | $20/month, or $17/month billed annually ($200 up front) | Included | None |
| Max 5x | $100/month | Included | $100 |
| Max 20x | $200/month | Included | $200 |
Prices are in USD for US web subscriptions. Mobile and local-currency prices can differ, and tax depends on the region. Claude Code shares the plan's limits with claude.ai and Claude Desktop. Each plan has a session limit that resets every five hours, and Pro and Max add a weekly limit that resets at a fixed time assigned to your account. Max 5x and Max 20x give five and twenty times Pro's per-session allowance. Anthropic publishes no message or token counts. Fable models work differently: on Pro they run on usage credits from the first request, while Max can spend up to 50% of its weekly limit on Fable 5 and Fable 5.1. When you hit a limit, you can wait, upgrade, or turn on usage credits to keep working at standard API rates. Claude usage limits by plan explains what the 5x and 20x multiply, and Claude Pro vs Max covers which tier fits Claude Code.
"Credits" now means three different things here, and mixing them up is a common way to pay twice:
- Usage credits are overflow on a Pro or Max plan, billed at standard API rates after you pass your plan's limits. You turn them on in claude.ai under Settings > Usage, or manage them with
/usage-creditsin Claude Code, which only works when you're signed in with your claude.ai subscription. - Console API credits are what you buy to fund an API key. They pay for your own API calls, and for Claude Code only when Claude Code is signed in to Console or running on that key. They don't add anything to your Pro or Max limits.
- Monthly API credits come with Max and Team since October 7, 2026. They land in a Console organization you link and are spent before any credits you bought there. They also leave your plan limits untouched.
A limit reset is a fourth, separate thing: it refills your five-hour or weekly plan limit for free and adds nothing to the API side. Claude cloud session credit vs usage credits vs limit reset sorts those out, including the cloud session credit whose claim deadline was October 7, 2026.
Do Max's monthly API credits cover Claude Code? Only headless runs
Not the way most people use it. Interactive Claude Code is excluded, even when the session runs on a key from the linked organization. Here is the split as of October 8, 2026, from Anthropic's help article on monthly API credits for Max and Team plans:
| What you run | Paid by the monthly API credits? |
|---|---|
| Messages API and Message Batches API calls | Yes |
| Console Playground | Yes |
| Claude Managed Agents | Yes |
claude -p or the Agent SDK, run yourself with an API key from the linked Console organization | Yes |
claude -p or the Agent SDK while signed in with your Claude plan | No, it draws your plan's usage limits |
| Interactive Claude Code in the terminal, IDE, desktop app or web, even on the linked key | No |
Runs started by the Claude Code GitHub Action, an IDE extension or the desktop app, even with -p | No, they count as Claude Code usage |
| Usage credits (extra usage) in Claude, Claude Code or Cowork | No |
| Claude on Amazon Bedrock, Google Cloud Vertex AI or Microsoft Foundry | No |
The amounts: Max 5x gets $100 a month and Max 20x gets $200. Team plans get $20 per Standard seat and $100 per Premium seat, pooled into one balance capped at $500 a month. Three Standard seats and two Premium seats, for example, come to $260. Free, Pro and Enterprise aren't eligible.
How it works in practice:
- Claiming. After seven days on the plan, link one Console organization in claude.ai under Settings > Billing (Max) or Organization settings > Billing (Team owners). You can link only one, and Anthropic is rolling the offer out over a few days, so it may not show up yet.
- Spending. Create the API key inside that linked organization. The monthly credits are used before any credits you bought there.
- Expiry. The balance refreshes each billing cycle and doesn't roll over.
- Running out. When it's gone, requests keep going only if the organization has bought credits or set up auto-reload. Otherwise they stop until the next cycle. Nothing is ever charged to your Claude plan.
So, can you use your API key in Claude Code? Yes, and the next section shows how it takes over billing. But on Max, pointing interactive Claude Code at the linked key doesn't make it free: the monthly credits don't apply, so those sessions spend credits you bought in that organization while your included plan usage sits unused. For day-to-day coding, stay signed in with the plan. The monthly credits pay off for the scripts, agents and apps you build.
Which account Claude Code is actually billing
Claude Code checks for credentials in a fixed order and uses the first one it finds. Simplified from Anthropic's authentication docs:
- A cloud provider, when
CLAUDE_CODE_USE_BEDROCK,CLAUDE_CODE_USE_VERTEXorCLAUDE_CODE_USE_FOUNDRYis set ANTHROPIC_AUTH_TOKEN, used for LLM gateways and proxiesANTHROPIC_API_KEY- An
apiKeyHelperscript CLAUDE_CODE_OAUTH_TOKENfromclaude setup-token- Anthropic profile and federation credentials
- Your subscription login from
/login

The subscription login is last. If a key from another project sits in your shell profile and you approved it once when Claude Code asked, your sessions bill per token to that Console account even though you pay for Max. In interactive mode you can change that choice with the "Use custom API key" toggle in /config. In -p mode there's no prompt: a key that is present is always used.
To go back to the subscription and confirm it:
unset ANTHROPIC_API_KEY
claude
# inside the session, run /status/status shows the active login method, and when both a login and a key are configured it marks the one that isn't in use. Remove the key from your shell profile too, or it comes back in the next terminal. The desktop app and browser-based cloud sessions ignore these environment variables and sign in with your claude.ai login, except when the desktop app is set up for third-party inference.
If the numbers still don't add up, Claude Code API billing vs subscription walks through the diagnosis in more depth. For settings files, gateways and Bedrock, Google Cloud or Foundry setup, see Claude Code API configuration.
Can Claude Code be used as an API?
Claude Code itself isn't an HTTP endpoint. The closest hosted option is Managed Agents, an agent harness Anthropic runs for you and you configure through the Claude API. What you can do with Claude Code is run its agent from your own programs. The headless docs describe the Agent SDK as available both as a CLI for scripts and CI/CD and as Python and TypeScript packages.
# Runs with your normal configuration: CLAUDE.md, hooks, MCP servers
claude -p "Find and fix the bug in auth.py" --allowedTools "Read,Edit,Bash"
# Bare mode: skips that configuration and needs ANTHROPIC_API_KEY or apiKeyHelper
claude --bare -p "Summarize README.md" --allowedTools "Read"From a language other than Python or TypeScript, run the CLI as a subprocess with -p and --output-format json.
Two details decide whether a headless setup works and whether it's safe:
- Credentials. Bare mode never reads OAuth credentials or the system keychain, and it ignores
CLAUDE_CODE_OAUTH_TOKEN. A subscription-based CI job therefore only works without--bare. Bedrock, Google Cloud's Agent Platform and Foundry keep reading their own credentials in either mode. - What runs before the model does. Without
--bare, a-psession runs the hooks in the project's.claude/settings.jsonand connects the servers in its.mcp.json, even in a folder you've never trusted, with no trust dialog. Point a non-bare job at code you didn't write and you're running that code's hooks. Anthropic recommends--barefor scripted and SDK calls.
Headless runs are also the one place Claude Code and the Max or Team monthly API credits meet. With an API key from the linked organization, claude -p and the Agent SDK spend those credits. Signed in with your plan, the same commands draw your plan's usage limits instead.
On the policy side, Pro and Max limits "assume ordinary, individual usage of Claude Code and the Agent SDK." Running claude -p against your own repo on your own plan fits that. Running it on behalf of customers doesn't: that is the "ship an agent" row in the table above, and it needs API or cloud credentials.
What calling the API directly looks like
The API has no built-in idea of files, a terminal or your repo. This is Anthropic's quickstart request against the Messages API:
curl https://api.anthropic.com/v1/messages \
-H "content-type: application/json" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-opus-5-5",
"max_tokens": 1000,
"messages": [
{"role": "user", "content": "Explain what a race condition is in two sentences."}
]
}'You get a JSON message back, and nothing on your machine changes unless your code acts on the reply. To turn this into a coding agent you would define tools, execute them, send the results back and repeat, either by hand or with the client SDK's beta tool runner. The Agent SDK exists so you don't have to rebuild that loop, which is why "embed Claude Code's agent in my app" and "call the API" are different jobs even though both bill per token.
API keys come from the Claude Console at platform.claude.com, whatever plan you have. Pro includes no API usage through the Console. Max and Team don't hand you a key either, but their monthly API credits arrive in the Console organization you link, and a key you create there spends them. Claude API key: how to get one covers creating a key and adding credits.
Subscription or API billing for Claude Code: the rough math
List prices for the API, per million tokens, as of October 8, 2026 on Anthropic's pricing page:
| Model | Input | Output | Cache hits |
|---|---|---|---|
| Claude Sonnet 5.5 | $2 | $10 | $0.10 |
| Claude Sonnet 5 | $2 | $10 | $0.20 |
| Claude Opus 5.5 | $4 | $20 | $0.20 |
| Claude Haiku 5.5 (prompts up to 100,000 tokens) | $0.10 | $0.50 | $0.01 |
| Claude Haiku 4.5 | $1 | $5 | $0.10 |
| Claude Fable 5.1 | $10 | $50 | $0.25 |
Haiku 5.5 costs more on prompts over 100,000 tokens: $0.50 input, $2.50 output and $0.05 for cache hits. Sonnet 5's $2 / $10 launch price is now the standard price; the increase to $3 / $15 that had been scheduled for September 1, 2026 was canceled.
To compare against a plan, assume one agentic coding session uses 2 million input tokens and 150,000 output tokens. That's an assumption for illustration, not a measurement; your sessions may be much larger or smaller. At list price with no caching:
- Sonnet 5.5 or Sonnet 5: 2 × $2 + 0.15 × $10 = $5.50 per session
- Opus 5.5: 2 × $4 + 0.15 × $20 = $11.00 per session
| Sessions per month | Sonnet 5.5 on API | Opus 5.5 on API | Plan price |
|---|---|---|---|
| 3 | $16.50 | $33.00 | Pro $20 |
| 20 | $110 | $220 | Max $100 or $200 |
Read that in both directions. Under this assumption, someone who codes with Claude most days passes the Pro price within four sessions on the API, so a subscription is usually the cheaper route as long as its limits hold. Someone who opens Claude Code a few times a month on Sonnet can come in under $20 on a key. Prompt caching changes the API side a lot: repeated context billed as cache hits costs a twentieth of the input price on Sonnet 5.5 and Opus 5.5, and a tenth on Sonnet 5. And the plan side is not unlimited: the five-hour and weekly limits cap how many of those sessions fit.
Max's monthly API credits don't change this comparison for interactive coding, because they can't pay for it. They do mean a Max subscriber's own API calls, Agent SDK runs and keyed claude -p jobs get the first $100 or $200 a month at no extra charge.
For a team-level reference, Anthropic's cost docs report that across enterprise deployments Claude Code averages about $13 per developer per active day and $150–250 per developer per month, with 90% of users under $30 per active day. That comes from enterprise usage, not a forecast for one person. On Enterprise plans, seats are $20 a month plus usage at API rates, so the per-token math applies there as well.
For your actual numbers, use the Console Usage page. The session cost in /usage is computed locally at list price and, on Pro and Max, isn't what you're billed. The detailed keep-or-switch scenarios are in Claude Code heavy users: keep subscription, downgrade, or use API, and plan-by-plan prices and extra usage in the Claude Code pricing guide.
Three expensive mix-ups and how to spot them
Paying API rates for work your plan already covers. Symptom: Console charges keep growing while your Max usage bars barely move. Check /status in Claude Code, then run env | grep ANTHROPIC in the same shell. If a key shows up and you didn't mean to use it, unset it, remove it from your shell profile and any env block in your Claude Code settings, and confirm with /status again.
Buying Console credits "to use Claude Code," or expecting Max's API credits to pay for it. If you're on Pro or Max and signed in with /login, Claude Code already runs on your plan. Console credits only matter if you deliberately switch Claude Code to a key or Console login, or for your own API calls. The same goes for the monthly API credits on Max: they never cover interactive Claude Code, even on the linked key. Past your plan's limits, usage credits on the plan are the other option.
Powering a product with a subscription login. If other people's requests go through your app, the credential has to be an API key from the Console or a cloud provider. A Pro or Max login, or a CLAUDE_CODE_OAUTH_TOKEN, behind a service for other users is exactly what Anthropic's terms rule out.
New to the tool entirely? Start with how to install Claude Code and sign in with your plan. You can add a key later if a real job needs one.
FAQ
Can I use my Claude API key in Claude Code?
Yes. Set ANTHROPIC_API_KEY and Claude Code asks you to approve it on first launch. Once approved it takes priority over your subscription login, and usage bills per token to that key's Console account. /status shows which one is active. On Max or Team, a key from the linked organization spends the monthly API credits only in claude -p or Agent SDK runs you start yourself. Interactive sessions on that key bill per token as usual.
Is Claude Code better with an API key or a subscription?
The tool and the models are the same either way. The difference is billing and limits. A subscription is usually cheaper for regular daily coding but has five-hour and weekly limits. An API key isn't bound by the plan's usage windows and bills every token, which suits occasional use, bare-mode automation, and teams that need usage on a company account.
Does a Pro or Max plan include API access for my own apps?
Pro doesn't: its usage stays inside Claude's apps and Claude Code. Max does, as of October 7, 2026: $100 a month on Max 5x and $200 on Max 20x in API credits, once you link a Claude Console organization and create a key there. Team plans get pooled per-seat credits. Beyond those amounts, your app is billed per token like any other Console account.
Sources8
External pages this guide links to, in the order they appear. Last updated Oct 8, 2026.
Sources8
External pages this guide links to, in the order they appear. Last updated Oct 8, 2026.
- 1.Agent SDK overviewcode.claude.com/docs/en/agent-sdk/overview
- 2.legal and compliance pagecode.claude.com/docs/en/legal-and-compliance
- 3.claude.com/pricingclaude.com/pricing
- 4.help article on monthly API credits for Max and Team planssupport.claude.com/en/articles/17154008-monthly-api-credits-for-max-and-team-plans
- 5.authentication docscode.claude.com/docs/en/authentication
- 6.headless docscode.claude.com/docs/en/headless
- 7.pricing pageplatform.claude.com/docs/en/about-claude/pricing
- 8.cost docscode.claude.com/docs/en/costs





