← All posts
·4 min read

How a Claude API call works, end to end

One request, one response: the five fields you send, the three you read back, and why stop_reason is the field first integrations most often get wrong.

This is Day 2 of Claude Architect in 30 Days. Day 1 mapped the five parts every Claude system is built from. Today follows a single call to the Claude API from start to finish: what you send, what comes back, and the one field that decides whether your code handles the answer correctly.

Who this is for: a developer writing a first integration with the Claude API, or reviewing one someone else wrote.

The five fields that make up almost every request.

What you send

A request to the Messages API is a small JSON object. Five fields do most of the work:

{
  "model": "claude-sonnet-5-5",
  "max_tokens": 16000,
  "system": "You answer customer questions using our refund policy.",
  "messages": [
    { "role": "user", "content": "Can I return an opened item?" }
  ]
}

model picks which Claude answers (Day 3 covers choosing). max_tokens is the most the reply may contain. system holds the role and the standing rules. messages is the conversation, alternating user and assistant turns and always starting with user. tools, when you add it, lists functions Claude may ask you to run.

There is only one endpoint for all of this. Tool use, structured JSON output and extended thinking aren't separate APIs; they're extra fields on the same request. That keeps the mental model small: one request in, one message out.

Claude remembers nothing between calls

The API is stateless. It doesn't keep the conversation for you, so a chat that feels continuous is your application sending the full history again on every turn: the first question, Claude's answer, the follow-up, and so on.

Two things follow from that. Your app decides exactly what Claude sees, which is a strength (Day 6 is about using it well). And long conversations get more expensive with every turn, because the history is input you pay for each time. That is where prompt caching earns its place.

What comes back

The response has three fields worth reading every time. content is a list of blocks, not a single string: usually text, but it can also hold a request to call one of your tools. stop_reason says why Claude stopped. usage reports the input and output tokens the call used.

The field to check first: stop_reason

The most common bug in a first integration is reading the text of the reply without asking why the reply ended. stop_reason tells you:

  • end_turn: Claude finished. Use the answer.
  • max_tokens: the reply hit your ceiling and was cut off mid-thought. Don't show it as if it were complete.
  • tool_use: Claude is asking you to run a tool. Run it and send the result back (Week 2 covers this).
  • refusal: Claude declined. There is no answer to parse.

Code that skips this check works in testing, where answers are short and nothing is refused, and fails later in ways that look random.

max_tokens is a ceiling, not a target

You are billed for the tokens Claude actually writes, not for the ceiling you set. So setting max_tokens too low saves nothing and cuts answers short. Set it generously, and treat a max_tokens stop as a signal to investigate rather than something to hide.

usage closes the loop. Record input and output tokens per feature from the first day, and cost stops being a surprise at the end of the month. Cost-aware LLM engineering covers what to do with those numbers.

Try this today

Log stop_reason on every call for a week, then count how often it isn't end_turn. Each one is an answer a user saw cut short, or a refusal your interface showed as a blank. Tomorrow is about choosing between Opus, Sonnet and Haiku. If you're building on the Claude API and want a review of the integration, that's part of the work I do in LLM and RAG systems.

Prefer slides? Download today's carousel as a PDF.

Shanker Dhand
Shanker Dhand
AI Engineer & Technical Lead

I design and ship production AI systems — RAG pipelines, agents, and evaluation infrastructure — built on 10+ years of full-stack engineering.

Related posts