Can I use Claude Code with an API key?

Updated 2026-07-15Asked across Reddit, Quora & Google· Claude Code
Short answer

Yes. Claude Code works with an Anthropic Console/API account instead of a subscription. You authenticate once, and usage is billed per token—Claude Opus 4.5 runs $5 per million input and $25 per million output tokens (as of 2026-07). You can also point it at Amazon Bedrock, Google Cloud, or Microsoft Foundry with those providers' keys.

Why — the first-principles explanation

Claude Code separates two jobs: who runs the tool and who pays for the compute. A subscription bundles both into a flat fee. An API key unbundles them—you're telling Claude Code, 'bill my usage to this Anthropic Console account, per token.' The tool behaves the same either way; only the billing pipe changes.

Why pick the API route? Because it's pay-as-you-go with no monthly minimum. For light, bursty, or automated use—a nightly script, a CI job—paying only for the tokens you consume can be cheaper than a subscription. It also gives teams centralized cost tracking: when you authenticate Claude Code with a Console account, Anthropic auto-creates a 'Claude Code' workspace where all that usage is metered and capped with spend limits.

There's a broader version of the same idea. Claude Code can also authenticate through cloud providers—Amazon Bedrock, Google Cloud's Agent Platform, or Microsoft Foundry—using their credentials. Then the compute is billed to your cloud account, not directly to Anthropic. So 'can I use an API key' really means: yes, and you can choose which billing relationship—Anthropic direct, or your cloud provider—handles the tokens.

An example that makes it click

Think of a rental car you can drive two ways. Option one is a monthly membership: flat fee, drive all you want (the subscription). Option two is pay-per-mile with a fuel card (the API key): the car's identical, but now every mile is metered to your account. If you only drive occasionally, the fuel card is cheaper. And if your company already has a fleet account with a fuel supplier—that's Bedrock or Google Cloud—you can charge the miles there instead.

How to do it

  1. Create an account at the Anthropic Console (platform.claude.com) and add a payment method.
  2. Start Claude Code and choose the Console/API sign-in option when prompted (instead of a subscription login).
  3. On first API authentication, Anthropic auto-creates a 'Claude Code' workspace for centralized cost tracking.
  4. Optionally set a workspace spend limit in the Console to cap what Claude Code can bill.
  5. For cloud billing instead, configure Claude Code to use Amazon Bedrock, Google Cloud, or Microsoft Foundry credentials.

Key facts

Infographic: Can I use Claude Code with an API key — short answer and key facts
Visual summary — Can I use Claude Code with an API key?
CC
Try Claude Code by Anthropic

Anthropic's agentic coding tool that works in your terminal.

Affiliate link — we may earn a commission at no cost to you.
Visit Claude Code ↗
▶ The 60-second explainer (script)

Can you use Claude Code with an API key? Yes—and it's a common choice. Instead of a monthly subscription, you sign in with an Anthropic Console account, and your usage gets billed per token. The tool works exactly the same; only the billing changes. Why go this route? It's pay-as-you-go, no monthly minimum, so for light or automated use it can be cheaper. On the top model, Opus, you're looking at about five dollars per million words in and twenty-five out. When you first authenticate, Anthropic automatically spins up a 'Claude Code' workspace so all your usage is tracked in one place, and you can set a spend limit to cap it. There's a bonus option too: you can point Claude Code at your cloud provider—Amazon Bedrock, Google Cloud, or Microsoft Foundry—and have the tokens billed to your cloud account instead. So yes, API key works, and you even get to pick which account foots the bill.

What authoritative sources say

Claude Code Docs — Overviewofficial — Most surfaces require a Claude subscription or an Anthropic Console account; the Terminal CLI and VS Code also support third-party providers. source ↗
Claude Code Docs — Manage costsofficial — First-time Console authentication auto-creates a 'Claude Code' workspace, and workspace spend limits can cap usage. source ↗
Anthropic Platform — Pricingofficial — Claude Opus 4.5 API pricing is $5 per million input tokens and $25 per million output tokens. source ↗

People also ask

Do I need a subscription if I have an API key?

No. An Anthropic Console/API account is an alternative to a subscription. You pay per token instead of a flat monthly fee.

Is the API cheaper than a subscription?

For light or automated use, often yes. For heavy daily coding, a flat subscription usually caps cost more predictably.

How do I control API spend?

Claude Code creates a 'Claude Code' workspace on first login; set a workspace spend limit in the Console to cap billing.

Can I use Claude Code through Amazon Bedrock or Google Cloud?

Yes. Claude Code supports Bedrock, Google Cloud, and Microsoft Foundry, billing tokens to your cloud account.

Related questions