DocumentationChat

Build

Chat

Instructions, a question, an answer. Then the rest of the exchange, sending the history back on every turn.

On this page
  1. Messages
  2. Multiple turns
  3. Useful parameters
  4. Reasoning

Messages

A conversation is a list of messages, each with a role.

RoleWho is speaking
systemYour instructions: tone, language, what the model should do or avoid
userThe person or your application
assistantThe model’s previous responses
toolThe result of one of your functions

Multiple turns

The model keeps nothing between calls. To continue an exchange, send the whole conversation again with the new message.

messages = [
    {
        "role": "system",
        "content": "Answer in French, in plain words.",
    },
    {
        "role": "user",
        "content": "What must a privacy notice contain?",
    },
]
first = client.chat.completions.create(
    model="flash", messages=messages
)

# No memory between calls: send the whole conversation again.
messages.append(first.choices[0].message)
messages.append(
    {
        "role": "user",
        "content": "Write one for a bakery with a web shop.",
    }
)
second = client.chat.completions.create(
    model="flash", messages=messages, temperature=0.4
)
print(second.choices[0].message.content)

Useful parameters

temperaturenumber
Lower gives more consistent responses, higher gives more varied ones. If unset, the model receives the value we chose for it.
max_tokensinteger
The maximum length of the response, capped at the model’s limit if it exceeds it.
response_formatobject
Asks for a response in JSON, so your code can read it directly.
stoparray
Character sequences that stop the response.

Reasoning

For a hard question, ask the model to think before answering. Effort ranges from none to high. The reasoning arrives separately, in reasoning_content.

response = client.chat.completions.create(
    model="max",
    reasoning_effort="high",
    messages=[
        {
            "role": "user",
            "content": "Compare these contracts.",
        }
    ],
)
message = response.choices[0].message
# How the model got there, then the answer.
print(getattr(message, "reasoning_content", None))
print(message.content)