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

# 创建实时会话

> 启动语音Agent对话会话，获取实时通信所需的房间信息和连接凭证。支持创建新对话或继续已有对话。

## 说明

提供端到端的实时语音交互能力，适合构建语音助手、陪伴 Agent、呼叫机器人等低延迟交互应用。

* **会话模型**：一个会话由 `session_id` 唯一标识，音视频通过 RTC 通道传输
* **生命周期**：`invoke` → [`status`](/api-reference/endpoint/realtime/status)（轮询）→ [`leave`](/api-reference/endpoint/realtime/leave)


## OpenAPI

````yaml POST /v1/realtime/invoke
openapi: 3.1.0
info:
  title: SenseAudio Open Platform API
  description: >-
    SenseAudio 开放平台
    API，覆盖语音合成、语音识别、音色能力、音乐生成、图片生成、视频生成、智能体与大语言模型等能力。未显式说明的字段为依据素材文档推断。
  version: 1.0.0
servers:
  - url: https://api.senseaudio.cn
    description: 生产环境
security:
  - bearerAuth: []
paths:
  /v1/realtime/invoke:
    post:
      tags:
        - Realtime
      summary: 创建对话式 Agent
      description: 启动语音Agent对话会话，获取实时通信所需的房间信息和连接凭证。支持创建新对话或继续已有对话。
      operationId: invokeRealtimeAgent
      parameters:
        - name: Content-Type
          in: header
          required: true
          description: 内容类型。固定为 application/json
          schema:
            type: string
            default: application/json
            example: application/json
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RealtimeInvokeRequest'
            examples:
              newDialogue:
                summary: 创建新对话
                value:
                  agent_id: 690f53770e9d9d60d98ba7a8
                  new_dialogue: true
              continueDialogue:
                summary: 继续已有对话
                value:
                  agent_id: 690f53770e9d9d60d98ba7a8
                  new_dialogue: false
                  conv_id: 9b8260e2-19d9-4609-abe7-3b74ac16b677
      responses:
        '200':
          description: 成功响应
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RealtimeInvokeResponse'
              example:
                conv_id: 9b8260e2-19d9-4609-abe7-3b74ac16b677
                app_id: d4432b04117aj77r7755c2d8e86e140b
                room_id: lO81loRAfmUMFIwY
                room_user_id: 360706506
                token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
        '400':
          description: 参数错误 / 配额不足
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                code: invalid
        '401':
          description: 鉴权失败
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                notFilled:
                  summary: 未填写API KEY
                  value:
                    code: authentication_error
                    message: invalid authorization
                apiKeyFailed:
                  summary: API KEY 错误
                  value:
                    code: authentication_error
                    message: incorrect API key provided
        '404':
          description: 对话不存在
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                code: notfound
                message: 资源未找到
                ref_code: 404000
        '500':
          description: 服务器内部错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                code: internal
                message: 服务繁忙，请稍后再试
                ref_code: 500000
      security:
        - bearerAuth: []
components:
  schemas:
    RealtimeInvokeRequest:
      type: object
      properties:
        agent_id:
          type: string
          description: Agent ID，可通过获取 Agent 列表接口获取
          example: 690f53770e9d9d60d98ba7a8
        new_dialogue:
          type: boolean
          description: '是否开启新对话。true: 创建全新的对话会话；false: 继续之前的对话'
          example: true
        conv_id:
          type: string
          description: >-
            对话 ID。当 new_dialogue 为 false
            时必填，用于继续之前的对话。可从之前调用此接口的返回结果中获取。如果未填写会创建新会话。
          example: 9b8260e2-19d9-4609-abe7-3b74ac16b677
      required:
        - agent_id
        - new_dialogue
    RealtimeInvokeResponse:
      type: object
      properties:
        conv_id:
          type: string
          description: 对话 ID，用于后续继续对话
          example: 9b8260e2-19d9-4609-abe7-3b74ac16b677
        app_id:
          type: string
          description: 实时通信 App ID
          example: d4432b04117aj77r7755c2d8e86e140b
        room_id:
          type: string
          description: 房间 ID，用于查询状态和停止对话
          example: lO81loRAfmUMFIwY
        room_user_id:
          type: integer
          description: 房间用户 ID
          example: 360706506
        token:
          type: string
          description: 连接凭证 (JWT)，用于建立实时通信连接
          example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
      required:
        - conv_id
        - app_id
        - room_id
        - room_user_id
        - token
    ErrorResponse:
      type: object
      properties:
        code:
          type: string
        message:
          type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API_KEY
      description: 格式：`Bearer <API_KEY>`

````