stream: true to receive output as server-sent events (SSE). Keep your Phaseo API key on your server and forward the output to your UI.
Send a streaming request
Read events
Use the event format for the endpoint you called:
SSE events are separated by blank lines. A network chunk can contain part of an event or several events; do not parse each network chunk as standalone JSON. Buffer incomplete frames or use an SDK stream helper. Do not assume every endpoint sends
[DONE].
The SDK helpers handle stream transport:
- TypeScript:
streamResponses(),streamChat(),streamMessages(). - Python:
stream_responses(),stream_chat(),stream_message(). - Vercel AI SDK:
streamText()with@phaseo/ai-sdk-provider.
Stream tool calls
Streaming with tools is accepted by the Gateway, but support depends on the selected model and provider. Accumulate tool-call argument deltas until the call is complete, then parse, validate, and authorise the arguments before execution. Never execute partial arguments. Follow tool-calling patterns for continuation requests and tool safety for validation and approval controls.Cancel and recover
Pass anAbortSignal to your server-side HTTP client and cancel when the user stops or disconnects. Set a deadline appropriate to the workload. Cancellation does not guarantee that the provider stops immediately or that generated output is free.
Render partial text progressively, but mark a response complete only after the endpoint’s successful terminal event. A closed connection alone is not proof of completion.
If a stream fails after output begins:
- Mark the partial response as interrupted.
- Keep the request or generation ID, endpoint, and model in your logs.
- Offer an explicit retry. A new request can generate different output and incur another charge.
- Do not replay executed tools or append a retried response to the partial output automatically.