Kolkata ·  
AI engineering
foundations
short · 3 min

The chat API

A list of messages with roles, sent every call. The model remembers nothing; some APIs store history for you, but you still pay for all of it.

updated 23 Sept 2026

When you chat with a model, it feels like it remembers you. You say hello, it says hello back, you ask a follow-up and it knows what you mean. It doesn't remember a thing. Let's follow one short conversation, one HTTP call at a time, and see where the memory really lives.

Call one

Here's the smallest request to Claude, as of 2026-09:

{
  "model": "claude-opus-5-5",
  "max_tokens": 1024,
  "messages": [
    {"role": "user", "content": "Hello, Claude"}
  ]
}

A model name, a cap on how long the answer can be, and a list of messages. Each message has a role: user is the person, assistant is the model. (Your own instructions as the developer go somewhere else, the system prompt.) A message's content can also be a list of blocks, so an image and a question can sit in the same message.

What comes back:

{
  "role": "assistant",
  "content": [{"type": "text", "text": "Hello!"}],
  "stop_reason": "end_turn",
  "usage": {"input_tokens": 12, "output_tokens": 6}
}

Two fields are worth a look on every reply. stop_reason says why it stopped: end_turn means it finished, max_tokens means it hit your cap and the answer got cut off. usage counts the tokens you're billed for.

Call two

Now the person asks "Can you describe LLMs to me?" If we send only that, the model has no idea a conversation happened. So we send all of it again:

"messages": [
  {"role": "user", "content": "Hello, Claude"},
  {"role": "assistant", "content": "Hello!"},
  {"role": "user", "content": "Can you describe LLMs to me?"}
]

That's the memory. It's this list, and our app keeps it. The input went from 12 tokens to 30, and the next call will be bigger again, because the model reads the whole history from the top every time.

Two things follow from that. The whole list, plus the reply, has to fit in the model's context window, so long chats eventually get trimmed or summarised. And since the list is ours, we can edit it. The assistant turns don't even have to be real. Writing them ourselves is how we show a model worked examples (few-shot prompting).

"But some APIs do keep the history"

True. OpenAI's Responses API can store it on their side. You pass previous_response_id to chain onto the last reply, or keep a Conversation object that lasts across sessions. Responses are kept for 30 days by default (store: false turns that off); Conversations don't expire.

Does that change the bill? No. The model still reads every earlier token in the chain, and every one is billed as input on each new turn. It saves us shipping the history over the wire, that's all. Claude's Messages API skips this and always takes the full list.

Old tutorials, new models

A common trick used to be starting the model's reply for it: end the list with an assistant message reading "The answer is (" so it fills in one letter. On Claude 4.6 and later, that's a 400 error now; use structured output or plain instructions. Claude 4.7 and later also reject temperature, top_p and top_k, so code that sets them will fail too.

Where developer instructions go also differs. Claude takes a top-level system field, and the newest models (Opus 4.8, the 5-series) also accept a system message partway through, just not as the first one. OpenAI does it its own way. Code written for one provider rarely runs as-is on the other.

Back to our three calls. The reply to call two is a long one, and the person stares at a blank screen until all of it is written. That's what streaming fixes.

Further reading

  • Using the Messages API, Anthropic docs. Short and worth reading end to end: the request, the multi-turn example, the system field, and why prefill now fails.
  • Conversation state, OpenAI docs. How server-side history works, and the one line that says you still pay for all of it.