Skip to main content
Events

Stream session events

GET /api/v1/forward/sessions/{session_id}/events/stream Streams session events as Server-Sent Events. The data payload uses the same Forward filtering model as the event history endpoint. New integrations that need streaming output should subscribe with event_deltas[].

Headers

HeaderRequiredDescription
AuthorizationYesBearer <PAT or SAT>
AcceptYestext/event-stream
Last-Event-IDNoResume after this Event ID.
X-Qoder-BetaWhen subscribing to thinking deltasSet to thinking-event-stream-delta-2026-07-20 when event_deltas[]=agent.thinking is requested.

Path parameters

ParameterTypeRequiredDescription
session_idstringYesSession ID.

Query parameters

ParameterTypeRequiredDefaultDescription
event_deltas[]stringNo-Subscribe to streaming delta events for the specified public event types. Supports repeated parameters. Allowed values: agent.message, agent.thinking. See Event delta streaming.
include_tool_callsbooleanNotrueInclude tool call events.
include_thinkingbooleanNotrueInclude thinking events.

Example request

curl -s -X GET 'https://api.qoder.com.cn/api/v1/forward/sessions/sess_xxx/events/stream' \
  -H "Authorization: Bearer $QODER_ACCESS_TOKEN" \
  -H "Accept: text/event-stream"
Subscribe to text and thinking streaming delta events. Thinking deltas require the Beta request header:
curl -s -G 'https://api.qoder.com.cn/api/v1/forward/sessions/sess_xxx/events/stream' \
  -H "Authorization: Bearer $QODER_ACCESS_TOKEN" \
  -H "Accept: text/event-stream" \
  -H "X-Qoder-Beta: thinking-event-stream-delta-2026-07-20" \
  --data-urlencode 'event_deltas[]=agent.message' \
  --data-urlencode 'event_deltas[]=agent.thinking'

Example response

HTTP 200 OK
id: evt_xxx
event: agent.message
data: {"id":"evt_xxx","type":"agent.message","session_id":"sess_xxx","content":[{"type":"text","text":"Here is the analysis result."}],"processed_at":"2026-06-22T11:00:03Z"}

Event delta streaming example

When event_deltas[] is provided, the stream includes event_start and event_delta frames before the final buffered event:
id: evt_xxx
event: event_start
data: {"id":"evt_xxx","type":"event_start","session_id":"sess_xxx","event":{"id":"evt_xxx","type":"agent.message"}}

id: evt_xxx
event: event_delta
data: {"id":"evt_xxx","type":"event_delta","session_id":"sess_xxx","event_id":"evt_xxx","delta":{"type":"content_delta","index":0,"content":{"type":"text","text":"Here"}}}
Model usage event example:
id: evt_xxx
event: span.model_request_end
data: {"id":"evt_xxx","type":"span.model_request_end","is_error":false,"model_request_start_id":"evt_yyy","model_usage":{"credits":0.42},"processed_at":"2026-06-22T11:00:01Z"}

Response fields

FieldDescription
idSSE event ID. Equals the Event ID.
eventEvent type.
dataFiltered Forward Event JSON. Standard public events follow the Event type matrix documented by List Session Events; event delta stream frames follow Event delta streaming.

Connection interruptions and reconnection

An SSE connection can close because of gateway timeouts, server restarts, or similar conditions. The server does not guarantee that a connection remains open indefinitely. Clients must implement their own reconnection and retry logic:
  • Continuously record the id of the last SSE frame received. This is the Event ID.
  • After a disconnect, reconnect with that ID in the Last-Event-ID header to resume from the last received Event and avoid missing Events.
  • If a reconnect request omits Last-Event-ID, delivery starts at the tail of the event stream at connection time. Only Events created after the connection is established are delivered; historical Events are not replayed. To retrieve Events created while disconnected, first query history through List Session Events, and then establish the SSE connection to continue streaming.
  • Starting August 24, 2026, when a connection is established without Last-Event-ID, the server starts delivering from the tail of the event stream at connection time and does not replay historical Events. Recommended integration: retrieve historical Events through paginated List Events requests, receive real-time Events through SSE, reconnect with the last received Event ID in Last-Event-ID, and process Events idempotently by Event ID.

Errors

HTTPTypeCodeTrigger
404not_found_error-Last-Event-ID references an Event that does not exist or does not belong to this Session.
401authentication_errorauthentication_requiredPAT or SAT invalid or expired.
404not_found_errorsession_not_foundSession does not exist.

Notes

  • event_deltas[] is the recommended way to enable streaming; when this parameter is not provided, only standard public events are returned.
  • Incremental agent.thinking streaming is a Beta feature. Requests subscribing to it must include X-Qoder-Beta: thinking-event-stream-delta-2026-07-20; behavior may change during the Beta period.
  • After each model call completes, the stream emits a span.model_request_end model usage event. model_usage.credits is the incremental usage for that call. Read usage.total_credits from Get Session for the cumulative Session usage; see Model usage events in the data structure documentation.
  • Unknown Event types are forwarded as envelope-only events when available.
  • include_thinking=false filters thinking events, legacy thinking deltas, and new stream agent.thinking event start signals and delta.content.type=thinking fragments.
  • include_tool_calls=false filters tool-use events and legacy tool input/output deltas.