Skip to content

Chat Completions Interaction Example

Back to OpenAI Chat Completions.

This compact example mirrors the detailed Chinese walkthrough. It shows the Chat shape: candidate choices[], each containing one assistant delta/message and optional tool_calls[].

  1. 1
    client request

    Client sends ordered `messages`, a function tool, optional search-like request settings, and `stream: true`.

  2. 2
    assistant delta

    The stream starts with a choice delta, usually carrying `role: assistant`.

  3. 3
    tool call deltas

    `choices[].delta.tool_calls[]` carries function argument fragments.

  4. 4
    finish_reason

    `finish_reason: tool_calls` marks that arguments are complete and local tools should run.

  5. 5
    tool message

    The next request sends a `role: tool` message with the matching `tool_call_id`.

  6. 6
    final answer

    The final stream emits `delta.content`, then `finish_reason: stop`, then `[DONE]`.

EntityJoin keyNotes
choicechoices[].indexDifferent candidate answers can interleave.
tool callchoice.index + tool_calls[].indexLater argument chunks may omit the tool id/name.
tool resulttool_call_idThe next request returns local tool output with this id.
stream endfinish_reason then [DONE]Chat streams use a data-only sentinel after terminal chunks.