To call Claude from code, you need an API key. The API is completely separate from claude.ai subscriptions (like Pro) — it's pay-as-you-go, billed per token. This guide covers where and how to get a key, what it costs, and how to keep your key safe. (For the actual first call, see the API getting-started guide.)
Subscription vs API
This trips people up most. Claude Pro ($20/mo) does not include API usage. The API isn't a monthly subscription — it's pay-as-you-go, billed by the input tokens you send and output tokens you receive. Call nothing and you owe nothing.
How to get an API key
- Sign up / log in at platform.claude.com (the developer console). New accounts usually get a small amount of free credit, though the amount and terms can change.
- Add a payment method and top up credits. New accounts start on prepaid credits with optional auto-reload; higher-usage accounts can switch to monthly invoicing.
- Create a key under API Keys. The key value is often shown only once, so store it somewhere safe immediately.
Pricing by model
Pricing bills input tokens (your prompt/context) and output tokens (Claude's reply) separately, and output is ~5x input across all current models. The three recommended models as of May 2026 are in the table above.
- Haiku 4.5 ($1/$5): cheapest; great for classification, extraction, summarization, high-volume work.
- Sonnet 4.6 ($3/$15): best price-to-quality balance for general tasks.
- Opus 4.7-4.8 ($5/$25): most capable; for complex coding, reasoning, and agents (Opus 4.8 is the latest).
Cutting costs
- Prompt caching: cache long, repeated prefixes for up to 90% off cached input.
- Batch API: process non-urgent work in bulk for a flat 50% discount.
- Use the right model. Sending simple tasks to Opus is a common source of overspend. Combining caching and batch helps a lot.
Rate limits
The API has per-minute request and token limits that increase by tier based on your payment and usage history. Check the limits page in the console for exact numbers. Exceeding a limit returns a 429 error.
Key security — don't skip this
- Keep keys in environment variables, e.g.
export ANTHROPIC_API_KEY="sk-ant-..." - Never commit keys to code or Git. A public repo can get a key stolen instantly.
- Rotate keys periodically; if you suspect exposure, revoke and reissue in the console immediately.
- Never put keys in front-end (browser) code — call only from your server.
Next steps
Once you have a key, see the API getting-started guide for the first request/response. For billing or key issues, use the platform.claude.com console and official docs.