Getting started with the Claude API: from API key to first call to pricing
- The Claude API runs on a Claude Console (platform.claude.com) account and an API key. Claude Pro/Max/Ultra subscriptions don’t include API usage, which is billed separately.
- You create keys in the Console under Settings > API keys. They start with
sk-ant-, and the full key is shown only once, when you create it. - If you put the key in the
ANTHROPIC_API_KEYenvironment variable, the SDK reads it automatically. Never write the key directly in your code. - The model IDs are
claude-opus-5-5,claude-sonnet-5-5,claude-haiku-5-5, andclaude-fable-5-2(Fable 5.1,claude-fable-5-1, is the previous version). - Prices per 1M tokens (input/output) are $4/$20 for Opus 5.5 and $2/$10 for Sonnet 5.5 (as of 2026-11-16).
- If you only swap the model ID in an example, each model blocks different parameters. Opus 5.5 can’t turn thinking off, and Haiku 5.5 returns a 400 error for
budget_tokensand sampling parameters. See the quick reference tables for details.
What you’ll be able to do after this tutorial
Section titled “What you’ll be able to do after this tutorial”- Create an API key in the Console and store it safely.
- Call the Messages API directly with curl and read the response structure.
- Make the same call with the Python SDK, and try changing the system prompt and the model.
- Understand per-model pricing and ways to save (the Batch API and prompt caching), and choose a model.
Concepts to know first
Section titled “Concepts to know first”| Term | Meaning |
|---|---|
| Claude Console | The developer console for managing API keys and billing (platform.claude.com). It’s separate from a claude.ai subscription. |
| API key | A secret string that authenticates your calls. It starts with sk-ant-. |
| Messages API | The core API where you send a conversation and get a reply via POST https://api.anthropic.com/v1/messages. |
| Token | The unit used to calculate price. The response’s usage shows the input and output token counts. |
| SDK | The official client library. It reads the key from an environment variable automatically. |
The Console Playground
Section titled “The Console Playground”The screen formerly called Workbench was renamed Playground on 2026-08-18 (platform.claude.com/playground). It supports every Messages API parameter and shows the full SDK request and the API response for each run, so it’s a good place to try out requests before writing code. If you see “Workbench” in older posts, it’s the same screen.
Types of API keys
Section titled “Types of API keys”| Type | Description |
|---|---|
| Personal key | Tied to your account. It becomes invalid if you leave the organization. |
| Service account key | For CI, production, and agents. Recommended for shared use. |
| Workspace key | Legacy. |
Step by step
Section titled “Step by step”-
Create an API key in the Console
Sign up or log in at platform.claude.com. Under Settings > API keys (https://platform.claude.com/settings/keys), click Create key. Set a name, an expiration, the account to link it to (Linked account: yourself or a service account), and a workspace if needed.
Screen guide: Clicking Create key under Settings > API keys in the ConsoleSee this screen in the official help ↗
How to create an API key - platform.claude.com (Console)Sign up or log in
- Settings > API keysClick Create key
- Key creation formSet the name, expiration, and Linked account→ The sk-ant- key is shown only once. Save it right away
This is a simplified flow. See the official help page for the actual screens.
-
Put the key in an environment variable
Don’t write the key directly in your code or repository. Pass it through an environment variable. The SDK reads
ANTHROPIC_API_KEYautomatically.Terminal window export ANTHROPIC_API_KEY="your-api-key-here" -
Make your first call with curl
This is the example from the official quickstart. When you call over HTTP directly, you need the
x-api-keyheader and theanthropic-versionheader. The official quickstart now usesanthropic-version: 2026-10-21(as of 2026-11-16).Terminal window curl https://api.anthropic.com/v1/messages \-H "content-type: application/json" \-H "x-api-key: $ANTHROPIC_API_KEY" \-H "anthropic-version: 2026-10-21" \-d '{"model": "claude-opus-5-5","max_tokens": 1000,"messages": [{"role": "user","content": "What should I search for to find the latest developments in renewable energy?"}]}'The response is JSON. The answer is in the block of the
contentarray whosetypeistext, the reason it stopped is instop_reason, and the token counts are inusage(input_tokens,output_tokens).Screen guide: curl response JSON (content, stop_reason, usage)See this screen in the official help ↗
-
Make your first call with Python
Create a virtual environment and install the SDK.
Terminal window mkdir claude-quickstart && cd claude-quickstartpython3 -m venv .venv && source .venv/bin/activatepip install anthropicCreate a file named
quickstart.py. The key isn’t in the code; the SDK reads it from the environment variable.import anthropicclient = anthropic.Anthropic()message = client.messages.create(model="claude-opus-5-5",max_tokens=1000,messages=[{"role": "user","content": "What should I search for to find the latest developments in renewable energy?",}],)for block in message.content:if block.type == "text":print(block.text)Terminal window python quickstart.py -
Try a system prompt and a different model
You pass the system prompt in the top-level
systemfield. If you want to cut costs, try changingmodeltoclaude-sonnet-5-5orclaude-haiku-5-5. Below is a modified version of the example above.message = client.messages.create(model="claude-sonnet-5-5",max_tokens=1000,system="You are a helpful assistant. Keep your answers brief.",messages=[{"role": "user", "content": "What should I search for to find the latest developments in renewable energy?"}],)Copy and paste this promptAdd a system prompt to the quickstart.py above so that answers are always three lines or fewer. Don’t put the key in the code; read it from the environment variable.
Quick reference
Section titled “Quick reference”Model IDs and prices (per 1M tokens, input/output, as of 2026-11-16)
Section titled “Model IDs and prices (per 1M tokens, input/output, as of 2026-11-16)”Prices are in US dollars. For details, check the official pricing page.
| Model | Model ID | Input / Output |
|---|---|---|
| Fable 5.2 | claude-fable-5-2 |
$8 / $40 |
| Fable 5.1 (previous) | claude-fable-5-1 |
$10 / $50 |
| Opus 5.5 | claude-opus-5-5 |
$4 / $20 |
| Sonnet 5.5 | claude-sonnet-5-5 |
$2 / $10 |
| Haiku 5.5 | claude-haiku-5-5 |
from $0.10 / from $0.50 |
- The Batch API is a 50% discount.
- Prompt cache reads cost 10% of the base input price. The exceptions are Fable 5.2 and Fable 5.1 at 2.5%, and Opus 5.5 and Sonnet 5.5 at 5%.
- For how to choose a model, see C1; for how to cut costs by splitting work across models, see C15.
Required parts of a request (direct HTTP calls)
Section titled “Required parts of a request (direct HTTP calls)”| Item | Value |
|---|---|
| URL | POST https://api.anthropic.com/v1/messages |
| Headers | content-type: application/json, x-api-key: $ANTHROPIC_API_KEY, anthropic-version: 2026-10-21 (per the official quickstart as of 2026-11-16; the older 2023-06-01 still works and gives the old behavior. See below for the new API version. As of 2026-10-26, the migration docs say the API accepts the key through both the X-Api-Key and Authorization: Bearer <key> headers) |
| Body | model, max_tokens, messages (the system prompt goes in system) |
Per-model request restrictions (watch for 400 errors, as of 2026-11-02)
Section titled “Per-model request restrictions (watch for 400 errors, as of 2026-11-02)”If you only change model in an example, you can hit a 400 error for the reasons below. This follows the official release notes.
| Model | Restriction |
|---|---|
| Opus 5.5 | Sampling parameters (temperature, top_p, top_k) and assistant message prefill also return a 400 error. You can’t turn thinking off. thinking: {"type": "disabled"} and {"type": "enabled", ...} return a 400 error. Leave out the thinking field and control depth with effort. tool_choice of any or tool also returns a 400 error, so use auto and strict tool use. |
| Sonnet 5.5 | Five settings return a 400 error: thinking budgets (budget_tokens), sampling parameters (temperature, top_p, top_k), assistant message prefill, tool_choice of any or tool (use auto and strict tool use), and thinking: {"type": "disabled"} (to turn off up-front thinking, use thinking: {"type": "between_tools"}). |
| Fable 5.2, Fable 5.1, Mythos 5.2, Mythos 5.1 (5.2 confirmed 2026-11-16) | tool_choice of any or tool is not supported and returns a 400 error (auto and none still work). If you need tool input that matches a schema, use strict tool use. |
| Haiku 5.5 | Code written the Haiku 4.5 way may break. budget_tokens (manual extended thinking), temperature, top_p, top_k, and assistant message prefill can each cause a 400 error. Adaptive thinking is the default, so the response may start with a thinking block, and that text is omitted unless you set thinking.display to "summarized". |
- New API version 2026-10-21 (released 2026-10-21, as of 2026-10-26): The new major SDK versions (Python
anthropic2.0.0, TypeScript@anthropic-ai/sdk1.0.0, C# 13.0.0, Go 2.0.0, Java 3.0.0, PHP, Ruby, and others) and theantCLI 2.0.0 sendanthropic-version: 2026-10-21by default. If you call without an SDK, you need to change this header value to2026-10-21to get the new behavior; if you keep sending the old2023-06-01, you get the old behavior. In the new version, sendingtemperature,top_p, ortop_kreturns a 400 error even at default values.citationson user messages anddocumentblocks inside assistant messages also return a 400 error. The new SDKs send the API key asAuthorization: Bearer. Before upgrading, follow the checklist in the official migration docs. - Data retention: Like Fable 5, Fable 5.1, Fable 5.2, Mythos 5.1 and Mythos 5.2 require 30-day data retention, and can’t be used by ZDR (zero data retention) organizations unless Anthropic explicitly allows it. If you have a ZDR agreement, check before switching to Fable.
- You can look up which models accept turning thinking off or server tools through the Models API
capabilities(thinking.types.disabled,server_tools).
Installing the official SDKs
Section titled “Installing the official SDKs”| Language | Install |
|---|---|
| Python | pip install anthropic (Python 3.10 or later from v1.0) |
| TypeScript | npm install @anthropic-ai/sdk |
| C# | dotnet add package Anthropic |
| Go | go get github.com/anthropics/anthropic-sdk-go/v2 (from 2.0.0, the module path ends in /v2) |
| PHP | composer require anthropic-ai/sdk |
| Ruby | bundle add anthropic |
| Java | See the Gradle/Maven instructions in the official quickstart |
| CLI | brew install anthropics/tap/ant, then ant auth login |
Common sticking points
Section titled “Common sticking points”I lost my key
Section titled “I lost my key”- Cause: The full key is shown only once, when it’s created.
- Fix: Create a new key in the Console and delete the old one.
I subscribe to Claude Pro/Max/Ultra but the API doesn’t work
Section titled “I subscribe to Claude Pro/Max/Ultra but the API doesn’t work”- Cause: Subscriptions don’t include Console API usage, which is billed separately.
- Fix: Set up billing for the API separately in the Console. Follow the on-screen instructions for the steps.
I get an error when calling over HTTP directly
Section titled “I get an error when calling over HTTP directly”- Cause: A required header may be missing.
- Fix: Check the
x-api-keyandanthropic-version: 2026-10-21headers and themax_tokensvalue.
I switched to Opus 5.5 or Haiku 5.5 and got a 400 error
Section titled “I switched to Opus 5.5 or Haiku 5.5 and got a 400 error”- Cause: Opus 5.5 doesn’t allow turning off or fixing thinking,
tool_choiceofany/tool, sampling parameters, or prefill, and Haiku 5.5 doesn’t allowbudget_tokens, sampling parameters, or prefill. - Fix: Look at “Per-model request restrictions” in the quick reference and remove the parameter in question. The parameter name in the error message is your clue.
After upgrading the Python SDK, temperature gives an error (SDK 1.0)
Section titled “After upgrading the Python SDK, temperature gives an error (SDK 1.0)”- Cause: In the 2026-10-21 API version and the new major SDK versions (Python 2.0.0 and so on),
temperature,top_p, andtop_kare gone entirely. Before that, Python SDK v1.0 (2026-08-20) required Python 3.10 or later and removed things that had been deprecated long ago. Examples are the Text Completions API and thetemperature,top_p, andtop_kparameters on Messages methods. The HTTP layer also changed fromhttpxtohttpx2. - Fix: Remove those parameters or follow the before-and-after code in the official migration guide. The
pip install anthropicin the examples works as is.
My personal key suddenly stopped working
Section titled “My personal key suddenly stopped working”- Cause: Personal keys become invalid when you leave the organization.
- Fix: Use a service account key for CI and production.
The response gets cut off partway
Section titled “The response gets cut off partway”- Cause:
max_tokensmay be too small. Check the response’sstop_reason. - Fix: Increase
max_tokens.
Practical tips
Section titled “Practical tips”- If cost worries you, start with a smaller model. The examples use
claude-opus-5-5as in the official quickstart, but you can switch toclaude-sonnet-5-5orclaude-haiku-5-5. The official guide says adjusting effort is also a good lever. - Keep
max_tokenssmall. For calls where a short answer is fine, lowering the output cap prevents unintended long outputs. - Log
usage. Recording input and output token counts per call makes it easy to estimate cost. - Use the Batch API when you don’t need real time. It’s a 50% discount.
- Use service account keys for shared use. Don’t use personal keys for team services.
- Review your keys regularly. Set expiration dates and delete keys you don’t use.
- Beta headers are no longer needed. The Files API (
/v1/files) and Agent Skills (/v1/skills) became generally available (GA) on the Claude API on 2026-08-19, so thefiles-api-2025-04-14andskills-2025-10-02beta headers are no longer needed. If you keep sending them it still works, but the Files API goes back to the earlier response format. - If you’re on Max, Ultra, or Team, check your API credits. Your plan includes monthly API credits. See C2 for how to claim them.
Next steps: going deeper
Section titled “Next steps: going deeper”These features go beyond the beginner scope. Just learn the names and consult the official docs when you need them.
- Claude Managed Agents: A service that runs agents in the cloud. With dynamic workflows (beta, 2026-10-09), an agent can directly use workflows that run multiple agents step by step.
- Computer and browser toolsets:
computer_toolset_20260801left beta on 2026-08-19, and the browser toolset (browser_toolset_20260801) was released the same day. The Python and TypeScript SDKs have classes in beta that inherit from them. - Compaction: A Messages API feature that compresses long conversations into a summary block (2026-09-14, beta,
compact-2026-09-04header). - Models API
capabilities: Look up what a model accepts so your code can avoid the 400 errors above in advance.
What to read next
Section titled “What to read next”- C1. Claude at a glance — comparing the 4 models and a selection guide
- C15. Model division strategy — splitting work across models to cut costs
- C14. Claude Code core features — writing API code with Claude Code
- C2. Plans and usage limits — how subscriptions differ from the API
- Build a work bot with tool use — building a bot that calls tools through the API
- Cut API costs with prompt caching, batching, and effort — caching and the Batch API in depth
- Run agents on a server with Managed Agents — running agents in the cloud
Sources
Last verified: Nov 16, 2026
- Claude pricing claude.com
- How do I pay for my Claude API usage? support.claude.com
- Rate limits platform.claude.com
- Get started with Claude (API) platform.claude.com
- Get your Claude API key platform.claude.com
- Models overview platform.claude.com
- What is the Pro plan? support.claude.com
- Prompting best practices platform.claude.com
- Claude Platform release notes platform.claude.com
- Model deprecations platform.claude.com
Prices, limits, and menu names change often. Before making an important decision, check the official pages above for the latest details.
Finished this tutorial?
Progress is saved only in this browser and never sent anywhere.