Skip to main content
Stream answers incrementally with stream: true on observe-and-respond (or respond), attach inline images in files, render downloadable citations, and load thread history.

Step 1: open a stream with an optional image

In v2, you do not need a separate image-upload route. Pass up to 10 images directly in files (base64-encoded data or an existing file_id), and set "stream": true on POST/v2/agents//threads//observe-and-respond (or POST…/respond when you do not want the agent to learn from user messages). Send an Idempotency-Key header so retrying after a connection drop never duplicates work or billing.
Image limits: 10 MiB per image, up to 10 images per message (PNG, JPEG, or WebP), up to 20 MiB total base64 image payload per v2 request.

Step 2: handle server-sent events

The response streams text/event-stream events:
SSE stream
Full complete event data payload:
complete event payload
Every stream ends with exactly one complete or one error event.

Step 3: render citations

Each item in citations names a file the answer drew on:
  • Proxy href through your backend with your API key so users can download or preview the source file without ever seeing your key.
  • verified: true means the model inspected an image attached on this turn; verified: false means the answer drew on memories learned earlier from a document.

Step 4: handle errors

Before the stream begins, errors arrive as standard HTTP statuses:
  • 400 or 422 invalid_request: missing content or speaker, or invalid image format.
  • 402 payment_required: organization balance is zero.
  • 404 thread_not_found or not_found: invalid thread id or unknown file_id in files.
  • 409 agent_not_ready: poll GET/v2/agents/ until ready.
  • 413 payload_too_large: image exceeds 10 MiB, more than 10 images, or total base64 payload exceeds the request cap.
  • 429 rate_limit_exceeded: more than 20 calls/min or 2 concurrent answers per subject. Wait Retry-After seconds.
  • 503 answer_model_unavailable: retry with the same Idempotency-Key.
After the stream starts, errors arrive in an error event carrying the same code and request_id.

Step 5: load conversation history

Returns the thread with up to its 200 most recent turns in messages. To paginate older turns, the owner calls GET/v2/agents//memories?thread_id=.