chat/stream returns the answer as it is written, with citations at the end. This walkthrough sends one message with one image.
Step 1: upload the image the user attached
200.
413 payload_too_large: the image is larger than 10 MB. Make it smaller before you upload it.422 invalid_request: the bytes are not a PNG, JPEG, WebP, or GIF that can be decoded.400 invalid_request: theContent-Lengthheader is missing or wrong. Send the exact number of bytes.429 rate_limit_exceeded: more than 20 uploads in one minute. WaitRetry-Afterseconds.
Step 2: open the stream
turn_id is an id that you create. It must be unique for each message. If the connection drops and you send the same turn_id again, Priors charges the message only once.
Step 3: handle the events
The response is a stream of server-sent events.
A stream always ends with exactly one
complete event or one error event.
Step 4: show the citations
label as a link to href. verified: true means the model looked at this file for this message, which is the case for the image you attached. verified: false means the link comes from a memory that the file produced earlier, which is the case for every document learned before. Both are real sources. You can style them differently.
When it fails
Before the stream starts, the failure is an HTTP status:400or422 invalid_request:turn_idormessageis missing, ormessageis longer than 2,000 characters. Correct it and send again.413 payload_too_large: more than 10 images, or more than 32 MB of images, in the message. Remove an image and send again.404 not_found: an id inimage_source_idsis not an image this agent holds. Upload it first.404 thread_not_found: the thread is gone, or it is not yours.402 payment_required: no credits. Show a clear message. Do not send again.409 agent_not_ready: poll the agent, then send again.429 rate_limit_exceeded: more than 20 messages in one minute, or 2 answers already running. WaitRetry-Afterseconds. Show “one moment” to the user.503 answer_model_unavailable: wait, then send again with the sameturn_id.
error event, with the same code values. Keep the text already shown. Offer the user a way to try again with the same turn_id.
Step 5: show the history
What this walkthrough showed
- One message is one
turn_id. Use the sameturn_idwhen you send the message again. - Upload images first, then name them in the message.
- Every message is also learned. The agent remembers the conversation.