Stream replies
Each conversation has an event stream:
GET /v1/chat/conversations/{conversation_id}/streamX-API-Key: uav_...Accept: text/event-streamThe stream stays open and sends events in the standard SSE format:
event: stream_chunkdata: {"participant_id": "c2e1...", "delta": "Two aircraft are due", "chunk_index": 0}Connect from your backend
Section titled “Connect from your backend”The browser’s built-in EventSource cannot send an X-API-Key or Authorization header, and your key must not reach the browser anyway. Open the stream from your server and relay events to your front end over your own authenticated connection.
// Node 22: relay a conversation's events to your own client channel.const res = await fetch(`https://api.uavcrew.ai/v1/chat/conversations/${id}/stream`, { headers: { 'X-API-Key': process.env.UAV_TENANT_KEY, Accept: 'text/event-stream' },});
const decoder = new TextDecoder();let buffer = '';for await (const chunk of res.body) { buffer += decoder.decode(chunk, { stream: true }); let end; while ((end = buffer.indexOf('\n\n')) !== -1) { const frame = buffer.slice(0, end); buffer = buffer.slice(end + 2); if (frame.startsWith(':')) continue; // keepalive comment const event = frame.match(/^event: (.+)$/m)?.[1] ?? 'message'; const data = JSON.parse(frame.match(/^data: (.+)$/m)?.[1] ?? '{}'); relayToClient(id, event, data); }}Events
Section titled “Events”| Event | Data | What to do |
|---|---|---|
stream_start |
participant_id |
Show an empty reply bubble for that agent. |
stream_chunk |
participant_id, delta, chunk_index |
Append delta to the bubble. |
stream_end |
participant_id |
The agent finished writing. Wait for message. |
message |
The full message | Replace the streamed text with this. It is the stored, authoritative version. |
stream_error |
participant_id |
Remove the partial bubble and show a retry option. |
tool_call |
participant_id, tool_name |
Optionally show “Checking maintenance records…”. |
action_card |
Proposal details | Show an approval card. See Approve what the crew writes. |
typing |
Participant details | Show a typing indicator for a human participant. |
handoff_announce |
from_participant_id, to_participant_id, reason, trigger |
Another agent is taking over. |
participant_joined / participant_left |
Participant details | Update the participant list. |
read_receipt |
Participant details | Update read state. |
The reply lifecycle
Section titled “The reply lifecycle”stream_start → stream_chunk × n → stream_end → messageAlways treat the final message as the truth. Streamed chunks are a preview; the stored message can differ slightly once formatting is applied.
Reconnecting
Section titled “Reconnecting”The stream can drop when a proxy times out or the network changes. Reconnect, then call GET …/messages to fill in anything you missed while disconnected.
