Skip to main content
Perplexica’s Search API supports streaming responses, allowing you to receive results incrementally as they’re generated. This provides a better user experience by displaying partial results immediately rather than waiting for the complete response.

Enable streaming

To enable streaming, set the stream parameter to true in your search request:

Response format

When streaming is enabled, the API returns a stream using Server-Sent Events (SSE) with Content-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-stream
  • Cache-Control: no-cache, no-transform
  • Connection: 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

  1. Connection - The stream begins with an init message
  2. Sources - A sources message contains all references used
  3. Content - Multiple response messages deliver the answer incrementally
  4. Completion - A done message signals the end of the stream
If the client disconnects before the stream completes, the server will automatically clean up resources and stop processing the request.

Non-streaming mode

If you prefer to receive the complete response at once, set stream to false or omit the parameter (defaults to false):
The response will be a standard JSON object: