Enable streaming
To enable streaming, set thestream parameter to true in your search request:
Response format
When streaming is enabled, the API returns a stream using Server-Sent Events (SSE) withContent-Type: text/event-stream. Each line in the stream contains a complete, valid JSON object.
Stream headers
The streaming response includes these headers:Content-Type: text/event-streamCache-Control: no-cache, no-transformConnection: keep-alive
Message types
The stream sends different message types during the search process:init
Sent when the stream connection is established:sources
Sent once with all sources used to generate the response:response
Sent multiple times with chunks of the generated answer:done
Sent when the stream is complete:Complete example
Here’s what a complete streaming response looks like:Consuming the stream
Here are examples of how to consume the streaming API in different languages:Each line in the stream is a complete JSON object. Make sure to parse each line separately rather than treating the entire stream as a single JSON document.
Stream lifecycle
- Connection - The stream begins with an
initmessage - Sources - A
sourcesmessage contains all references used - Content - Multiple
responsemessages deliver the answer incrementally - Completion - A
donemessage signals the end of the stream
Non-streaming mode
If you prefer to receive the complete response at once, setstream to false or omit the parameter (defaults to false):