> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ariacompute.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 流式传输智能体事件

> 使用服务器推送事件（SSE）流式传输智能体会话的助手回复与中间增量。非常适合实时聊天界面。

此接口接受与非流式创建事件接口相同的载荷，但返回 `text/event-stream` 响应。你会以独立的 SSE 事件形式收到增量令牌、轮次边界与完成信号。

## 接口

```http theme={null}
POST /v1/agents/sessions/{session_id}/events/stream
```

## 认证

传递 `Authorization: Bearer <api-key>` 或 `Authorization: ApiKey <key>` 之一。

## 路径参数

<ParamField path="session_id" type="string" required>
  智能体会话标识符。
</ParamField>

## 请求体

<ParamField body="role" type="string" required>
  事件角色。消息用 `user`，工具结果用 `tool`。
</ParamField>

<ParamField body="content" type="string">
  消息的文本内容。当 role 为 `user` 时必填。
</ParamField>

<ParamField body="tool_calls" type="array">
  模型发出的工具调用对象数组。
</ParamField>

<ParamField body="tool_call_results" type="array">
  返回给模型的工具调用结果对象数组。
</ParamField>

## 响应

响应为 `text/event-stream`。每一行是一个 SSE 事件。常见的事件类型包括用于内容片段的 `delta`，以及模型轮次结束时的 `turn.completed`。

<RequestExample>
  ```bash cURL theme={null}
  curl -N -X POST https://agent.example.com/v1/agents/sessions/sess_01J5X8/events/stream \
    -H "Authorization: Bearer <api-key>" \
    -H "Content-Type: application/json" \
    -H "Accept: text/event-stream" \
    -d '{
      "role": "user",
      "content": "Explain quantum computing"
    }'
  ```
</RequestExample>

<ResponseExample>
  ```text/event-stream 200 theme={null}
  event: delta
  data: {"content":"Quantum"}

  event: delta
  data: {"content":" computing"}

  event: delta
  data: {"content":" is..."}

  event: turn.completed
  data: {}
  ```
</ResponseExample>
