The Messages API Is a State Machine
The API does not remember your conversation. Your application does, and one misplaced content block can break the entire loop. Model a Claude request as an explicit application state transition. Choose SDK or raw REST separately from synchronous, streaming, or batch delivery. Construct image and document content blocks with explicit asset boundaries. Preserve typed response blocks and branch on stopreason. Enforce session, retry, timeout, retention, and context-budget hygiene. Test a complete lifecycle without depending on a live API key. An engineer sends this sequence: User asks, "Where is order A-17?". Claude returns a tooluse block with ID toolu01. The application runs lookuporder. The application sends only the tool result in a fresh request. The second request fails, or Claude responds as though it never requested the tool. Nothing mysterious happened. The Messages API is stateless. The client failed to resend the assistant message containing the original tooluse block. A toolresult is not a freestanding fact. It answers a specific tool request by ID, inside a conversation sequence owned by your code. Frameworks make this easy to miss because they maintain the array for you. The certification expects you to reason below that convenience layer. Build the raw state machine once. Every SDK, agent framework, and managed runtime becomes easier to debug afterward. A request supplies the model, system instructions, messages,…
The Messages API Is a State Machine: The API does not remember your conversation. Your application does, and one misplaced content block can break the entire…
This free lesson is part of the AI Engineering from Scratch curriculum. Read the full explanation, run the lesson code, and verify the result in the interactive reader or from the repository source.
Browse the complete course catalog or open this lesson on GitHub.