How to use the Claude API: Console, API key, first call, and best practices
A step-by-step guide to the Claude Developer Platform: create a Claude Console account, test in the playground, create and store an API key, make your first call with curl and Python, choose a model, and handle cost, data, and security.
AI$ curl https://api.anthropic.com/v1/messages▍Chatting with Claude in the browser is one thing. Putting it inside your own system, to summarize tickets or classify emails, is another: for that you need the API. This guide goes from zero to the first answer in your terminal and covers what to take care of before production. For the full map of products, see the overview of Anthropic’s AI.
What the Claude Developer Platform is
It is Anthropic’s “for builders” side, with three parts:
- Claude Console, at platform.claude.com: where you create the account, test prompts, create keys, and track spend. The old console.anthropic.com redirects there.
- Claude API: the service your code calls. It is a regular REST API: JSON over HTTPS.
- Documentation, at platform.claude.com/docs, with the reference, guides, and a cookbook. The old addresses redirect too.
Anthropic renamed several things between 2025 and 2026 (the “Anthropic API” became the “Claude API,” for example). If an older tutorial doesn’t match what you see, check the official docs.
Step by step: from account to API key
1. Create a Console account
Go to platform.claude.com and create an account. It is separate from Claude app subscriptions: with the API you pay for usage, measured in tokens (chunks of text). Set up billing when the Console asks for it.
2. Test in the playground and use “Get code”
Before writing code, use the Console playground: write the system prompt (general rules) and the user message, pick a model, and click Run. When the answer looks right, “Get code” shows the same call ready to use in cURL and other languages.
Animated illustration (not a real screenshot): in the Console playground, a system prompt and a user message, picking a model, Run and the answer; then “Get code” with cURL (x-api-key and anthropic-version), API keys › Create key, and the key copied once into an environment variable. The real interface may use different names and positions.
3. Create the key at Settings › API keys
Under Settings › API keys, create a key with a name that says where it will be used, such as support-staging. Copy it right away: the full key is shown only once. Lost it? Create a new one and revoke the old one.
4. Separate projects with workspaces
Workspaces split your organization: each one has its own keys and its own spend and rate limits. Use one per environment or team, so a runaway test doesn’t eat the production budget. If you use Claude Code with a Console account, you’ll see a “Claude Code” workspace created automatically.
| Where in the Console | What it’s for |
|---|---|
| Playground | Testing prompts and models without code |
Settings › API keys (/settings/keys) |
Creating and revoking keys |
| Workspaces | Separating keys and limits by team or environment |
/cost |
Tracking spend |
/usage/limits |
Checking rate limits |
Keep the key out of your code
The key is a password: whoever has it spends on your behalf. Never put it in code or in Git. On your machine, use an environment variable; on servers and pipelines, a secrets manager. The reasoning is in environment variables and the 12-factor app.
# Read the key without echoing it or saving it to shell history
read -rs ANTHROPIC_API_KEY && export ANTHROPIC_API_KEY
# If you use a .env file, it never goes into Git
echo ".env" >> .gitignore
First call with curl
This is the official call to the Messages endpoint. Replace <model> with the model id (where to find it is explained below):
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": "<model>", "max_tokens": 1000, "messages": [{"role": "user", "content": "Explain in 3 sentences what a REST API is."}]}'
The anthropic-version header pins the API version, so the response format doesn’t change on you. max_tokens caps the length of the answer and, with it, the cost per call. messages is the conversation, with a role (user or assistant) and content. The response is JSON with a content list of blocks, the reason it stopped (stop_reason), and token usage (usage).
Reading just the text with jq
In a simple response, the first block is the text. Pipe it to jq (curl’s -s option hides the progress meter, if it shows up):
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": "<model>", "max_tokens": 1000, "messages": [{"role": "user", "content": "Explain in 3 sentences what a REST API is."}]}' \
| jq -r '.content[0].text'
In Python, with the official SDK
There are official SDKs for Python, TypeScript, C#, Go, Java, PHP, and Ruby. In Python, set the model through an environment variable too, so you can switch without touching the code:
pip install anthropic
export CLAUDE_MODEL="<model id>"
import os
import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY from the environment
message = client.messages.create(
model=os.environ["CLAUDE_MODEL"],
max_tokens=1000,
messages=[{"role": "user", "content": "List 3 precautions for storing an API key."}],
)
for block in message.content:
if block.type == "text":
print(block.text)
The loop prints only the text blocks; the response may include other types, such as tool calls.
Alternative: the ant CLI
ant is the official CLI for the API. For local development, the docs recommend authenticating through it instead of handling keys in the terminal:
brew install anthropics/tap/ant
ant auth login
After that, commands such as ant messages create call the API straight from the terminal; the options are in the docs.
How to choose a model
Claude models come in families: Fable (the most capable), Opus (the docs’ recommended default), Sonnet (a balance of speed and intelligence), and Haiku (the fastest). There is also Mythos, with availability limited to verified organizations.
Start with the recommended default, test with real cases, and try a faster model for simple tasks such as classifying text. Model ids change with every release: copy the current one from the “Models overview” page in the docs, or list them through the API (GET /v1/models), and store it in CLAUDE_MODEL.
API features at a glance
| Feature | What it’s for |
|---|---|
| System prompts | Rules for role, tone, and format, kept separate from the user message |
| Tool use | The model asks to call your functions |
| Prompt caching | Reuses a repeated prompt prefix (5 minutes by default, 1-hour option) |
| Batches | Asynchronous batch processing, at a discount |
| Files API | Upload a file once and use its file_id afterward |
| Citations | Points to the part of the document used in the answer |
| Structured outputs | Responses that follow a JSON Schema |
| Web search and code execution | Server-side tools to search the web and run code |
| MCP connector | Calls remote MCP servers directly from the API |
| Agent Skills | Your own skills, plus pre-built ones for PowerPoint, Excel, Word, and PDF |
| Managed Agents (beta) | Agents hosted by Anthropic, with a sandbox and tools |
| Agent SDK | Claude Code as a library, in Python and TypeScript |
The Agent SDK is the former Claude Code SDK. Managed Agents are in beta; be careful in production.
Claude via Amazon Bedrock, Google Cloud, and Microsoft Foundry
If your company already runs everything on one cloud, you can use Claude through it: Amazon Bedrock (the docs also mention “Claude Platform on AWS”), Google Cloud (in the offering formerly called Vertex AI), and Microsoft Foundry, formerly Azure AI Foundry. You reuse the identity, network, and billing you already have, but authentication, model ids, and available features may differ from the direct API; check the provider’s docs.
Cost and limits without surprises
Prices change and depend on the model; check the official page. The habits that help most:
- A realistic
max_tokensfor the answer length you expect. - Prompt caching when the same long context repeats.
- Batches for anything that doesn’t need an immediate answer.
- A spend limit per workspace.
- Rate limits: check yours in the Console and on the docs’ rate limits page; on a 429 error, retry with increasing waits (backoff).
Your data: training, retention, and privacy laws
According to the official policy, data sent through the API is not used to train models by default (exceptions: explicit feedback and opt-in programs). On the app’s consumer plans, users choose. Retention periods are listed in Anthropic’s privacy center (privacy.claude.com); check the one for the API, and for features that store files, before sending anything sensitive.
Privacy laws such as Brazil’s LGPD or the GDPR still apply: personal data needs a legal basis, minimization, and records. Never paste secrets, customer data, or production credentials into prompts. This guide is not legal advice; involve your company’s legal team and data protection officer.
Security: think OWASP for LLMs
LLM applications have their own risks, such as prompt injection (text that tries to change the instructions) and agents with too much permission. The OWASP for LLMs security guide covers each one. The basics: validate the model’s output before executing or storing it, give tools the least permission they need, and revoke any exposed key immediately.
Checklist
- I created a Claude Console account and tested my prompt in the playground
- I have one key per application and environment, in a workspace with a spend limit
- The key lives in an environment variable or secrets manager, never in Git
- My first call worked, with the model coming from
CLAUDE_MODEL - I set
max_tokens, handle 429 errors, and considered caching and batches - I reviewed data retention, privacy laws, and the OWASP risks for LLMs
The first call takes five minutes. What separates a test from a product is everything else: a well-kept key, per-workspace limits, minimal data, and output that is always validated.