Skip to main content
Streaming allows you to receive partial responses from the API as they are generated, rather than waiting for the entire response to be completed. This can significantly improve the perceived latency and user experience, especially for longer generations.

How Streaming Works

The Nusantara AI API implements streaming using Server-Sent Events (SSE) when you set the stream: true parameter in your request. When a streaming request is made:
  1. Content-Type Header: The API sets the Content-Type header to text/event-stream.
  2. Partial Data Chunks: The server sends data in small chunks. Each chunk is an event with a specific type and data payload.
  3. End of Stream Signal: The stream is terminated by a final event, like response.completed or a data: [DONE] message, indicating that no further data will be sent.
This allows your client application to display or process the generated content incrementally.

Usage with SDKs

You can enable streaming easily by setting stream: true in your request body. Below are examples for both of our main endpoints.
The /v1/responses endpoint uses a modern, event-driven stream. Each chunk is a typed event, allowing you to easily handle different parts of the response, such as text deltas or function call arguments.

Request Body Example

Example Streaming Events

Python & Javascript Examples

Last modified on December 3, 2025