Skip to content
Mastering Claude

Home

Building and certifying8 lessons57 min

The Claude API for builders

  1. 01The request, a single point of entry6 min

    The Claude API has a single point of entry, the POST request of the Messages API: every exchange goes through it, with a messages array and a chosen model. The max_tokens field is required, with no default value, and the response always follows the same shape, with a stop_reason saying why generation stopped.

  2. 02Roles that hold, not a prefill that breaks7 min

    Completing the start of Claude's response yourself, assistant turn prefilling, no longer works on current models: the server returns an error, except for one special case of refusal handling. A stable system instruction produces the same result without touching the messages array, and the output_config.format field constrains the shape of the output.

  3. 03Tools: Claude proposes, the code decides7 min

    Claude never executes a tool itself: it returns a usage request, the developer's code actually executes it, then returns the result so the conversation can continue. This cycle rests on a single contract, the schema declared by input_schema. A tool is declared with name, description and input_schema.

  4. 04Receiving the response as it streams6 min

    Streaming mode keeps the HTTP connection open and delivers the text in fragments as the model produces it, without waiting for generation to finish. The token count lives in the usage field of the last message_delta event, never in message_stop: code that looks for it there will not find it.

  5. 05Two cost levers: cached memory and batch processing8 min

    A request prefix marked as reusable costs a reduced fraction of the normal price when read back from the cache, and a set of non-urgent requests processed in a batch costs less than immediate processing, two discounts that stack with each other and with the other pricing modifiers.

  6. 06Counting before sending: the context window6 min

    A dedicated counting endpoint returns the number of tokens in a request before it is sent, and the context window to compare against this figure is no longer one shared value across a whole model range, it now varies sharply from one family to another.

  7. 07Choosing a model, switching models, and handling a refusal9 min

    The choice of a model is a trade-off between quality, speed and cost that gets revisited with every new generation, and a refusal returned by a safety classifier is handled as a normal case of the protocol, not as a failure.

  8. 08Moving to Opus 5.5 without breaking your code8 min

    Moving from Claude Opus 5 to Claude Opus 5.5 is not just a matter of changing the identifier: four old settings now return a 400 error, and the notes written between two tool calls arrive empty until the code sets thinking.display.