Your first Claude API call
Why this lesson
Section titled “Why this lesson”You have used Claude through a chat interface and watched it reason, refuse, write code, summarize a document, answer follow-up questions in context. The chat interface is one application of the model. Behind it is an HTTP endpoint, an API, that you can call from your own code. The moment you make that first call, the model becomes a component your application controls, not a product you visit.
The gap between chatting with Claude and building with Claude is smaller than most developers expect. It is one HTTP POST. The lesson is making that call confidently and understanding the shape of what comes back, because every later lesson in this track is a more interesting variation on the same primitive.
The simplest possible call
Section titled “The simplest possible call”There is one endpoint that matters, the Messages create endpoint at api.anthropic.com/v1/messages. You send a JSON request describing the model you want, how many tokens you will let it produce, and the conversation so far. You get a JSON response describing what the model said and why it stopped.
Here is the smallest meaningful request, with cURL:
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": "Hello, Claude."} ] }'Three things are worth naming. The header anthropic-version names the API version your request follows, written as a date. Each new version is how breaking changes ship, so a request on an older version keeps the behavior it was written for. The official SDKs set this header for you; with raw HTTP you send it yourself, and the table below shows the value the docs use. The header x-api-key carries your API key from the environment variable ANTHROPIC_API_KEY; the Claude Console at platform.claude.com/settings/keys is where you create one. The body has three fields: which model to call, how many tokens of output you will allow, and a list of messages representing the conversation.
Now the same call in Python, using the official SDK:
import anthropic
client = anthropic.Anthropic()
message = client.messages.create( model="claude-opus-5-5", max_tokens=1000, messages=[ {"role": "user", "content": "Hello, Claude."} ],)
for block in message.content: if block.type == "text": print(block.text)The Python client reads ANTHROPIC_API_KEY from the environment automatically; you do not pass it in code. (The SDKs can also pick up a sign-in from Anthropic's command-line tool, which the quickstart suggests for local development.) The loop at the end prints only the text blocks; the next section explains why you loop rather than grab the first item. Install the Python SDK from pip, or the TypeScript SDK from npm:
pip install anthropicnpm install @anthropic-ai/sdkThe TypeScript shape is parallel to Python: construct a new Anthropic client, then call anthropic.messages.create. Java, Go, C-sharp, PHP, and Ruby SDKs exist and follow the same shape; the lesson sticks to cURL and Python for concreteness.
The model ID in both examples is the one the Models overview suggests starting with for most workloads; the table below names it. Lesson 3 of this track is the proper model-selection lesson. For now it is enough to know that Anthropic's models come in tiers, from the most capable down to the fastest and cheapest, and that capability rises with cost and latency. Starting where the docs point is fine here, because the call you are making is small and the cost is rounding error. Once you have a way to measure quality, evaluation can move you down a tier.
| As of November 2026 | Value used in this lesson | Notes |
|---|---|---|
| Model ID in the samples | claude-opus-5-5 (Claude Opus 5.5) | The Models overview: "If you're unsure which model to use, start with Claude Opus 5.5 for most workloads." |
| Other current model IDs | claude-fable-5-2, claude-sonnet-5-5, claude-haiku-5-5 | Above-flagship, balanced, and fastest-and-cheapest tiers. Lesson 3 compares them. |
anthropic-version header | 2026-10-21 | The latest version; Anthropic recommends using the latest whenever possible. The earlier version, 2023-06-01, is still listed. |
| Sampling parameters | temperature, top_p, top_k are removed | Starting with 2026-10-21, a Messages request that sends any of them returns a 400 error. Steer the model with the prompt instead. |
max_tokens in the samples | 1000, as in the quickstart (1024 in later samples) | Thinking and the reply both count toward this cap; leave headroom. |
| Sources | Models overview, API versions, Get started, Steering thinking |
What comes back
Section titled “What comes back”The response is a JSON object with a predictable shape. Here is what the public quickstart's example call returns (the prompt there is longer than the Hello, Claude call above, but the response shape is the same regardless of prompt):
{ "model": "claude-opus-5-5", "id": "msg_013mHbppMPd2PrVJzGMZPt2D", "type": "message", "role": "assistant", "content": [ { "type": "text", "text": "Here are some effective search strategies to find the latest developments in renewable energy:\n\n## General Search Terms\n- \"Renewable energy news 2025\"\n- ..." } ], "stop_reason": "end_turn", "stop_sequence": null, "stop_details": null, "usage": { "input_tokens": 21, "output_tokens": 305 }}Five fields carry meaning your application will rely on.
id is a unique identifier for this specific generation. Log it. When something goes wrong in production and you need to ask Anthropic Support what happened to one call, this is the handle.
content is an array of blocks, not a single string. For a plain text response you often get one block of type text. But on models that think before they answer, a thinking block can arrive ahead of the text, and the docs warn not to assume either way, because the model decides per request whether to think. Later in the track, when the model uses a tool, the same array holds tool blocks too. Code that reads response.content expecting a string will break the first time the model returns two blocks; the right pattern is to iterate the array and handle each block by its type. The Python SDK shows the same shape: message.content is a list of block objects, each with a type, not a flat string.
stop_reason tells you why the model stopped generating. The four values you will see most are end_turn (the model finished its thought naturally and yielded the turn back to you, the normal case), max_tokens (you set a limit and it hit it before finishing, so the response is truncated), stop_sequence (you supplied a custom stop string and it was generated), and tool_use (the model is requesting a tool call; lesson 4 picks this up). A fifth value, refusal, means the model declined the request; lesson 2 covers how to handle it. Application code should check this on every response. If you see max_tokens you got a truncated answer; rerun with a higher cap or break the request into smaller turns.
usage is input_tokens and output_tokens. This is the unit Anthropic bills on (different rates for input and output, different rates per model). Log it from day one. Lesson 12 covers production cost monitoring; the data you need begins here.
role on the response is always assistant. The model speaks as the assistant; you spoke as the user. That role distinction is what makes multi-turn possible.
Multi-turn is stateless
Section titled “Multi-turn is stateless”This is the conceptual jump that catches most developers new to LLM APIs. The Messages API does not remember your previous calls. It is stateless. Each call is independent of every other call. To have a conversation that the model can follow, you send the entire conversation history with every request.
Here is a three-message conversation:
message = client.messages.create( model="claude-opus-5-5", max_tokens=1024, messages=[ {"role": "user", "content": "Hello, Claude"}, {"role": "assistant", "content": "Hello!"}, {"role": "user", "content": "Can you describe LLMs to me?"}, ],)The messages list alternates user and assistant, ending with user. The model reads the whole list and generates the next assistant turn. The first two entries do not have to be a real prior call: you can synthesize an assistant message to seed context the model will then continue from. The API does not check, and does not care.
This pattern has a practical consequence. Your application is the one that has to maintain conversation state. Some applications keep state in memory and rebuild the list per call. Some serialize it to a database between turns. Some compress old turns into summaries to fit longer conversations into the context window. Whatever you choose, by default the API itself holds nothing for you between calls. That is a feature, not a limitation: it makes the API simple, debuggable, and trivially horizontal-scaled (any worker can handle any request).
The second consequence is cost. Every turn pays for the full prior history as input tokens. A long conversation gets expensive on input even if the latest turn is short. Lesson 7 of this track covers prompt caching, which directly addresses this; for now, know that the cost shape is "you pay for the whole history on every turn."
The system parameter
Section titled “The system parameter”Instructions to the model (a persona, a constraint, a format requirement) belong in the system parameter, separate from the messages list. The messages list is the conversation; the system parameter is the standing instruction the model carries into every turn.
message = client.messages.create( model="claude-opus-5-5", max_tokens=1024, system="You are a terse code reviewer. Return only the changes you would make, in unified diff format. No prose.", messages=[ {"role": "user", "content": "<diff omitted for the lesson>"}, ],)The system text is not a message. It does not get a role. It is not part of the alternating user-assistant sequence. It is a separate channel that tells the model how to behave for the whole call. Conceptually it sits above the conversation, not in it.
Common confusion: developers used to other LLM APIs sometimes put the system instruction as the first message with role system or push the instruction into the first user message. With Claude, the dedicated system parameter exists for exactly this and is the right home for instructions. Later lessons build on it; for example, lesson 7 shows how a long, stable system prompt becomes the part of the request you cache.
Common pitfalls
Section titled “Common pitfalls”A handful of failures will happen on the way to your first working call. Name them so you recognize them.
The API key is not set. The client reads ANTHROPIC_API_KEY from the environment; if it is not there (and you have not signed in with the command-line tool), the call fails immediately with an authentication error. Set the variable for the shell session with an export statement, or persist it in your shell profile (.zshrc, .bashrc, .config/fish/config.fish):
export ANTHROPIC_API_KEY='your-key-here'In production, treat the key like any other secret: do not commit it, do not log it, rotate it on suspected exposure. The Console has a button to revoke a leaked key and issue a new one.
The model name is wrong. Anthropic publishes a precise model ID for every model, and a casual product name does not work in its place. The table above lists the IDs on the date in its heading; the Models overview at platform.claude.com/docs/en/models/overview is canonical, so copy the ID from there. Lesson 3 covers selection and version conventions.
max_tokens is too small. max_tokens is the hard ceiling on the model's output for one call. Too small and you get a truncated response with stop_reason equal to max_tokens. Too generous costs more only when the model uses more (you pay for actual output, not the cap). On models that think before they answer, the thinking counts against the same ceiling as the reply, so a cap sized for the answer alone can run out. Leave headroom, and raise the cap for long-form output.
Reading content as a string. The content field is an array of blocks. Code that grabs the first block and reads its text works only while that first block happens to be text; it breaks the first time a thinking block or a tool block comes first. Iterate the array.
Treating the API as stateful. Sending only the latest user message and expecting the model to remember the earlier conversation is the most common mistake. The model can only see what you send in this call. If your code rebuilds the messages list each turn and forgets to include the prior turns, you get a fresh model with no memory of the conversation it just had.
What you do not need yet
Section titled “What you do not need yet”This lesson stays on the smallest possible primitive. Several things you will hear about are deliberately not in this lesson; the track gets to each one in turn.
- Streaming. Receiving the response token-by-token as the model generates it (rather than waiting for the whole response). Lesson 2.
- Tools. Letting the model call functions you define (read a file, query a database, hit a third-party API). Lessons 4 and 5.
- Model Context Protocol. A protocol that lets one tool definition work across many model providers. Lesson 6.
- Prompt caching. A discount on tokens you reuse across calls (long system prompts, stable context blocks). Lesson 7.
- Agents and the agent loop. Letting the model decide its own next step in a loop, not just respond to one turn. Lesson 8 onward.
Knowing the names and that the track reaches them lets you suppress the impulse to learn everything at once. Get the simplest call working first.
Where this fits
Section titled “Where this fits”Lesson 1 is the smallest unit. Lesson 2 is "the Messages API in production" (streaming, error handling, retries, batches). Lesson 3 is the model-selection conversation (the model tiers, the effort parameter, and the thinking modes). Together they are the foundations phase, what you need before any later lesson is worth reading. Phase 2 picks up the augmentation patterns (tools, MCP, caching, context management) that extend what one call can do. Phase 3 is the agent patterns. Phase 4 is what it takes to ship.
What you should remember
Section titled “What you should remember”- One endpoint, the Messages create endpoint at api.anthropic.com/v1/messages, with one canonical request shape: model, max-tokens, messages. Optional system for standing instructions.
- The response is structured. id for logging, content as an array of blocks (iterate, do not index), stop_reason as control flow (check on every response), usage for cost.
- The Messages API is stateless. To have a conversation, your code sends the full message history on every call. The API remembers nothing between calls.
- The system parameter is where instructions live, separate from the messages list. Use it for persona, format, constraint; not as the first message.
- Use the precise model ID the docs publish, not a casual name; the table lists today's IDs. Start with the model the docs point to, then let evaluation move you down a tier.
You now have the smallest end-to-end pattern. Every other lesson in Track 22 is a more interesting variation on the same primitive.