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

# Streaming

> Server-Sent Events, chunks, usage, and mid-stream errors.

With `stream: true`, Nito sends the reply a few tokens at a time over one long-lived connection instead of one JSON body. Use it when a person is watching the output or the output is long. Skip it for batch jobs that wait for the full text anyway. The exact wire format is in the [streaming format reference](/api/api-reference/streaming-format/server-sent-events).

## Turn It On

```shellscript wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl https://app.trynito.ai/v1/chat/completions \
  -H "Authorization: Bearer $NITO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "moonshotai/kimi-k3",
    "stream": true,
    "messages": [
      {"role": "user", "content": "Write a haiku about gateways."}
    ]
  }'
```

OpenAI SDKs expose this as `stream=True` and hand you an iterator of chunks.

## What Arrives

* **Content chunks.** `object` is `chat.completion.chunk`; new text is in `choices[].delta.content`. The assistant `role` arrives once, on the first chunk. Concatenate the deltas in order.
* **Heartbeats.** A `: keep-alive` comment line roughly every 15 seconds. Ignore it.
* **Usage chunk.** With `stream_options.include_usage: true`, a final chunk with an empty `choices` array and a `usage` object arrives before the end.
* **Terminator.** `data: [DONE]`.

Tool calls arrive as `tool_calls` fragments assembled by `index` ([Tool Calling](/api/features/tool-calling)); reasoning arrives as `reasoning_details` deltas ([Reasoning](/api/features/reasoning)).

## Mid-Stream Errors

Once streaming starts, `200` has already been sent. A later failure arrives as a chunk with a top-level `error` object and `finish_reason: "error"`. Check each chunk for `error` before reading `delta.content`. A failure before any byte is written returns an ordinary HTTP error.

## Privacy

Streaming works at every level. At [Encrypted](/api/api-reference/chat-and-text/encrypted), the deltas arrive as ciphertext for your client to decrypt.

## Related

<CardGroup cols={3}>
  <Card title="Chat Completions" icon="message-captions" href="/api/features/chat-completions">
    The endpoint.
  </Card>

  <Card title="Tool Calling" icon="screwdriver-wrench" href="/api/features/tool-calling">
    Function calls.
  </Card>

  <Card title="Reasoning" icon="brain-circuit" href="/api/features/reasoning">
    Think first.
  </Card>

  <Card title="Stream Format Reference" icon="book" href="/api/api-reference/streaming-format/server-sent-events">
    Every chunk field.
  </Card>

  <Card title="Privacy Levels" icon="file-lock" href="/privacy/levels">
    The four levels.
  </Card>
</CardGroup>


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