In this lesson: Describe the request/response shape of a model API and why it is stateless.
A chat window hides four things that become your responsibility the moment you call the model from code. Understanding them up front prevents most beginner architecture mistakes.
1. The API is stateless
There is no conversation on the server. Every request carries the entire history, and the model sees only what you send this second. The chat interface you have used maintains that history for you; in your program, you own it — storing it, trimming it, and paying for it on every turn.
2. You choose the model, per request
Model choice is a parameter, not a setting. A classification job that runs a million times a day and a hard reasoning task can and should use different models. Current Anthropic models look like this:
| Model | Model ID | Use it for |
|---|---|---|
| Claude Opus 5 | claude-opus-5 | Hard reasoning, agents, code. The default. |
| Claude Sonnet 5 | claude-sonnet-5 | Balanced work at lower cost |
| Claude Haiku 4.5 | claude-haiku-4-5 | High-volume, latency-sensitive, simple tasks |
Model IDs are exact strings. Do not append a date suffix, and do not guess an ID from a marketing name — a wrong ID is a 404, and a plausible-looking wrong ID is worse because it looks correct in review.
3. Output is a list of blocks, not a string
This is the shape mistake that catches everyone once. A response contains a list of typed content blocks — text, thinking, tool calls — and reaching straight for the first one breaks as soon as the model thinks or calls a tool. Always filter by type.
4. Everything can fail
Networks time out, you get rate limited, the model refuses, the answer hits the length ceiling. In a browser you press retry; in a program you write the retry, the backoff and the fallback. Budget for this — it is a real part of the work, not an afterthought.
What you need before the next lesson
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install anthropic
You will also need an API key from the provider's console, kept in an environment variable — never in your source code, and never in a file you commit.
export ANTHROPIC_API_KEY="sk-ant-..." # Windows PowerShell:
# $env:ANTHROPIC_API_KEY="sk-ant-..."
Try it yourself
Before writing any code, sketch on paper the four inputs and three outputs above for an application you would like to build. If you cannot say what the instructions are and what the output must look like, you are not ready to write the call yet — and that is the most common reason early AI projects wander.