Skip to content
NotHolyDocs

Guides

Streaming

Receive tokens as they are generated with server-sent events, in every API format.

View as Markdown

Set stream: true. The response is text/event-stream. Events are sent one by one, without buffering.

curl -N https://api.notholy.com/v1/chat/completions \
  -H "Authorization: Bearer $NOTHOLY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "notholy-specter", "stream": true, "stream_options": {"include_usage": true}, "messages": [{"role": "user", "content": "Define XSS."}]}'

What to expect

  • Chat completions and text completions end with data: [DONE]. The chunk before it always carries usage, with or without include_usage.
  • Responses ends with response.completed (or response.incomplete at the output limit). Messages ends with message_delta and message_stop. Neither sends [DONE].
  • Long pauses get keep-alive comments (OpenAI formats) or ping events (Messages).
  • If the stream breaks, you pay only for the tokens that were generated before the break.
  • Errors found before the stream starts (key, credits, limits) come back as a normal JSON error with its HTTP status. A failure after the stream starts arrives as an error event in the same format: data: {"error": ...}, response.failed or an error event.

Next