Claude API vs Claude Code: Which One to Use and How You Pay
Same Claude models, different jobs: the API is per-token access for your own code; Claude Code is a coding agent that runs on Pro/Max or an API key.
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.
The working rule, as of September 26, 2026: 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. 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 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, 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 |
| 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, 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 | Your Pro or Max plan can't pay for this |
| 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 | 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.
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, according to claude.com/pricing as of September 26, 2026:
| Plan | Price | Claude Code |
|---|---|---|
| Free | $0 | Not included |
| Pro | $20/month, or $17/month billed annually ($200 up front) | Included |
| Max 5x | $100/month | Included |
| Max 20x | $200/month | Included |
Prices exclude tax. Claude Code shares the plan's limits with chat on the web, desktop and mobile. Limits reset on a rolling 5-hour session window, and paid plans add weekly limits. When you hit them, you can wait, upgrade, or turn on usage credits to keep working at standard API rates. Anthropic also points heavy coders to pay-as-you-go API credits through a Console account. If you're deciding between the two subscriptions, Claude Pro vs Max covers the limit differences.
"Credits" means two 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 API rates after you pass your plan's limits. You manage them in claude.ai under Settings > Usage, or with
/usage-creditsin Claude Code, which only works when you're signed in with your claude.ai subscription. - Console API credits 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.
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 cloud sessions on the web work differently: they don't read 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.
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. A Pro or Max plan doesn't give you one. 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 (input / output), as of September 26, 2026 on Anthropic's pricing page:
| Model | Input | Output | Cache hits |
|---|---|---|---|
| Claude Sonnet 5 | $2 | $10 | $0.20 |
| Claude Opus 5.5 | $4 | $20 | $0.20 |
| Claude Haiku 4.5 | $1 | $5 | $0.10 |
| Claude Fable 5.1 | $10 | $50 | $0.25 |
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: 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 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, since repeated context billed as cache hits costs a tenth of the Sonnet 5 input price and a twentieth of Opus 5.5's. And the plan side is not unlimited: the 5-hour and weekly limits cap how many of those sessions fit.
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." 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. 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.
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 5-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?
No. The plan covers Claude's apps and Claude Code. An app that calls Claude needs an API key from the Claude Console, or a cloud provider account, billed per token.





