Skip to main content
Set stream: true on any chat endpoint and NagaAI sends the answer as server-sent events while the model writes it. Your interface can show the first words while the model is still writing the rest.
The SDKs parse the events for you. With cURL you see them raw, one data: line per event, and the response has the text/event-stream content type.

Stream fields by format

Each format names its events differently, but they carry the same things. Use this table to find the field you need: Chat Completions sends usage only when you ask for it. That last chunk has an empty choices array, so check chunk.choices before you read from it, as the example does.

Responses events

Every event has an event: line with its type and a data: line with a JSON object that repeats the type and carries a sequence_number. A text answer starts with response.created, then response.output_item.added and response.content_part.added. The text follows in many response.output_text.delta events, and response.output_text.done, response.content_part.done and response.output_item.done close it. The last event is response.completed, with the full response and its usage. Tool calls add response.function_call_arguments.delta and .done, and web search adds response.web_search_call.in_progress, .searching and .completed. A stream that stops at max_output_tokens ends with response.incomplete instead of response.completed.

Chat Completions chunks

Each data: line holds a chat.completion.chunk, and all chunks of one answer share one id. The first chunk carries role: "assistant" in choices[0].delta. Later ones carry content, reasoning_content on reasoning models, or tool_calls. A tool call arrives in pieces: the first piece has the id and function.name, and later pieces with the same index add to function.arguments. The last content chunk has a finish_reason of stop, length, tool_calls or content_filter.

Messages events

message_start opens the message with its id and model. Each block of the answer, whether text, thinking or tool_use, comes as content_block_start, then content_block_delta events, then content_block_stop. The deltas are text_delta, thinking_delta, signature_delta or input_json_delta for tool input. message_delta brings the stop_reason and the final usage, and message_stop ends the stream.

When a provider fails

NagaAI holds back the 200 status until the first content is ready. If the provider it picked fails before that, inside its stream or before it, NagaAI sends the request to another provider that serves the model. You only get an error status when every attempt fails, and then it’s a normal error response, not an error inside a stream. Once content has started, the status is already sent, so a later failure arrives as an error event inside the stream. NagaAI doesn’t charge for the broken stream. Errors in a stream shows the event in each format and how to retry.

Closing the connection

The model keeps generating after your client disconnects, and NagaAI charges the full request. To limit the cost of answers you might abandon, set max_output_tokens in Responses or max_tokens in Chat Completions and Messages.