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

# Streaming

> Receive ReyGrid chat replies as Server-Sent Events by setting stream to true.

Set `"stream": true` in the [chat request](/api-reference/chat-with-an-agent) to receive the reply as a **Server-Sent Events (SSE)** stream of delta events instead of a single JSON body.

* The stream uses data-only messages (`data:` field). No `event:` field is sent.
* Each `data:` line carries a JSON object.

```bash theme={"system"}
curl -N -X POST https://reygrid.com/api/v1/agents/{AgentId}/chat \
  -H "Authorization: Bearer $REYGRID_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"message": "What are your hours?", "stream": true}'
```

## Frame shape

The OpenAPI document only states that frames are delta events. The official SDKs parse frames of this shape:

```text theme={"system"}
data: {"success":true,"delta":{"reply":{"content":"Hello"}}}

data: {"delta":{"reply":{"content":" there"}}}

data: {"delta":{"reply":{"content":""},"finish_reason":"stop"},"usage":{"credits":1}}
```

| Field | Notes |
| - | - |
| `delta.reply.content` | Text fragment to append |
| `delta.finish_reason` | Set on the terminal frame |
| `delta.tool_calls` | Tool calls delivered as deltas |
| `usage.credits` | Present on the terminal frame |
| `conversationId`, `messageId` | May be present |

<Info>
  The frame schema comes from the SDK implementations and tests, not from the OpenAPI specification. An empty `data:` message is treated by the SDKs as an end-of-stream marker.
</Info>

## Read a stream

<CodeGroup>
  ```python Python theme={"system"}
  for frame in client.stream_chat("{AgentId}", "What are your hours?"):
      if frame.delta and frame.delta.reply and frame.delta.reply.content:
          print(frame.delta.reply.content, end="")
  ```

  ```typescript TypeScript theme={"system"}
  for await (const frame of client.streamChat("{AgentId}", "What are your hours?")) {
    process.stdout.write(frame.delta?.reply?.content ?? "");
  }
  ```
</CodeGroup>

If you call the API directly, parse each `data:` line as JSON and append `delta.reply.content`. Errors that happen before streaming starts (such as 400 or 401) are returned as normal JSON error responses.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.