Streaming
Receive the agent's reply as server-sent events, or wait for it as a single JSON response.
POST /v1/conversations/{id}/messages stores the end user's message and runs the agent. With "stream": true the response is text/event-stream. Without it, the call waits for the whole reply and returns JSON.
Request
curl -N https://api.heyllo.co/v1/conversations/conv_8LpR3tY6nW1qK9xM2vB5cZ7d/messages \
-H "Authorization: Bearer $HEYLLO_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 6f1c2a9e-4b7d-4e0a-9c35-2d8f1b6a7e40" \
-d '{"content": "Do you ship to Nairobi?", "stream": true}'| Field | Type | Description |
|---|---|---|
content | string | The end user's message, 1 to 8,000 characters. Required. |
stream | boolean | true for server-sent events. Defaults to false. |
The endpoint needs the chat:write scope and an Idempotency-Key header. Rate limits, monthly limits and the concurrent-reply limit are checked before the stream opens, so those failures arrive as a normal JSON error with an HTTP status.
Events
Each event has an event: name and a single-line JSON data: payload.
| Event | Data |
|---|---|
message.created | The stored user message: a message object with role user. Always the first event. |
response.delta | { "text": "..." }, the next piece of the reply. Concatenate the pieces in order. |
response.tool | { "name": "...", "status": "started" } or "completed" when the agent uses a tool, for example knowledge_base_search. |
response.citations | { "citations": [...] }, the knowledge sources the reply used, each with title, source_type and source_ref. Sent only when there are citations. |
handoff.requested | { "reason": "..." } when the agent escalates the conversation to a human. |
response.completed | { "message": {...}, "usage": {...} }, the stored assistant message and the turn's token usage: input_tokens (the whole prompt, with cached_input_tokens and cache_write_tokens from the prompt cache), output_tokens (with reasoning_tokens) and total_tokens, over every model call made for the turn. The last event of a successful turn. |
error | { "error": { "type": "...", "code": "...", "message": "..." } }. The stream then closes. |
Error codes sent in the stream are conversation_busy, generation_failed, turn_timeout and upstream_unavailable. See Errors.
Example stream
event: message.created
data: {"id":"msg_51aH7kP2xQ9mN4vR6tW8yC3b","object":"message","conversation":"conv_8LpR3tY6nW1qK9xM2vB5cZ7d","role":"user","content":"Do you ship to Nairobi?","citations":[],"superseded":false,"created":"2026-11-18T09:05:00.000Z"}
event: response.tool
data: {"name":"knowledge_base_search","status":"started"}
event: response.tool
data: {"name":"knowledge_base_search","status":"completed"}
event: response.delta
data: {"text":"Yes, we deliver to Nairobi "}
event: response.delta
data: {"text":"within 3 to 5 working days."}
event: response.citations
data: {"citations":[{"title":"Shipping and delivery","source_type":"url","source_ref":"https://acme.example/help/shipping"}]}
event: response.completed
data: {"message":{"id":"msg_51bJ3nL8zT5qR2wK7pX4mV9d","object":"message","conversation":"conv_8LpR3tY6nW1qK9xM2vB5cZ7d","role":"assistant","content":"Yes, we deliver to Nairobi within 3 to 5 working days.","citations":[{"title":"Shipping and delivery","source_type":"url","source_ref":"https://acme.example/help/shipping"}],"superseded":false,"created":"2026-11-18T09:05:02.000Z"},"usage":{"input_tokens":1830,"cached_input_tokens":1536,"cache_write_tokens":0,"output_tokens":96,"reasoning_tokens":0,"total_tokens":1926}}Sync mode
Without "stream": true the call returns once the reply is complete. A turn is limited to 120 seconds, so allow a client timeout of at least 150 seconds.
{
"object": "turn",
"conversation": "conv_8LpR3tY6nW1qK9xM2vB5cZ7d",
"message": {
"id": "msg_51bJ3nL8zT5qR2wK7pX4mV9d",
"object": "message",
"conversation": "conv_8LpR3tY6nW1qK9xM2vB5cZ7d",
"role": "assistant",
"content": "Yes, we deliver to Nairobi within 3 to 5 working days.",
"citations": [],
"superseded": false,
"created": "2026-11-18T09:05:02.000Z"
},
"usage": {
"input_tokens": 1830,
"cached_input_tokens": 1536,
"cache_write_tokens": 0,
"output_tokens": 96,
"reasoning_tokens": 0,
"total_tokens": 1926
}
}If the turn fails, sync mode returns 409 conversation_busy, or 502 with generation_failed, turn_timeout or upstream_unavailable.
Behaviour
- Keepalive. A
: pingcomment line is sent every 15 seconds. Use a read timeout of at least 60 seconds. - One turn at a time. Only one reply runs per conversation. A second message sent while a reply is being generated gets
conversation_busy. - Concurrency. Your organisation can generate a limited number of replies at once. Beyond it, the request returns
429 concurrency_limitwithRetry-After. - Disconnects. If your client disconnects mid-reply, Heyllo still finishes the turn and stores the assistant message. Fetch it from
GET /v1/conversations/{id}/messagesor receive it through themessage.createdwebhook. - Retries. Retrying with the same
Idempotency-Keyafter a completed turn returns the final turn as JSON (the sync-mode body) with the headerIdempotent-Replayed: true, instead of running the agent again. If the turn failed, a retry with the same key runs it again. - Handoff. While a human agent handles the conversation, or a handoff is requested on a bot whose handoff
modeispause_ai, the user's message is stored and passed to the human. The stream sendsmessage.createdand thenresponse.completedwith"message": nulland"handoff_active": true.
A live event stream for a conversation, for example to receive human-agent replies as they are sent, is not available yet. Read new messages with GET /v1/conversations/{id}/messages or subscribe to webhooks.