Connect
Query parameters
When true, the final
message envelope carries data.trace_info — the
reasoning trace.Omit for the minimal stream (token deltas + completion).
all or verbose
opts into the full workflow/lifecycle event set.With
task_id, replays buffered envelopes with seq greater than this value
on connect — gap recovery after a reconnect.Thread id to replay from on connect (pairs with
resume_after).Frames you send
message — submit a turn
Must be
"message".The target agent — use the
agent_id returned by the
token exchange.Omit to auto-create a thread; its id is announced back as the first
envelope. Pass it to continue an existing thread.
End-user reference for an auto-created thread.
The message content.
resume — replay after a reconnect
seq > resume_after for the active thread.
Envelopes you receive
Every server frame is a sequenced envelope:type | Meaning | data |
|---|---|---|
thread | The resolved thread id, once per thread per connection | { "thread_id": "..." } |
event | A streaming event while the agent works | Token deltas carry data.text under event name thread-message-text-content-updated |
message | Turn complete — the full agent reply | The same message object as REST, plus trace_info when include_trace=true |
error | A recoverable error; the socket stays open | { "error": "...", "code": 402 } for session errors, or the turn error’s message and status |
seq you’ve processed — that’s your resume cursor.
Locally-generated errors use seq: -1 and are not resumable.
Code example
Node.js
Best practices
- Reconnect with resume — on an abnormal close, reconnect with
task_id+resume_after(or send aresumeframe) instead of restarting the turn; you get exactly the envelopes you missed. - Track
seqcontinuously — a gap inseqmeans you missed frames; resume from your last processed value. - Exponential backoff — back off between reconnection attempts.
- Keep the thread id — persist
thread_idacross reconnects to stay in the same conversation.
/asyncapi.yaml.