Skip to main content

Stream events (SSE)

Receive all events in a session in real time through Server-Sent Events (SSE). After the connection is established, the server pushes the session's complete event history and continues to stream new events as they occur.

Path parameters

ParameterTypeDescription
session_idstringSession ID with thesess_prefix

Request headers

HeaderRequiredDescription
AuthorizationYesBearer $QODER_PAT
AcceptRecommendedtext/event-stream

Query parameters

ParameterTypeRequiredDescription
after_idstringNoOnly receive events created after this event ID

Example request

curl -N -X GET "https://api.qoder.com.cn/api/v1/cloud/sessions/sess_019e392c0d1e74e095d21ea4c6b41def/events/stream" \
  -H "Authorization: Bearer $QODER_PAT" \
  -H "Accept: text/event-stream"

Example response

HTTP 200 OK Content-Type: text/event-stream Each event follows the standard SSE format:
id: [event_id]
event: [event_type]
data: [json_payload]

SSE format examples

The JSON in each SSE data line is a completely flat structure — all fields (such as name, input, tool_use_id, content, and is_error) sit at the top level with no additional nesting. The content field is always an array in SSE output, for example [{"type": "text", "text": "..."}]. User message:
id: evt_019e392c0d787cfaa21bda98e06cd913
event: user.message
data: {"id": "evt_019e392c0d787cfaa21bda98e06cd913", "type": "user.message", "content": "Hello", "turn_id": "turn_019e392c0d787ceea6bb62943f9ac3ec", "created_at": "2026-05-18T03:40:48.888851795Z", "session_id": "sess_019e392c0d1e74e095d21ea4c6b41def", "processed_at": "2026-05-18T03:40:48.888851795Z", "schema_version": "1.0"}
Session scheduled:
id: evt_771c1195bcbd4a07834d4ed4dd6450ca
event: session.status_running
data: {"id": "evt_771c1195bcbd4a07834d4ed4dd6450ca", "type": "session.status_running", "turn_id": "turn_019e392c0d787ceea6bb62943f9ac3ec", "created_at": "2026-05-18T03:40:50.321Z", "session_id": "sess_019e392c0d1e74e095d21ea4c6b41def", "processed_at": "2026-05-18T03:40:50.321Z", "schema_version": "1.0"}
Agent reply:
id: evt_f8599c68e7784f2d8c490af1b3056716
event: agent.message
data: {"id": "evt_f8599c68e7784f2d8c490af1b3056716", "type": "agent.message", "content": [{"text": "Got it! Message received.", "type": "text"}], "turn_id": "turn_019e392d6aad7158b377c039c6ba5db3", "created_at": "2026-05-18T03:42:41.194Z", "session_id": "sess_019e392c0d1e74e095d21ea4c6b41def", "processed_at": "2026-05-18T03:42:41.194Z", "schema_version": "1.0"}
Agent tool call:
id: evt_01JZ6Q3FB6SG8F7J1M2N
event: agent.tool_use
data: {"id": "evt_01JZ6Q3FB6SG8F7J1M2N", "type": "agent.tool_use", "schema_version": "1.0", "session_id": "sess_019e392c0d1e74e095d21ea4c6b41def", "turn_id": "turn_019e392c0d787ceea6bb62943f9ac3ec", "tool_use_id": "toolu_bdrk_01T42NPLcKrBvLJfWgGt3QMt", "name": "Bash", "input": {"command": "echo hello"}, "requires_confirmation": false, "processed_at": "2026-05-18T03:41:05.000Z"}
Tool result:
id: evt_01JZ6Q5Y0S1H2G3F4E5D
event: agent.tool_result
data: {"id": "evt_01JZ6Q5Y0S1H2G3F4E5D", "type": "agent.tool_result", "schema_version": "1.0", "session_id": "sess_019e392c0d1e74e095d21ea4c6b41def", "turn_id": "turn_019e392c0d787ceea6bb62943f9ac3ec", "tool_use_id": "toolu_bdrk_01T42NPLcKrBvLJfWgGt3QMt", "name": "Bash", "content": [{"type": "text", "text": "hello\n"}], "is_error": false, "processed_at": "2026-05-18T03:41:06.000Z"}
Session idle (turn complete):
id: evt_a289470296c94e7ba8d7ea562efe5925
event: session.status_idle
data: {"id": "evt_a289470296c94e7ba8d7ea562efe5925", "type": "session.status_idle", "usage": {"input_tokens": 150, "output_tokens": 42, "cache_read_input_tokens": 0, "cache_creation_input_tokens": 0}, "status": "idle", "turn_id": "turn_019e392d6aad7158b377c039c6ba5db3", "created_at": "2026-05-18T03:42:41.195Z", "session_id": "sess_019e392c0d1e74e095d21ea4c6b41def", "stop_reason": {"type": "end_turn"}, "processed_at": "2026-05-18T03:42:41.195Z", "schema_version": "1.0"}

Event types

Supported event types:
event(SSE field)Description
user.messageUser-sent message
session.status_runningAgent started processing
span.model_request_startModel inference request started
agent.thinkingAgent thinking (internal reasoning)
agent.messageAgent-generated reply
agent.tool_useAgent invoked a built-in tool
agent.tool_resultTool execution result
agent.mcp_tool_useAgent invoked an MCP tool
agent.mcp_tool_resultMCP tool execution result
session.status_idleProcessing complete, session back to idle
span.model_request_endModel inference request ended
session.errorError occurred during processing
terminatedTurn terminated

Typical event lifecycle

A typical conversation turn streams events in the following order:
  1. user.message – user message enqueued.
  2. session.status_running – agent started.
  3. span.model_request_start – model call begins.
  4. agent.thinking – agent internal reasoning.
  5. agent.message – agent generates the reply.
  6. session.status_idle – turn complete, back to idle (includes usage stats).
  7. span.model_request_end – model call ends.

Client implementation guidance

  • Use the EventSource API or an HTTP client that supports SSE.
  • Listen for the session.status_idle event to detect the end of a conversation turn.
  • Use the turn_id field to correlate all events belonging to the same turn.
  • The connection stays open until the client disconnects; the server continues to push new events.

Errors

HTTPTypeTrigger
401authentication_errorPAT invalid or expired
404not_found_errorSession does not exist
See Errors for the full error envelope.