Home / The Claude API for builders
The request, a single point of entry
Every interaction with Claude goes through a single HTTP entry point, the POST /v1/messages request, which receives an array of turns and always returns the same response structure.
The Claude API has only one point of entry: the POST /v1/messages request, called the Messages API. Every exchange, whether it fits in a single turn or strings together a long conversation, goes through this same entry point, with a body that carries a messages array and a chosen model. An ordinary HTTP client is enough: there is no other route to memorise, whatever model is called or whatever the request is about.
A required field, with no default value
The request body carries a field named exactly max_tokens, which sets the maximum number of tokens the model can generate before stopping. This field has no default value: it is required on every request, on the same footing as the model and the messages array. This field also drives the cost and duration of the generation, without forcing it: the model can very well stop before reaching this limit, as soon as it judges its response complete. One special case exists: sending max_tokens as 0 requests no generation at all, only pre-filling the prompt cache ahead of a following request.
// Minimal body of a request to the Messages API
{
"model": "claude-sonnet-5",
"max_tokens": 300,
"messages": [
{ "role": "user", "content": "Résume ce texte en une phrase." }
]
}
A response always structured the same way
The response returned by the API always follows the same shape, whatever model is called. The content field carries an array of blocks, the model field confirms the model actually used, and the stop_reason field indicates why generation stopped: end_turn for a response completed naturally, max_tokens for a cutoff at the set limit, stop_sequence for a stop sequence encountered, and depending on the request's context, tool_use, refusal, pause_turn or model_context_window_exceeded. When a stop sequence triggered the cutoff, it is repeated in the stop_sequence field.
The usage field closes out the response with four counters: input_tokens, output_tokens, cache_creation_input_tokens and cache_read_input_tokens. These four numbers are enough to calculate the exact cost of an exchange without consulting any other source, and they come back on every request, even the simplest one. Reading input_tokens before sending the next turn also shows how much headroom remains in the ongoing conversation.
This same response structure comes back in declaring a tool, where the stop_reason field takes the value tool_use to signal a usage request rather than a completed response.
The path of a request to the Messages API
A developer builds the body of a request to the Messages API with the model field and the messages field, then sends it to the API. The server returns a 400 error code before generation begins.
Write, in one sentence, what this situation establishes, and in one sentence what it does not establish.
What this establishes: This establishes that the max_tokens field is required in the body of a request to the Messages API, since a body that only carries model and messages is rejected before any generation.
What this does not establish: This does not establish which value of max_tokens suits this use case, since the developer has not yet supplied a value to test.
The three most common miscalibrations
- Too broad This situation proves that every possible field in the body of a request to the Messages API is required.
- Too narrow This situation proves nothing since only one request was sent.
- Off target This situation shows that the Messages API takes longer to respond when the request body is incomplete.
- The only entry point of the Claude API is the POST /v1/messages request, whatever the length of the conversation exchanged.
- The max_tokens field has no default value: it is required on every request, on the same footing as the model and the messages array.
- The model can stop before reaching the limit set by max_tokens, as soon as it judges its response complete.
- The response's stop_reason field carries distinct values depending on context, including end_turn, max_tokens, stop_sequence, tool_use, refusal, pause_turn and model_context_window_exceeded.
- The four counters in the usage field, input_tokens, output_tokens, cache_creation_input_tokens and cache_read_input_tokens, are enough to calculate the exact cost of a response.
Open an empty file and write the JSON body of a request to the Messages API for your own project, with the model you use, a max_tokens field and a messages array holding a single user message. Do not send it: re-read it and check that the three required fields are present.
Every datable claim in this lesson links here to the public text behind it. A source that does not open proves nothing.
- Anthropic, Messages API, request parameter reference consultée le 2026-09-02