> ## Documentation Index
> Fetch the complete documentation index at: https://docs.thesys.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Streaming Chunks

Streaming message chunks are returned by the API when `stream=true` is set in the request.

## Request Headers

<ParamField path="Authorization" type="string" required>
  The API key to use for the request.
</ParamField>

<ParamField path="Content-Type" type="string" required>
  The content type of the request. Should be `application/json`.
</ParamField>

## Request Body

<ParamField path="messages" type="array" required>
  An array of messages of the conversation so far.

  <Expandable title="Message Properties">
    <ParamField path="message.role" type="string">
      The role of the message. Can be either `user`, `assistant`, or `tool`.
    </ParamField>

    <ParamField path="message.content" type="string">
      The content of the message.
    </ParamField>

    <ParamField path="message.tool_call_id" type="string">
      The ID of the tool call. Only present if the role is `tool`.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField path="model" type="string" required>
  The model to use for the UI completion. Should be one of the models listed in the [Models](/api-reference/models-and-compatibility) page.
</ParamField>

<ParamField path="temperature" type="number">
  The temperature to use for the UI completion. Should be between 0 and 1.
</ParamField>

<ParamField path="top_p" type="number">
  The top-p value to use for the UI completion. Should be between 0 and 1.
</ParamField>

<ParamField path="max_tokens" type="integer">
  The maximum number of tokens to use for the UI completion.
</ParamField>

<ParamField path="n" type="integer">
  The number of completions to generate.
</ParamField>

<ParamField path="stop" type="integer">
  Should be unset or set to 1.
</ParamField>

<ParamField path="stream" type="boolean">
  Whether to stream the response. Should be `true` for streaming.
</ParamField>

<Note>
  The parameters above are commonly used with the Messages API. For a
  comprehensive list of all supported parameters and their compatibility across
  different model providers (OpenAI vs Anthropic), see the [Supported API
  Parameters](/api-reference/getting-started#supported-api-parameters) table.
</Note>

<RequestExample>
  ```sh curl theme={null}
  curl -X POST \
    -H "Authorization: Bearer <api_key>" \
    -H "Content-Type: application/json" \
    -d '{"model": "c1/anthropic/claude-sonnet-4/v-20251230", "stream": true, "messages": [{"role": "user", "content": "Hello, world!"}]}' \
    https://api.thesys.dev/v1/embed/chat/completions
  ```
</RequestExample>

<ResponseExample>
  ```
    id: 1
    data: {"id":"chatcmpl-1743157601318-pzx9ougakm","object":"chat.completion.chunk","created":1743157601,"model":"c1/anthropic/claude-sonnet-4/v-20251230","choices":[{"index":0,"delta":{"role":"assistant","content":{...}}]}

    id: 2
    data: {"id":"chatcmpl-1743157601318-pzx9ougakm","object":"chat.completion.chunk","created":1743157601,"model":"c1/anthropic/claude-sonnet-4/v-20251230","choices":[{"index":0,"delta":{"content":{...}}]}
  ```
</ResponseExample>

## SSE Event Stream

<ResponseField name="id" type="string">
  A identifier for this event.
</ResponseField>

<ResponseField name="data" type="object">
  One of the following objects:

  * [Completion Chunk](#completion-chunk)

  ## Completion Chunk

  <ResponseField name="id" type="string" required>
    A unique identifier for the UI completion. Will be the same in all events for a given completion.
  </ResponseField>

  <ResponseField name="object" type="string" required>
    The object type, which is always `chat.completion.chunk`
  </ResponseField>

  <ResponseField name="created" type="integer" required>
    Timestamp for when the chunk was created.
  </ResponseField>

  <ResponseField name="model" type="string" required>
    The model used to generate the UI completion.
  </ResponseField>

  <ResponseField name="usage" type="object">
    An object containing the usage statistics for the UI completion
    Only present if the generation is complete.

    <Expandable title="Properties">
      <ResponseField name="usage.prompt_tokens" type="integer">
        Number of tokens in the prompt
      </ResponseField>

      <ResponseField name="usage.completion_tokens" type="integer">
        Number of tokens in the generated UI completion
      </ResponseField>

      <ResponseField name="usage.total_tokens" type="integer">
        Total number of tokens: `prompt_tokens + completion_tokens`
      </ResponseField>
    </Expandable>
  </ResponseField>

  <ResponseField name="choices" type="array">
    An array of completions. Will always contain exactly one object.

    <Expandable title="Properties">
      <ResponseField name="finish_reason" type="string" optional>
        The reason the generation stopped. Can be either `stop` or `tool_calls`.
        Present only if the generation is complete.
      </ResponseField>

      <ResponseField name="delta" type="object">
        A JSON object containing the UI completion.
      </ResponseField>
    </Expandable>
  </ResponseField>
</ResponseField>
