How to Generate API Keys for Claude (2 Ways)
How to Generate API Keys for Claude
There are two legitimate ways to get a Claude API key, and which one you need depends on how you're already paying for Claude. If you don't have any Claude access yet, you create an Anthropic Console account, add billing, and generate a key from the dashboard — that's the direct path to the official Anthropic API. If you already pay for a Claude subscription (Pro, Team, or Max) and just want to call Claude from your own code without setting up separate usage-based billing, a service like SubToAPI generates an HTTPS API key (sub_live_...) from your existing Claude access instead.
Both paths give you a bearer token you put in an Authorization header. The difference is billing and account setup, not the shape of the API itself. Below is how to do each one, plus how to manage keys once you have them.
Option 1: Generate a key directly from Anthropic
This is the standard route if you want to pay-as-you-go for API usage separately from any chat subscription.
- Create an account at the Anthropic Console (console.anthropic.com).
- Add a payment method. The API is billed by token usage, not a flat subscription, so you need a card on file before keys will work in production.
- Go to Settings → API Keys and click "Create Key." Give it a descriptive name (e.g.,
prod-backend,staging-worker) — you'll thank yourself later when you have five keys and need to know which one is live. - Copy the key immediately. Anthropic shows the full key only once. If you lose it, you have to revoke it and generate a new one.
- Store it in an environment variable, never in source code:
export ANTHROPIC_API_KEY="sk-ant-..."
- Test it with a simple request:
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-3-5-sonnet-latest",
"max_tokens": 100,
"messages": [{"role": "user", "content": "Say hello"}]
}'
This gives you full access to Anthropic's models, rate limits tied to your usage tier, and billing based on tokens consumed — separate from any Claude.ai subscription you might also be paying for.
Option 2: Generate a key from an existing Claude subscription
A common situation: you (or your team) already pay for Claude through claude.ai and don't want a second, separate usage-based bill just to experiment with the API or wire Claude into an internal tool. SubToAPI turns that existing access into a standard API key without a separate pay-per-token account.
- Sign up at /signup and connect the Claude access you already have.
- Generate a key from the dashboard. Keys are prefixed
sub_live_...so they're easy to identify in logs and secret managers. - Pick a plan — Solo at €9 for individual use, Team at €19/seat if multiple people need their own keys under one account, or Scale at €49/seat for larger usage and team controls. There's a free trial at signup so you can test before committing.
- Call the API the same way you'd call any Messages-style endpoint:
const res = 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-3-5-sonnet-latest",
max_tokens: 200,
messages: [{ role: "user", content: "Summarize this ticket: ..." }]
})
});
const data = await res.json();
console.log(data);
This path is faster if your goal is "I already pay for Claude, I just want a real API key to plug into my app," rather than setting up a second billing relationship. It also includes streaming, tool use, usage metadata per key, and seat-based keys for teams — see /docs for the full reference, /docs/quickstart to get your first request working, /docs/messages for the request format, /docs/streaming for SSE responses, and /docs/tools for function-calling.
Managing keys once you have them
Regardless of which path you took, treat API keys like passwords:
- One key per environment. Separate keys for local dev, staging, and production so you can revoke one without breaking the others.
- Rotate on a schedule or on suspicion. If a key leaks in a commit, a log file, or a screen share, revoke it immediately and issue a new one.
- Name keys descriptively.
mobile-app-prodbeatskey-3when you're debugging usage spikes six months from now. - Scope keys per teammate when possible. If your plan supports seats (SubToAPI's Team and Scale plans do), give each person or service their own key rather than sharing one — it makes usage tracking and revocation far easier.
- Never hardcode keys. Use environment variables, a secrets manager, or your platform's config store. Check
.gitignorebefore your first commit touches a.envfile.
Checklist before going to production
- Key stored as an environment variable, not in code
- Separate keys for dev/staging/prod
- Billing or plan confirmed (pay-as-you-go for direct Anthropic access, or a seat plan if using SubToAPI)
- A revocation plan if a key leaks
- Usage/metadata monitoring in place so you notice anomalies early
questions
Do I need a credit card to generate a Claude API key? If you're going through Anthropic's Console directly, yes — API usage is billed by tokens, so a payment method is required before a key becomes active. If you're generating a key through SubToAPI from an existing Claude subscription, you're on a flat per-seat plan instead, starting at €9/month on Solo, with a free trial at /signup.
Can I use my Claude.ai (Pro/Team) subscription to call the API directly? Not out of the box — Anthropic's chat subscription and its pay-as-you-go API are separate products with separate billing. A service like SubToAPI bridges that gap by generating an API key from your existing subscription access.
How many API keys should I create? At minimum, one per environment (dev, staging, production) and one per teammate or service that needs independent access. This limits the blast radius if a key is ever leaked and makes usage tracking per key or per seat much easier to audit.