How does chat work?
A chat request is a stateless list of role-tagged messages, and your application owns the conversation history.
Guide details
- Type
- Explainer
- Reading time
- 2 min read
- Scope
- Second rung of the agent fundamentals ladder: how message lists become model requests.
A chat model does not remember a conversation. What looks like an ongoing dialogue is, on the wire, a single request containing the entire message history so far.
Each message in that list carries a role and a text body. A system message sets instructions and constraints for the whole exchange. User messages carry requests; assistant messages record what the model previously replied. Some APIs add further roles for tool calls and their results. The client assembles this array, sends it to an endpoint, and the model returns the next assistant message.
Because the API is stateless, your application owns the conversation. To continue a dialogue you send the accumulated history again, appending the latest reply; trimming, summarizing, or reordering that history is your code's job, and everything you send counts against the token budget described in the token guide.
Two practical rules follow. First, put durable instructions in the system message rather than repeating them in every user turn. Second, treat history as data you curate: stale or contradictory messages keep influencing the model until you remove them.
Sources
- Chat Completions API reference — OpenAIdocumentationOpenAI
- Messages API reference — AnthropicdocumentationAnthropic
Taxonomy
Concepts
Topics
Related content
- RequiresWhat is a token?Message history is consumed as tokens and billed against the context window.
Referenced by
- RelatedWhat is a token?Chat requests are assembled from text that models consume as tokens.
Related
- What is a token?Mellnx first-partyagent-fundamentals
Tokens are the smallest units of text a language model reads or writes, and every context limit and price is measured in them.
- What is an AI agent?Mellnx first-partyagent-fundamentals
An AI agent is an LLM plus a harness plus tools running in a loop, with the model deciding each next step.
- What is a tool?Mellnx first-partyagent-fundamentals
A tool is a schema-described function the model can call by name, turning text output into real action.