Skip to main content
Sessions

Session Event Stream (SSE)

All interactions within a session are recorded as events and delivered in real time via Server-Sent Events (SSE) when subscribed to via the API.

Server-Sent Events

While an agent processes messages, the server pushes events of the following types:
typeDescription
messageAssistant-generated message output; may be streamed in chunks (cumulatively ordered by sequence_number)
tool_call / tool_call_outputBuilt-in tool invocation requests and their execution results
mcp_call / mcp_call_outputMCP tool invocation requests and their execution results
session_statusSession status change, including stop_reason (see Managing Sessions)

Client-Sent Events

Send events to a session using POST /sessions/{session_id}/events.
typeDescription
messageSends a user message, triggering the agent to transition into the running state
Sending a message event initiates agent processing. For full parameter details, see the Session API.
curl -X POST "https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/agentstudio/sessions/sesn_xxx/events" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": [
      {
        "role": "user",
        "type": "message",
        "content": [
          {"type": "text", "text": "Analyze Q3 sales trends in /mnt/session/uploads/sales.csv"}
        ]
      }
    ]
  }'

SSE Subscription

When sending a message event, include the header Accept: text/event-stream in your request. The response will then deliver all session events in real time using the SSE format. Without this header, the API returns the full list of events (requiring polling for incremental updates). See the Session API for details.
curl -N "https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/agentstudio/sessions/sesn_xxx/events/stream" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Accept: text/event-stream"

Event Filtering

In the Console’s Events panel, use the dropdown menu in the top-left corner to filter events by type. Supported filters include: All events, User, Agent, Tool, Tool_output, Error, Model, and System.

Next Steps

  • Managing Sessions: Learn about the session state machine and tool invocation flow.
  • Session API: Detailed documentation for the SSE event stream API.