camelAI Documentation

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.

View as Markdown

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).

bash
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 / HeaderBehavior
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.
runIdOptional 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=1Keep 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 EventSource or your client can reconnect with Last-Event-ID without missing events.

JSON polling (GET /v2/agents/:idOrKey/events)

Without Accept: text/event-stream, the endpoint returns a JSON page:

bash
# 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 typeEmitted when
run_queuedA run is enqueued (runId, queueMode)
run_startedA run begins executing
text_deltaModel streams a text chunk (delta, step)
tool_call_startA tool call begins executing
tool_call_endA tool call finishes with result or error
steer_appliedA mid-turn whileRunning: "steer" message is injected (steerId, text)
input_requiredRun pauses for human approval, ask_human, or signed MCP elicitation
input_resolvedA pending input is answered or denied (id, status)
run_resumedA paused input_required run resumes execution
run_completedRun finishes (text, output, usage, filesChanged)
run_failedRun fails (error: { code, message })
run_cancelledRun is aborted or cancelled
context_compactedConversation history is compacted into a summary
context_resetActive context is reset via /reset-context (upToSeq)
dream_completedMemory consolidation writes /workspace/MEMORY.md
message_start / message_endTurn message boundaries (emitted on legacy-compatible runs)