This is a beta feature according to Algolia’s Terms of Service (“Beta Services”).
createAgentCompletion that returns a stream you iterate over.
Supported languages
Streaming is available in these API clients:- Go API client version 4.45.0 and later
- JavaScript API client version 5.54.0 and later
- Python API client version 4.42.0 and later
createAgentCompletion returns the complete response in a single call.
You can also stream from the HTTP endpoint with the stream parameter.
Stream completions
Open a stream and iterate over each event as it arrives. The following example streams a completion from a simple message:Raw and typed streams
Each client offers two streaming methods for the completion endpoint. Use the typed method for application code and the raw method when you need the events without parsing. Typed:CreateAgentCompletionStream (Go), createAgentCompletionStream (JavaScript), create_agent_completion_stream (Python). The client parses each event’s JSON payload for you:
- In Go, the returned stream’s
Current()method returns aStreamEvent: read the parsed payload fromevent.Data, the original event fromevent.Raw, and a parsing error, if any, fromevent.Err. - In JavaScript and Python, iteration yields
StreamEventobjects: read the parsed payload fromevent.data, the original event fromevent.raw, and a parsing error, if any, fromevent.error.
CreateAgentCompletionStreamRaw (Go), createAgentCompletionStreamRaw (JavaScript), create_agent_completion_stream_raw (Python). The client exposes the underlying SSE events without parsing them. Use this to proxy the stream to another service, parse events yourself, or forward event types the typed payload doesn’t model:
- In Go, the method returns an
sse.Decoder. Each event carries the JSON payload in itsDatafield, and you close the decoder yourself. - In JavaScript and Python, iteration yields
ServerSentEventobjects whosedatafield holds the JSON-encoded payload as a string.
Handle disconnections
Streaming requests connect to the first host only. They don’t retry or fail over to another host, and this behavior is the same in every client.If the connection drops mid-stream, re-initiate the stream from your application.