Docs

API Reference

Streaming

Streaming

Receive the answer as it is written, instead of waiting for the whole response.

POST /v1/generate:stream takes the same request body as Generate and answers with server-sent events (Content-Type: text/event-stream). It matters most for long answers, because the non-streaming call waits for the complete response.

text
POST https://api.aivana.ai/v1/generate:stream

JSON Schema (Strict) isn't streamed

A response_format of type json_schema is non-streaming. Its answer is checked against your schema before any of it is sent, which a stream can't wait for, so send it to Generate. Sent to this endpoint it is refused with a 422 and the code structured_output_streaming_not_supported, and nothing is charged. See Structured Outputs.

Events

EventWhat it carries
deltaA piece of the answer, in data.text. Append pieces in order to build the answer.
doneEnds the stream. Carries the final usage, finish_reason and notices, the same as a non-streaming response, and structured and structured_error when you asked for structured output.
errorThe request failed after the stream began. Because the HTTP status was already 200, check for this event rather than relying on the status code.
traceOnly when you set intelligence_trace to true: progress of the Intelligence Trace.

Ignore events you don't recognize

Handle delta, done and error, and skip any other event. That keeps your integration working as Aivana adds new event types.

Example

bash
curl -N https://api.aivana.ai/v1/generate:stream \
  -H "X-API-Key: $AIVANA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Explain the CAP theorem"}'

Stopping a stream

If you stop reading before the stream ends, the request is charged for its prompt and the part of the answer you received. If Aivana cuts an answer short on its side, for example because it ran out of time, the request isn't charged and you keep what you received; its finish reason is length.

Learn more

Parameters

Every option the Generate API accepts.

View in Docs

Quickstart Guide

Get your key and make your first request in minutes.

Try the Playground

Experiment with Aivana MMI — no account or code required.

Open PlaygroundView in Docs

Still have questions? We are here to help!

Try live

Run chat interactively in the Playground without any setup.

On this page

StreamingEventsExampleStopping a stream

Helpful links

Aivana Status

Was this helpful?

Still have questions? We are here to help!