API Reference
Events, SSE streaming, and WebSockets in camelRun v2
Stream live camelRun v2 agent events over SSE (?after=...&follow=1), poll JSON events, or connect over the hibernatable /ws WebSocket.
Every camelRun v2 agent maintains a monotonically ordered SQLite event log (seq = 1, 2, 3, ...). You can read it over Server-Sent Events (SSE), JSON polling, or a hibernatable WebSocket.
SSE streaming (GET /v2/agents/:idOrKey/events)
Send Accept: text/event-stream to open an SSE stream. Auth can be sent via Authorization: Bearer <token> or ?token=<token> (useful for browser EventSource).
curl -N "https://run.camelai.com/v2/agents/support-42/events?after=0&follow=1" \
-H "Authorization: Bearer $CAMELRUN_API_KEY" \
-H "Accept: text/event-stream"Query parameters and headers:
| Parameter / Header | Behavior |
|---|---|
after (or Last-Event-ID header) | Non-negative integer sequence cursor. Replays stored events with seq > after before switching to live events. Last-Event-ID takes precedence over after. |
runId | Optional filter to stream only events for one run. When runId is set, the stream closes automatically after a terminal event (run_completed, run_failed, run_cancelled, or input_required) or immediately after replay if the run already settled. |
follow=1 | Keep the stream open across runs when runId is not set, even while the agent is idle. Without follow=1, an idle agent replays stored events and closes. |
Wire format
Each SSE event has id, event, and data:
: connected
id: 14
event: text_delta
data: {"seq":14,"runId":"run_abc123","type":"text_delta","data":{"delta":"Hello","step":0},"createdAt":1763760000123}
: heartbeat- Heartbeat comments (
: heartbeat) are emitted every 10 seconds while idle. - If the upstream Durable Object socket closes (for example during a Worker deploy or idle hibernation), the SSE stream closes cleanly so
EventSourceor your client can reconnect withLast-Event-IDwithout missing events.
JSON polling (GET /v2/agents/:idOrKey/events)
Without Accept: text/event-stream, the endpoint returns a JSON page:
# Fetch the current high-water cursor without replaying old events
curl -s "https://run.camelai.com/v2/agents/support-42/events?after=latest" \
-H "Authorization: Bearer $CAMELRUN_API_KEY"
# { "events": [], "nextAfter": 42 }
# Poll events after seq 42
curl -s "https://run.camelai.com/v2/agents/support-42/events?after=42" \
-H "Authorization: Bearer $CAMELRUN_API_KEY"
# { "events": [...], "nextAfter": 47 }Hibernatable WebSocket (GET /v2/agents/:idOrKey/ws)
Connect to wss://run.camelai.com/v2/agents/:idOrKey/ws?token=<bearer> (or with an Authorization: Bearer ... header).
Server-to-client frames:
- Live agent events:
{ "type": "event", "seq": 14, "runId": "run_...", "event": { "type": "text_delta", "data": {...}, "createdAt": ... } } - Tool registration acknowledgement:
{ "type": "tools_registered", "tools": ["lookupOrder"] } - Attached tool call request:
{ "type": "tool_call", "callId": "call_...", "name": "lookupOrder", "args": { ... } } - Pong:
{ "type": "pong", "ts": 1763760000000 }
Client-to-server frames:
- Register local tools:
{ "type": "register_tools", "tools": ["lookupOrder"] } - Return local tool result:
{ "type": "tool_result", "callId": "call_...", "result": { ... }, "error": null } - Keepalive ping:
{ "type": "ping" }
Event types
Event type | Emitted when |
|---|---|
run_queued | A run is enqueued (runId, queueMode) |
run_started | A run begins executing |
text_delta | Model streams a text chunk (delta, step) |
tool_call_start | A tool call begins executing |
tool_call_end | A tool call finishes with result or error |
steer_applied | A mid-turn whileRunning: "steer" message is injected (steerId, text) |
input_required | Run pauses for human approval, ask_human, or signed MCP elicitation |
input_resolved | A pending input is answered or denied (id, status) |
run_resumed | A paused input_required run resumes execution |
run_completed | Run finishes (text, output, usage, filesChanged) |
run_failed | Run fails (error: { code, message }) |
run_cancelled | Run is aborted or cancelled |
context_compacted | Conversation history is compacted into a summary |
context_reset | Active context is reset via /reset-context (upToSeq) |
dream_completed | Memory consolidation writes /workspace/MEMORY.md |
message_start / message_end | Turn message boundaries (emitted on legacy-compatible runs) |