How to Get a Claude API Key (and How to Use It)
If you want to build with Claude programmatically, you need a Claude API key — a credential that authenticates your requests to Anthropic's API instead of the claude.ai chat interface. This guide walks through how to get one, what it costs, how to use it in code, and what to watch out for.
There are two separate ways people end up needing "Claude access": a personal claude.ai subscription for chatting in the browser, and an API key for calling Claude from your own application. They are billed differently and serve different purposes, which is the source of most confusion around this topic.
Getting a Claude API key from Anthropic
- Go to console.anthropic.com and sign up or log in.
- Navigate to the API Keys section of the console.
- Click Create Key, give it a name (e.g.
production-backend), and copy the value immediately — Anthropic only shows it once. - Add billing details. Anthropic's API is pay-as-you-go, priced per million input/output tokens, separate from any claude.ai Pro or Max subscription you might have.
- Store the key in an environment variable, never in source code.
export ANTHROPIC_API_KEY="sk-ant-..."
A basic request looks like this:
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Explain what a REST API is"}]
}'
That's the direct path: create a key, fund it, call the endpoint.
Why a plain API key isn't always enough
An Anthropic API key is a single, flat credential. That's fine for a prototype, but it creates friction once you're building a real product:
- No per-user or per-app keys. Every request uses the same key, so you can't tell which customer, feature, or environment generated a given call without building that tracking yourself.
- No built-in team structure. If three developers need access, they either share one key (bad for auditing and rotation) or you build your own key-management layer.
- Usage visibility is limited. You get aggregate billing, not a clean breakdown of tokens by application or team member.
- You're billed on top of any personal Claude subscription. If you already pay for Claude Pro or Max, API usage is a separate, additional cost with its own per-token pricing.
For a side project, none of this matters. For a team shipping a product on top of Claude, it usually does.
Using SubToAPI instead of (or alongside) a raw API key
SubToAPI turns your existing Claude access into a proper HTTPS API layer, with application-level keys instead of one shared secret. You get:
- Scoped keys per app or environment (
sub_live_...), so staging, mobile, and web backends each have their own credential you can revoke independently. - Streaming and tool use through the same interface you'd expect from a standard Claude integration — see /docs/streaming and /docs/tools.
- Usage metadata per key, so you can see exactly which application or team member is consuming tokens.
- Team seats on the Team (€19/seat) and Scale (€49/seat) plans, or a single-user Solo plan at €9, all with a free trial at signup.
A request through SubToAPI looks nearly identical to the direct Anthropic call, just pointed at a different host with your sub_live_ key:
curl https://api.subtoapi.app/v1/messages \
-H "Authorization: Bearer $SUBTOAPI_KEY" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Explain what a REST API is"}]
}'
If you're already paying for Claude and just want a clean, key-based API in front of it — with per-app keys and usage tracking instead of managing raw Anthropic credentials yourself — /docs/quickstart walks through setup in a few minutes, and /docs/messages covers the request format in detail.
Securing your Claude API key
Whether it's a raw Anthropic key or a SubToAPI key, treat it like a password:
- Never commit it to git. Use
.envfiles and add them to.gitignore. - Use environment variables in production, injected by your hosting platform's secret manager, not hardcoded.
- Rotate keys periodically, especially after any team member leaves or a key is accidentally exposed in logs or a client-side bundle.
- Never call the API directly from frontend JavaScript. The key would be visible in the browser. Always proxy requests through your own backend.
- Use separate keys per environment (dev, staging, production) so a leaked staging key doesn't compromise production.
// server.js — never expose this key to the browser
const response = await fetch("https://api.subtoapi.app/v1/messages", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "claude-sonnet-4-5",
max_tokens": 1024,
messages: [{ role: "user", content: "Summarize this ticket" }],
}),
});
(Fix the typo above in real code — max_tokens should not have a stray quote.)
Choosing the right approach
- Solo prototype or experiment: get a key directly from the Anthropic console and start calling the API.
- Product with multiple developers or environments: you'll want per-key isolation and usage tracking, whether you build it yourself or use a layer like SubToAPI.
- Team already relying on Claude and wanting a simpler billing/API story: check /pricing to compare Solo, Team, and Scale plans against managing raw API keys and billing yourself.
Either path gets you talking to Claude programmatically — the right one depends on whether you're shipping a quick script or a product with real users behind it.
Questions
Is a Claude API key the same as a claude.ai login? No. A claude.ai login is for the web chat interface; an API key authenticates programmatic requests and is billed separately, per token.
How much does a Claude API key cost? There's no fee for the key itself — Anthropic charges per million input/output tokens consumed, varying by model. SubToAPI instead offers flat monthly pricing starting at €9 (Solo), see /pricing.
Can I use one API key across multiple apps? You can, but it's not recommended — it makes usage tracking and revocation harder. Per-app keys, like SubToAPI's sub_live_ keys, keep environments and applications isolated.