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

# Stream Generation

> Stream text generation in real-time via Server-Sent Events

Stream text responses token-by-token using Server-Sent Events. Only available for text/LLM models.

## Request

Same as [Create Generation](/en/api-reference/generate/create) — `model`, `prompt`, optional `params`.

<CodeGroup>
  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://elumenta.ru/api/v2/generate/stream",
      headers={
          "Authorization": "Bearer nb_YOUR_API_KEY",
          "Accept": "text/event-stream"
      },
      json={
          "model": "gpt-5",
          "prompt": "Write a short story about a robot learning to paint"
      },
      stream=True
  )

  for line in response.iter_lines():
      if line:
          line = line.decode("utf-8")
          if line.startswith("data: ") and line != "data: [DONE]":
              import json
              chunk = json.loads(line[6:])
              if chunk.get("type") == "content_delta":
                  print(chunk["delta"], end="", flush=True)
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch("https://elumenta.ru/api/v2/generate/stream", {
    method: "POST",
    headers: {
      "Authorization": "Bearer nb_YOUR_API_KEY",
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      model: "gpt-5",
      prompt: "Write a short story about a robot learning to paint"
    })
  });

  const reader = response.body.getReader();
  const decoder = new TextDecoder();

  while (true) {
    const { done, value } = await reader.read();
    if (done) break;
    const lines = decoder.decode(value).split("\n");
    for (const line of lines) {
      if (line.startsWith("data: ") && line !== "data: [DONE]") {
        const chunk = JSON.parse(line.slice(6));
        if (chunk.type === "content_delta") {
          process.stdout.write(chunk.delta);
        }
      }
    }
  }
  ```
</CodeGroup>

## SSE Event Format

```
data: {"type": "generation_start", "id": 18473, "model": "gpt-5"}

data: {"type": "content_delta", "delta": "Once"}

data: {"type": "content_delta", "delta": " upon"}

data: {"type": "content_delta", "delta": " a time"}

data: {"type": "generation_end", "id": 18473, "tokens_spent": 3}

data: [DONE]
```

| Event type         | Fields               | Description          |
| ------------------ | -------------------- | -------------------- |
| `generation_start` | `id`, `model`        | Generation begun     |
| `content_delta`    | `delta`              | Token chunk          |
| `generation_end`   | `id`, `tokens_spent` | Done, billing info   |
| `error`            | `message`            | Something went wrong |

<Note>
  Streaming is only available for text/LLM models. Image, video, and audio models do not support streaming.
</Note>
