When streaming is useful
With a regular request, your application receives the complete text at once. With streaming, response fragments arrive as they are generated. You can display them immediately, which is useful for chats and long text responses.
Streaming does not change the model or message requirements. Use the same text model and messages, adding the stream parameter with a value of true. A complete request example is available in the SeaGenera documentation.
Process SSE events
SeaGenera returns a stream with the text/event-stream content type. Response text arrives in choices[].delta.content. Append each fragment to the text received so far, keeping their order. The [DONE] event marks the end of the stream.
A network chunk does not necessarily contain a complete event: one event may span several reads. Use an SSE parser and a streaming UTF-8 decoder. Handle comments and multiline events.
Handle cancellation and errors
Let the user stop generation through AbortController. Keep the text already displayed and clearly mark an incomplete response. Cancellation may still incur a charge for work the model has already completed.
HTTP status 200 does not rule out an error after streaming begins. Check error and finish_reason in events. If the connection closes without [DONE], treat the response as incomplete and check your history before retrying.
Show the confirmed cost
Usage information may arrive in a final event separately from the text. The usage.cost_rub field contains the confirmed cost in rubles when available. Do not calculate the charge from the number of received fragments.
While the cost is being finalized, show the operation status and use confirmed data or history for the final amount. The Streaming documentation includes SSE examples and a practical approach to handling the stream.

