Skip to main content
Keep conversations going by sending previous messages along with each new request.
Multi-turn conversations enable you to build chat experiences where the model can refer to and respond within the context of previous messages, instead of treating every request as a new conversation. The Chat Completions API is stateless by design: it does not automatically retain any memory or context of earlier requests. To continue a conversation, resend the full conversation history with each request. Your application is responsible for managing that history and including the relevant messages.

How conversations work

A conversation is represented as a list of messages. Each message has a role and content. Common roles include:
  • user: Contains a message from the user.
  • assistant: Contains a previous response from the model.
To continue a conversation, include the previous messages along with the new user message in your next request.

Continue a conversation

Python

The following example sends two requests:
The second request includes all three messages:
  1. The original user request.
  2. The assistant’s response.
  3. The user’s follow-up request.
Because the model receives the conversation history containing the earlier exchange, it can answer the follow-up in context.

cURL

With cURL, you can achieve the same result by sending the conversation history in the messages array.

Streaming

To use multi-turn conversations with streaming, send the conversation history in messages and set stream: true in your request. As the response arrives, collect the assistant’s text and append the completed response to the conversation history before sending the next turn. See Streaming for details on handling streamed responses.

Tool calling

A tool-calling exchange adds an assistant message containing tool calls and one or more tool-result messages. See Tool Calling for a complete example. Don’t reduce a tool-call exchange to plain text if you expect the model to use the result correctly.