Call requirements, permissions, request fields, response fields, and error handling.
Request and permissions
GET https://openapi.qwenwork.ai/v1/session/sessions/{session_id}/events/stream
Authentication: Authorization: Bearer <access_token>; use an access token obtained through user OAuth authorization.
Required business Scope: session.session.read
Authorization methods declared by the contract: Organization authorization (organization), personal authorization (personal)
The platform must enable the Scope for the application. The user must have the corresponding business permissions, and the target resource must be within their accessible scope. Whether personal or organization authorization is available to the application depends on the actual console configuration.
Behavior and limitations
Omitting session_type selects a cloud session. Every remote-control request must use session_type=remote and provide a nonempty device_id. Providing device_id for a cloud session, an empty or unknown type, or duplicate target parameters returns 422 VALIDATION_ERROR. Cross-device aggregated lists and automatic fallback to cloud are not provided. Both types use the same authentication chain; the open platform validates the corresponding Scope declared by each endpoint.
Cloud sessions:
Server-Sent Events over a persistent connection. Event content is identical to GET /sessions/{session_id}/events and shares the same seq_id space; events are pushed as they occur rather than waiting for polling.
What this adds beyond polling. Agent text arrives at the granularity at which it is produced—a response is delivered as sequential fragments as they are written, not one finished block. Polling cannot see this layer: events have already been aggregated by the time they are stored.
Reading a fragmented message. Aggregate by id, not seq_id. Every fragment of a message has the same id; its seq_ids lists the covered sequence numbers. A frame whose seq_ids covers multiple values is the aggregated form and replaces content accumulated for that id; a single-value frame appends. This also makes reconnecting mid-message safe—the whole message returns rather than half of it being duplicated.
Cursor. Your resume position is the end of the first contiguous sequence range you hold, not the largest value you have seen. Within an envelope, advance to the maximum seq_ids value, not seq_id: seq_id is the first sequence number covered, so an aggregated message reports a smaller number than its actual delivery position. Resuming from it redelivers the message tail.
Missing sequence numbers are normal, not lost events. Some events exist but are not published by this endpoint, while still consuming sequence numbers—so numbers may skip. Do not treat gaps as missing events or wait for them. What matters is that nothing remains unresolved before your resume position.
Resuming. id: is written only at message boundaries, so reconnecting never lands in the middle of a message. If a gap truly cannot be recovered, an error frame with code resync_required tells you which endpoint to use to fill it and where to resume. This is expected after a long disconnection, not a fault.
Ending. The stream always ends with a done or error frame, never simply by closing the connection, so clients need not guess whether everything was received. done means orderly closure; session_terminated means the session itself has ended and reconnecting will never yield more data. Any other reason only closes the connection: reconnect with the last received id to continue. error carries a code and resume_from; every error code permits resuming from that position.
Authentication uses the same bearer token as other endpoints, sent through Authorization: Bearer <token>.
The public OpenAPI gateway reads Bearer Tokens only from the Authorization header. It does not authenticate using query tokens or login cookies. If native EventSource cannot set this header, use a streaming client that supports custom headers.
Tokens in URLs are recorded in access logs, proxy logs, and Referer, and URLs are far more likely than headers to be pasted into bug reports. Wherever headers are supported, the header form remains the safer default.
Two failure surfaces. Before the response starts, failures use normal HTTP status codes. Once the stream opens, its status is already 200; subsequent failures can only appear as an error frame or a disconnected connection. Clients must handle both.
Content safety. content_blocked retracts text already delivered by this stream; discard all content received for that turn_id. Retractions cannot be replayed, so those occurring while disconnected will not be delivered. You must still moderate agent-generated text yourself before forwarding it externally.
Remote-control sessions:
Shares public gateway authentication with cloud sessions; this endpoint requires the business Scope stated below. No controller device ID or pairing is required. The target remote-control master switch must be enabled. If explicitly disabled, returns 403 FORBIDDEN with detail.reason=ACP_HOST_DISABLED; rejected write requests return detail.acceptance=not_accepted. An explicitly nonexistent session returns 404 NOT_FOUND with detail.reason=SESSION_NOT_FOUND. Commands route only to target connections signed in to the currently authenticated account. Offline targets, unknown targets, and targets belonging to other accounts all return device unavailable. Unknown request body fields are rejected. Use cursor or Last-Event-ID to subscribe to events in the same resource scope; conflicting values are rejected. Omitting the cursor starts at the beginning of available history; a missing history prefix returns an error. Establish the subscription first, then obtain the activation snapshot; after replay, send buffered and live events. Heartbeats keep the connection alive. Slow consumers, history gaps, or event stream changes end the stream. Offline replay is limited to a known contiguous cache window and does not represent the latest execution state. done closes the observation channel without stopping the executing turn. Like cloud SSE, authentication occurs only on connection or reconnection. Established connections have no fixed 30-minute duration or token-expiry timer; immediate disconnection on credential expiry or revocation is not guaranteed. Reconnection requires valid credentials and the same session target. Errors before response headers are sent use JSON; after streaming starts, an SSE error frame is sent if the connection remains writable.
Call through the open platform, retaining the existing oauth_app Token, identity resolution, application IP restrictions, and resource ownership checks. Cloud and remote-control parameters retain their actual contract semantics.
Short paths such as /sessions in this page are relative to the common prefix /v1/session. Use the full path at the top of this page for actual requests.
Supported session types: cloud, remote
In the full JSON, x-session-variants preserves the parameters, request bodies, and responses for cloud and remote-control sessions separately. Do not mix fields from the two branches.
Path parameters
| Parameter | Type | Required | Description and constraints |
|---|---|---|---|
session_id | string | Yes | Session identifier: a UUID for cloud sessions; an opaque identifier on the selected device for remote-control sessions. Minimum length: 1 Maximum length: 256 |
Query parameters
| Parameter | Type | Required | Description and constraints |
|---|---|---|---|
cursor | string | No | Resume after this seq_id. 🔴 What to pass: the end of the first contiguous sequence range you hold, not the largest sequence number observed. If you hold 1,2,3,7,8, pass 3, not 8. Numbers you never received are normal (some events are not published here but still consume sequence numbers), so gaps are not lost events and will never be filled—but resuming past them skips everything in between. Within one frame: advance to the maximum seq_ids value, not seq_id—seq_id is the first sequence number covered by the frame, so an aggregated message reports a smaller number than it actually delivered. Resuming from it redelivers the message tail.⚠️ Omitting this is not the same as passing 0: omission means "start now" without replay; 0 means "replay from the start of the session". ?cursor= (a parameter name with an empty value) is equivalent to omission.Equivalent to the Last-Event-ID header, which takes precedence. Providing both with different values returns 422.Remote-control sessions: an opaque string cursor bound to the account, device, session, and event stream. Pass unchanged as a string in HTTP parameters: a decimal sequence number for cloud sessions, an opaque cursor for remote control. The service validates it according to session type. Maximum length: 8192 |
include_status | boolean | No | Set to false to receive only session_event frames. This does not suppress content_blocked, which is always delivered. Supported only for cloud sessions; passing this parameter for remote control returns 422. Set to false to receive only session_event frames. This does not suppress content_blocked, which is always delivered. |
session_type | string | No | Omitting session_type selects a cloud session. Every remote-control request must use session_type=remote and provide a nonempty device_id. Providing device_id for a cloud session, an empty or unknown type, or duplicate target parameters returns 422 VALIDATION_ERROR. Cross-device aggregated lists and automatic fallback to cloud are not provided. Both types use the same authentication chain; the open platform validates the corresponding Scope declared by each endpoint. Default: "cloud" Allowed values: ["cloud", "remote"] |
device_id | string | No | Required only for remote control. An opaque target device identifier from device discovery; it must be URL-encoded. The target connection must be signed in to the currently authenticated account. Minimum length: 1 Maximum length: 256 |
Header parameters
| Parameter | Type | Required | Description and constraints |
|---|---|---|---|
Last-Event-ID | string | No | Standard SSE resume header, sent automatically by the browser's native EventSource. Equivalent to ?cursor= and takes precedence over it.A position, not a count—do not add 1. The rule is the same as for ?cursor=: the end of the first contiguous sequence range you hold, not the largest observed value. The browser sends back the last id: written by this endpoint, and id: is written only at message boundaries—which is why the browser's automatic behavior is correct.Remote-control sessions: an opaque string cursor bound to the account, device, session, and event stream. Pass unchanged as a string in HTTP parameters: a decimal sequence number for cloud sessions, an opaque cursor for remote control. The service validates it according to session type. Maximum length: 8192 |
Request body
The public contract declares no request body. Do not add identity fields or undeclared business fields.
Successful responses
Preserve the original response structure of each business endpoint; do not add a common code/msg/data wrapper.
HTTP 200
Success
Response type: text/event-stream
| Field | Type | Required | Description and constraints |
|---|---|---|---|
| (entire response) | string | — | — |
SSE frame definitions
The response is UTF-8 text/event-stream, not a JSON array returned all at once. Array branches in the full contract describe the possible incoming frames. Clients dispatch on event and parse the corresponding data.
| event | Meaning |
|---|---|
session_event | Session business event |
session_status | Session status |
content_blocked | Retraction signal for delivered content |
done | This observation stream has ended |
error | In-stream error |
responses in the corresponding x-session-variants branch in this service's JSON.
Error responses
| HTTP | Description and handling |
|---|---|
default | Error. Branch on code, not just the HTTP status code—multiple conditions can share the same status code. |
Full field contract
The JSON below contains the complete request, response, and error schemas, nested constraints, and public extension definitions for this endpoint. Copy it for verification. Success examples not declared in the contract are not inferred.
Full OpenAPI JSON
Full OpenAPI JSON