# Streaming

Page: https://galatea.co/api/docs/streaming

Server-sent events, one chunk per token group, ending with a data line of [DONE].

With stream set to true, the response has the content type text/event-stream. Each event is one line that starts with data: and holds a chat.completion.chunk object. The stream ends with data: [DONE].

- The first chunk carries the role and usually an empty content.
- Each later chunk carries the next piece of text in choices[0].delta.content.
- The last chunk carries finish_reason: stop, length or tool_calls.

To learn the token counts of a streamed answer, set stream_options.include_usage to true. The usage block then arrives on one last chunk, with cached tokens in prompt_tokens_details.

```curl
curl https://api.galatea.co/v1/chat/completions \
  -H "Authorization: Bearer $GALATEA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "deepseek-v4.1-flash-1017-uncensored", "stream": true, "stream_options": {"include_usage": true}, "messages": [{"role": "user", "content": "Hi"}]}'
```

If a stream breaks after it started, the edge sends an error frame: a data object with an error key, whose error.code says why (internal_error, deadline_exceeded and others) and whose error.type gives the class (server_error and others). Check every frame for the error key. The stream then ends with data: [DONE] whether it failed or not, so [DONE] alone does not mean the answer was complete.
