← Docs

Chat completions deep-dive

Every field in the chat completion request and response, explained.

Roles

system

Sets assistant behavior. Optional but recommended. Placed first.

user

End-user messages. Can contain text or multimodal content parts.

assistant

Model responses. May include tool_calls. Used for multi-turn history.

tool

Response from an external function. Must reference a tool_call_id.

Content shapes

string

Plain text. Most common shape for user and assistant messages.

array

Content parts array. Each part has a type: text, image_url, or input_audio. Used for vision and audio inputs.

tool_calls

When the model decides to invoke a function, the assistant message carries a tool_calls array. Each entry has:

  • id — unique call identifier
  • type — always "function"
  • function.name — function to call
  • function.arguments — JSON string of parameters

tool_choice

autoModel decides whether to call a tool (default).
noneModel never calls a tool.
requiredModel must call one or more tools.
{"type":"function","function":{"name":"x"}}Force a specific function call.

finish_reason

stoplengthtool_callscontent_filter

stop — natural end or stop sequence hit. length — max_tokens reached. tool_calls — model wants to call a function. content_filter — omitted due to safety flags.