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.
POST https://api.aivana.ai/v1/generate:streamJSON 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
| Event | What it carries |
|---|---|
| delta | A piece of the answer, in data.text. Append pieces in order to build the answer. |
| done | Ends 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. |
| error | The request failed after the stream began. Because the HTTP status was already 200, check for this event rather than relying on the status code. |
| trace | Only 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
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.
Quickstart Guide
Get your key and make your first request in minutes.
Try the Playground
Experiment with Aivana MMI — no account or code required.
Still have questions? We are here to help!