How Streaming Works
The Nusantara AI API implements streaming using Server-Sent Events (SSE) when you set thestream: true
parameter in your request. When a streaming request is made:
Content-Type
Header: The API sets theContent-Type
header totext/event-stream
.- Partial Data Chunks: The server sends data in small chunks. Each chunk is an event with a specific type and data payload.
- End of Stream Signal: The stream is terminated by a final event, like
response.completed
or adata: [DONE]
message, indicating that no further data will be sent.
Usage with SDKs
You can enable streaming easily by settingstream: true
in your request body. Below are examples for both of our main endpoints.
- Responses API
- Chat Completions API
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.