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

# 创建会话

> 根据图像、Persona 和音色创建实时会话。返回会话设置、WebSocket 控制凭证和 RTC 媒体凭证。最小可运行请求请参阅[快速开始](/cn/streaming-avatar/get-started/quickstart)。

对于角色视频会话，请提供 `output`。其中 `aspect_ratio` 接受 `9:16`（竖版）或 `16:9`（横版）。省略时默认为 `9:16`。不支持的宽高比会在会话开始前返回错误 `20004`。

> [accordion] 连接、时长和错误
>
> 响应中包含控制凭证和媒体凭证。连接方式请参阅[会话](https://docs.vivix.ai/cn/streaming-avatar/api-references/sessions#connect-and-control)，自动关闭请参阅[会话管理](https://docs.vivix.ai/cn/streaming-avatar/integrate/sessions.md)，错误码请参阅[错误](https://docs.vivix.ai/cn/streaming-avatar/api-references/sessions#errors)。

使用 `output.resolution` 选择 `480p` 或 `720p`。省略时，会话以 `720p` 启动，Vivix 会将图像适配到该尺寸。Vivix 会处理每张起始图像，包括会话后续可以切换到的图像。会话级 `image_fit` 优先于已保存角色中的设置。如果两处都未提供配置，Vivix 使用居中裁剪。同一个裁剪锚点会应用于会话中的所有图像。如果图像相对于画面过高，希望保留更多顶部区域，请发送：

```json theme={null}
{"image_fit":{"mode":"auto","crop_anchor":{"x":0.5,"y":0}}}
```

如果使用已经准备好尺寸的图像，请发送 `{"image_fit":{"mode":"manual"}}`。对于 JPEG，Vivix 会先应用 EXIF 方向信息，再检查尺寸。手动模式会保留画面范围，不进行裁剪和缩放。如果图像尺寸不正确，API 返回 `20013`，并在消息中包含字段路径、实际尺寸和期望尺寸。详情请参阅[准备起始图像](https://docs.vivix.ai/cn/streaming-avatar/character/first-image.md)。

对于 720p 竖版会话，使用 720 × 1280 的手动模式图像会产生以下错误：

```json theme={null}
{
  "code": 20013,
  "message": "invalid avatars: avatars[0].visual.source_images[0]: image is 720 × 1280, expected 672 × 1280; see https://docs.vivix.ai/streaming-avatar/character/first-image",
  "data": null
}
```

启用起始图像检查时，Vivix 会在图像适配后检查当前角色所选的起始图像，包括通过已保存角色创建会话的情况。如果请求返回 HTTP 422 和 `20021` 或 `20022`，请先更新图像再重试。详情请参阅[会话错误](https://docs.vivix.ai/cn/streaming-avatar/api-references/sessions#errors)和[起始图像指南](https://docs.vivix.ai/cn/streaming-avatar/character/first-image.md)。


## OpenAPI

````yaml cn/streaming-avatar/api-references/openapi.json POST /v1/realtime-avatar/sessions
openapi: 3.1.0
info:
  title: Vivix Streaming Avatar API 中文参考
  version: 1.0.0
  description: Streaming Avatar 会话、音色和角色的 REST 接口。
servers:
  - url: https://api.vivix.ai
security:
  - bearerAuth: []
paths:
  /v1/realtime-avatar/sessions:
    post:
      summary: 创建会话
      description: >-
        根据图像、Persona 和音色创建实时会话。返回会话设置、WebSocket 控制凭证和 RTC
        媒体凭证。最小可运行请求请参阅[快速开始](/cn/streaming-avatar/get-started/quickstart)。
      operationId: createSession
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                image_fit:
                  $ref: '#/components/schemas/ImageFit'
                model:
                  type: string
                  description: 请使用 `vivix-a1-stream`。
                idempotency_key:
                  type: string
                  description: 用于重试会话创建的可选键。重试同一请求时复用同一个键；创建新会话时使用新键。
                session:
                  type: object
                  description: >-
                    开场时使用的角色和源图像。只有一个角色且只有一张图像时可省略此对象。会话期间可通过 `session.update`
                    切换所选角色或图像。
                  properties:
                    mode:
                      type: string
                      description: 会话模式。默认为 `video_avatar`，该模式会流式传输角色视频、语音和文本事件。
                      enum:
                        - video_avatar
                      default: video_avatar
                    active_avatar_id:
                      type: string
                      description: 初始角色 ID。只提供一个角色时可省略；提供多个角色时需要指定。
                    source_image_id:
                      type: string
                      description: 开场图像 ID。省略时使用当前角色的默认图像或唯一图像。如果无法自动选择默认图像，则必须设置。
                output:
                  type: object
                  description: 必填的视频输出设置。创建会话时设置宽高比和分辨率。
                  properties:
                    aspect_ratio:
                      type: string
                      enum:
                        - '9:16'
                        - '16:9'
                      default: '9:16'
                      description: 角色视频宽高比。实际输出设置中未提供时默认为 9:16。其他值会返回错误 20004。
                    resolution:
                      type: string
                      enum:
                        - 480p
                        - 720p
                      default: 720p
                      description: 角色视频分辨率。未设置分辨率时，实际会话输出默认为 720p。
                avatars:
                  type: array
                  description: >-
                    可用角色。至少提供一个，各 `avatar_id` 必须唯一。每个用于视频的角色都需要源图像。共享音色在
                    `pipeline_config.tts_config` 中配置。
                  items:
                    type: object
                    properties:
                      avatar_id:
                        type: string
                        description: 由调用方定义的角色 ID，在会话内必须唯一。
                      persona:
                        type: string
                        description: >-
                          使用自然语言或 Markdown 描述角色的身份、性格、说话方式、回答习惯、动作偏好和聆听行为。Vivix
                          会根据这段 Persona 自动准备角色行为。请参阅[编写
                          Persona](/cn/streaming-avatar/character/persona)。
                        minLength: 1
                      voice:
                        type: object
                        description: >-
                          多角色会话需要使用不同音色时，可为各角色提供 TTS 配置。请提供
                          `provider`、`provider_voice_id` 和
                          `model`。常规的会话级音色配置无需设置此对象，请改用
                          `pipeline_config.tts_config`。会话级 TTS
                          配置的优先级高于所有角色级音色配置。
                        properties:
                          provider:
                            type: string
                            description: >-
                              TTS 后端，例如
                              `qwen-audio-3.0-tts-flash_ws`、`elevenlabs` 或
                              `qwen3tts`。与 `provider_voice_id` 和 `model`
                              一起使用时必填。
                          provider_voice_id:
                            type: string
                            description: 服务商侧的音色或风格 ID。与 `provider` 和 `model` 一起使用时必填。
                          model:
                            type: string
                            description: >-
                              服务商的 TTS 模型 ID。与 `provider` 和 `provider_voice_id`
                              一起使用时必填。
                          speed:
                            type: number
                            description: 语速倍数。有效范围为 `0.7` 到 `1.2`。
                        required:
                          - provider
                          - provider_voice_id
                          - model
                      visual:
                        type: object
                        description: 视觉渲染设置。该角色用于视频渲染时必填。
                        properties:
                          source_images:
                            type: array
                            description: 该角色可用的已注册源图像。使用基于图像的角色视频渲染时必填。
                            items:
                              type: object
                              description: 一张可选择用于角色视频渲染的源图像。
                              properties:
                                source_image_id:
                                  type: string
                                  description: 由调用方定义的源图像 ID，在角色内必须唯一。
                                url:
                                  type: string
                                  description: >-
                                    可公开访问的起始图像 HTTPS URL。Vivix
                                    默认将其适配到会话尺寸。手动模式下，图像必须已与目标尺寸一致。
                                description:
                                  type: string
                                  description: 对人物、姿势和场景的可选说明。
                                media_type:
                                  type: string
                                  description: 图像媒体类型，例如 `image/png` 或 `image/jpeg`。
                                opening:
                                  type: object
                                  description: >-
                                    可选的开场语音或动作。可提供 `dialogue`、`action`
                                    或同时提供两者。选择此图像并开始渲染时执行。
                                  properties:
                                    dialogue:
                                      type: string
                                      description: 要合成的准确开场台词。
                                    action:
                                      type: object
                                      properties:
                                        prompt:
                                          type: string
                                          description: 开场动作的视觉运动提示词。
                                        duration_ms:
                                          type: integer
                                          minimum: 1
                                          description: 开场动作时长，单位为毫秒。
                                      required:
                                        - prompt
                                        - duration_ms
                                      description: 以提示词和持续时间描述的开场动作。
                                    starting_at:
                                      type: integer
                                      minimum: 0
                                      default: 0
                                      description: 从首帧可用起到开场内容开始前的延迟，单位为毫秒。
                              required:
                                - source_image_id
                                - media_type
                                - url
                          default_source_image_id:
                            type: string
                            description: >-
                              默认图像 ID。角色只有一张源图像时可省略；否则请设置此字段或
                              `session.source_image_id`。
                        required:
                          - source_images
                    required:
                      - avatar_id
                      - persona
                  minItems: 1
                pipeline_config:
                  type: object
                  description: 会话级的语音识别、语音合成、对话模型和音频渲染设置。这些设置在创建会话时确定，之后不可更改。
                  properties:
                    tag_audio_enabled:
                      type: boolean
                      description: >-
                        在主要回答前播放“嗯”“唔”等简短语音回应。默认为 `false`。还需要在 Persona 的
                        Speaking Style
                        部分配置开场方式；请参阅[简短语音回应](/cn/streaming-avatar/interaction/acknowledgement)。
                    tts_config:
                      type: object
                      properties:
                        tts_voice_id:
                          type: string
                          description: 内置音色 ID 或 Vivix 克隆的 `voice_id`。提供 `tts_config` 时必填。
                        tts_provider:
                          type: string
                          description: >-
                            语音服务。使用内置 Qwen Audio 音色时默认为
                            `qwen-audio-3.0-tts-flash_ws`。使用 Vivix
                            克隆音色时省略；使用其他服务时需要指定。
                        tts_model_id:
                          type: string
                          description: >-
                            语音模型。使用内置 Qwen Audio 音色时默认为
                            `qwen-audio-3.0-tts-flash`。使用 Vivix
                            克隆音色时省略；使用其他服务时需要指定。
                        tts_endpoint:
                          type: string
                          description: 自定义语音服务端点。使用内置音色或 Vivix 克隆音色时省略。
                        tts_api_key:
                          type: string
                          description: 使用自己的语音服务凭证时，提供语音服务 API 密钥。内置音色不需要单独的密钥。
                        payload:
                          type: object
                          description: >-
                            所选语音服务支持的其他参数。请参阅[语音合成](/cn/streaming-avatar/integrate/speech-synthesis)。
                      required:
                        - tts_voice_id
                      description: 会话级 TTS 配置。其优先级高于所有 `avatars[].voice` 配置。
                    asr_config:
                      type: object
                      properties:
                        provider:
                          type: string
                          description: >-
                            提供 `asr_config` 时必填。优先考虑转写准确率时使用 `doubao`；仅需识别英语时使用
                            `nova-3`。
                        language:
                          type: string
                          description: >-
                            可选的识别语言。例如，豆包可使用 `zh-CN` 或 `en-US`，Nova-3 可使用
                            `en`。该设置作用于输入语音。
                      required:
                        - provider
                      description: >-
                        省略该对象时使用 `vivix-asr`，这是默认的低延迟多语言识别服务。仅将 `provider` 设为
                        `doubao`，即可使用豆包的默认配置。请参阅[语音识别配置](/cn/streaming-avatar/integrate/speech-recognition)。
                    llm_config:
                      type: object
                      properties:
                        llm_backend:
                          type: string
                          description: 可选；目前仅支持 `openai`。
                        llm_base_url:
                          type: string
                          description: 兼容 OpenAI 的基础 URL。使用自定义对话服务时与 `llm_model` 一起提供。
                        llm_model:
                          type: string
                          description: 可选的自定义模型名称。
                        llm_api_key:
                          type: string
                          description: 自定义对话服务需要时，提供对话服务 API 密钥。
                        llm_temperature:
                          type: number
                          description: 可选的生成温度；请使用模型支持的取值范围。
                        llm_max_output_tokens:
                          type: integer
                          description: 可选的生成 token 上限，不是字数上限。
                        llm_extra_payload:
                          type: string
                          description: 可选的 JSON 编码对象字符串；不要传入嵌套对象。
                      description: >-
                        可选的对话模型配置。使用自定义服务时设置 `llm_base_url` 和
                        `llm_model`；也可以只覆盖生成参数。字段类型和示例请参阅[对话模型配置](/cn/streaming-avatar/integrate/dialogue-model)。
                    a2a_config:
                      type: object
                      description: >-
                        使用应用发布的音频驱动角色渲染。请参阅[纯渲染模式](/cn/streaming-avatar/integrate/pure-rendering)。
                      properties:
                        enable_a2a:
                          type: boolean
                          default: false
                          description: 设为 `true`，使用应用的实时音频驱动角色。
                        provider:
                          type: string
                          description: 使用 `passthrough` 渲染应用发布到 RTC 房间的音频。
                          enum:
                            - passthrough
                conversation:
                  type: object
                  description: 工具、轮次处理和响应生成使用的初始对话默认设置。
                  properties:
                    tools:
                      type: array
                      description: 会话中的响应可使用的工具。
                      items:
                        type: object
                        description: 一个工具定义。v1 目前仅记录函数工具。
                        properties:
                          type:
                            type: string
                            description: 请使用 `function`。
                          name:
                            type: string
                            description: 可供响应规划器调用的函数名称。
                          description:
                            type: string
                            description: 便于用户理解的工具使用场景说明。
                          parameters:
                            type: object
                            description: 描述函数参数的 JSON Schema 对象。
                        required:
                          - type
                          - name
                    response_defaults:
                      type: object
                      description: 后续轮次使用的默认响应生成设置。
                      properties:
                        temperature:
                          type: number
                          description: 生成响应文本时使用的采样温度。支持范围为 `0` 到 `2`。
                        max_output_tokens:
                          type: integer
                          description: 单次响应最多生成的文本 token 数。
                    turn_detection:
                      type: object
                      description: 实时用户输入使用的默认轮次处理方式。
                      properties:
                        type:
                          type: string
                          description: >-
                            `manual` 表示由客户端显式启动响应；`server_vad`
                            表示由服务端根据传入的用户音频检测轮次边界。
                        silence_duration_ms:
                          type: integer
                          description: >-
                            兼容字段。不要使用它调整实际的语句结束时机。语音识别和轮次检测配置请参阅[语音识别配置](/cn/streaming-avatar/integrate/speech-recognition)。
                      required:
                        - type
                    input_audio_transcription:
                      type: object
                      description: 用户音频输入使用的默认转录设置。
                      properties:
                        enabled:
                          type: boolean
                          description: 是否转录用户音频。
                        language:
                          type: string
                          description: BCP-47 `language` 代码；也可设为 `auto`，以自动检测语言。
                assets:
                  type: object
                  description: >-
                    可复用的图像引用、音频、语音文本和动作提示。物体互动中的道具或产品请放在 `images`
                    中（请参阅[物体互动](/cn/streaming-avatar/interaction/object-interaction)）；角色的起始图像请放在
                    `avatars[].visual.source_images` 中。所有资产类型的资产 ID 必须互不重复。
                  properties:
                    images:
                      type: array
                      description: 道具或产品的参考图像。它们用于保持对象外观，不会替代角色的起始图像，也不会自行把对象放入场景。
                      items:
                        type: object
                        properties:
                          asset_id:
                            type: string
                            description: 对象引用 ID，在会话资产中必须唯一。请依次使用 `OBJ_0`、`OBJ_1` 等。
                          url:
                            type: string
                            description: 可公开访问的 HTTPS 图像 URL。
                          mime_type:
                            type: string
                            description: 图像 MIME 类型，例如 `image/png` 或 `image/jpeg`。
                          description:
                            type: string
                            description: >-
                              可选的视觉说明。如提供，请包含匹配的引用标签，例如对应 `asset_id: "OBJ_0"` 可写
                              `a dark gray cylindrical
                              speaker<OBJ_0>`。请参阅[物体互动](/cn/streaming-avatar/interaction/object-interaction)。
                        required:
                          - asset_id
                          - url
                    audio:
                      type: array
                      description: 可由脚本化语音输出引用的可复用音频文件。
                      items:
                        type: object
                        description: 一个可复用的音频资产。
                        properties:
                          asset_id:
                            type: string
                            description: 由调用方定义的音频资产 ID。
                          url:
                            type: string
                            description: 音频文件的 HTTPS URL。Vivix 必须能够在不添加自定义请求头的情况下直接访问该 URL。
                          mime_type:
                            type: string
                            description: 音频 MIME 类型。支持 `audio/wav` 和 `audio/mpeg`。
                        required:
                          - asset_id
                          - url
                    speech_text:
                      type: array
                      description: 可由脚本化语音输出引用的可复用准确语音文本。
                      items:
                        type: object
                        description: 一个可复用的语音文本资产。
                        properties:
                          asset_id:
                            type: string
                            description: 由调用方定义的语音文本资产 ID。
                          text:
                            type: string
                            description: 在 `response.script` 中使用时，要合成并通过输出文本事件流式返回的准确文本。
                        required:
                          - asset_id
                          - text
                    visual_prompts:
                      type: array
                      description: 可由脚本化视觉输出引用的可复用视觉指令。
                      items:
                        type: object
                        description: 一个可复用的视觉提示资产。
                        properties:
                          asset_id:
                            type: string
                            description: 由调用方定义的视觉提示资产 ID。
                          prompt:
                            type: string
                            description: 对角色动作、姿势、视线、手势或呈现方式的指令。
                        required:
                          - asset_id
                          - prompt
                delivery:
                  type: object
                  description: 媒体传输和交付设置。省略时默认使用 TRTC。
                  properties:
                    media:
                      type: object
                      description: 选择客户端发送和接收实时媒体的方式。
                      properties:
                        transport:
                          type: string
                          description: >-
                            会话请求使用的媒体传输方式。TRTC 使用 `trtc`，Agora 使用 `agora`。省略时默认为
                            TRTC。响应会在 `delivery.media.trtc` 或
                            `delivery.media.agora` 中返回对应服务商的加入信息。
                max_duration_seconds:
                  type: integer
                  description: >-
                    会话时长上限，单位为秒，最小值为 `4`。标准默认值为 20 分钟（`1200`
                    秒），但受工作区会话时长上限约束。请查看响应中的 `expires_at` 了解实际过期时间。
                  minimum: 4
                auto_close:
                  type: object
                  description: 创建会话时确定的自动关闭策略。响应返回应用平台默认值后实际生效的配置。
                  properties:
                    disconnected_timeout_seconds:
                      type: integer
                      description: >-
                        控制 WebSocket 断开达到指定秒数后关闭会话。省略时使用默认策略；设为 `0` 可禁用；也可设置为
                        `10`–`3600`。非零值不能超过会话时长。
                    interaction_idle_timeout_seconds:
                      type: integer
                      description: >-
                        在没有已接受的客户端交互或检测到的用户语音达到指定秒数后关闭会话。设为 `0` 可禁用；也可设置为
                        `30`–`3600`。非零值不能超过会话时长。Ping/Pong 不计为交互。
                recording_mode:
                  type: string
                  description: '`on` 或 `off`。传入 `off` 可禁用录制。'
              required:
                - model
                - avatars
                - output
            example:
              model: vivix-a1-stream
              output:
                aspect_ratio: '9:16'
                resolution: 720p
              avatars:
                - avatar_id: companion
                  persona: >-
                    You are a warm, curious conversation companion. Speak in
                    relaxed English and keep everyday replies brief. Acknowledge
                    corrections without making excuses. Use small smiles and
                    gentle nods, then let your hands rest while listening.
                  visual:
                    source_images:
                      - source_image_id: front
                        url: >-
                          https://static.vivi-x.ai/images/2026/07/20/b9b8e89651cd24ad.png
                        media_type: image/png
                        description: >-
                          A young woman with curly black hair and a pink shirt,
                          facing the camera in a softly lit room.
              pipeline_config:
                tts_config:
                  tts_voice_id: longanhuan_v3.6
      responses:
        '200':
          description: 成功
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - message
                  - data
                properties:
                  code:
                    type: integer
                    description: 成功时为 `0`；其他值均为错误码。
                  message:
                    type: string
                    description: '`success`，或英文错误说明。'
                  data:
                    type: object
                    properties:
                      session_id:
                        type: string
                        description: 已创建的角色会话 ID。
                      status:
                        type: string
                        description: 当前会话状态，例如 `active`、`closing`、`closed` 或 `failed`。
                      auto_close:
                        type: object
                        description: 首次创建会话时保存的实际生效策略快照。
                        properties:
                          disconnected_timeout_seconds:
                            type: integer
                            description: 实际生效的无控制 WSS 连接超时秒数。0 表示禁用。
                          interaction_idle_timeout_seconds:
                            type: integer
                            description: 实际生效的交互空闲超时秒数。0 表示禁用。
                        required:
                          - disconnected_timeout_seconds
                          - interaction_idle_timeout_seconds
                      session:
                        type: object
                        description: 应用默认值并通过校验后实际生效的可变会话状态。
                        properties:
                          mode:
                            type: string
                            description: 会话模式：`video_avatar`。
                            enum:
                              - video_avatar
                          active_avatar_id:
                            type: string
                            description: 视频中渲染并用于后续响应的角色。
                          source_image_id:
                            type: string
                            description: 当前用于生成角色视频的源图像 ID。
                        required:
                          - mode
                          - active_avatar_id
                      control:
                        type: object
                        description: 会话控制通道的连接信息。
                        properties:
                          url:
                            type: string
                            description: >-
                              控制通道的绝对 WSS URL，用于传输客户端控制事件和服务端状态事件。路径为
                              `/v1/realtime-avatar/control`，会话通过 `session_id`
                              查询参数标识；请始终连接此字段返回的完整 URL。
                          client_secret:
                            type: string
                            description: >-
                              本次会话的控制通道凭证。浏览器通过 `token` 查询参数发送；服务端客户端也可使用 Bearer
                              请求头。凭证在会话结束前始终有效，包括重连场景。请参阅[连接示例](/cn/streaming-avatar/api-references/sessions#connect-and-control)。
                        required:
                          - url
                          - client_secret
                      output:
                        type: object
                        description: >-
                          应用默认值和限制后实际生效的角色视频输出设置。当 `session.mode` 为
                          `video_avatar` 时提供。
                        properties:
                          aspect_ratio:
                            type: string
                            description: 实际生效的角色视频宽高比，为 `9:16` 或 `16:9`。
                          resolution:
                            type: string
                            description: 实际生效的角色视频分辨率，为 `480p` 或 `720p`。
                        required:
                          - aspect_ratio
                          - resolution
                      assets:
                        type: object
                        description: >-
                          可复用的图像引用、音频、语音文本和动作提示。物体互动中的道具或产品请放在 `images`
                          中（请参阅[物体互动](/cn/streaming-avatar/interaction/object-interaction)）；角色的起始图像请放在
                          `avatars[].visual.source_images` 中。所有资产类型的资产 ID
                          必须互不重复。
                        properties:
                          images:
                            type: array
                            description: 道具或产品的参考图像。它们用于保持对象外观，不会替代角色的起始图像，也不会自行把对象放入场景。
                            items:
                              type: object
                              properties:
                                asset_id:
                                  type: string
                                  description: 对象引用 ID，在会话资产中必须唯一。请依次使用 `OBJ_0`、`OBJ_1` 等。
                                url:
                                  type: string
                                  description: 可公开访问的 HTTPS 图像 URL。
                                mime_type:
                                  type: string
                                  description: 图像 MIME 类型，例如 `image/png` 或 `image/jpeg`。
                                description:
                                  type: string
                                  description: >-
                                    可选的视觉说明。如提供，请包含匹配的引用标签，例如对应 `asset_id:
                                    "OBJ_0"` 可写 `a dark gray cylindrical
                                    speaker<OBJ_0>`。请参阅[物体互动](/cn/streaming-avatar/interaction/object-interaction)。
                              required:
                                - asset_id
                                - url
                          audio:
                            type: array
                            description: >-
                              供 `response.script.vocal.type: "audio_asset"`
                              使用的可复用音频资产。
                            items:
                              type: object
                              description: 一个可复用的音频资产。
                              properties:
                                asset_id:
                                  type: string
                                  description: 由调用方定义的音频资产 ID。
                                url:
                                  type: string
                                  description: >-
                                    音频文件的 HTTPS URL。Vivix
                                    必须能够在不添加自定义请求头的情况下直接访问该 URL。
                                mime_type:
                                  type: string
                                  description: 音频 MIME 类型。支持 `audio/wav` 和 `audio/mpeg`。
                              required:
                                - asset_id
                                - url
                          speech_text:
                            type: array
                            description: >-
                              供 `response.script.vocal.type: "speech_asset"`
                              使用的可复用准确语音文本资产。
                            items:
                              type: object
                              description: 一个可复用的语音文本资产。
                              properties:
                                asset_id:
                                  type: string
                                  description: 由调用方定义的语音文本资产 ID。
                                text:
                                  type: string
                                  description: >-
                                    在 `response.script`
                                    中使用时，要合成并通过输出文本事件流式返回的准确文本。
                              required:
                                - asset_id
                                - text
                          visual_prompts:
                            type: array
                            description: >-
                              供 `response.script.visual.visual_prompt_asset_id`
                              使用的可复用视觉提示资产。
                            items:
                              type: object
                              description: 一个可复用的视觉提示资产。
                              properties:
                                asset_id:
                                  type: string
                                  description: 由调用方定义的视觉提示资产 ID。
                                prompt:
                                  type: string
                                  description: 对角色动作、姿势、视线、手势或呈现方式的指令。
                              required:
                                - asset_id
                                - prompt
                      conversation:
                        type: object
                        description: >-
                          应用服务端限制和默认值后实际生效的对话默认设置。结构和含义与请求中的 `conversation`
                          字段相同。
                        properties:
                          tools:
                            type: array
                            description: 会话中的响应可使用的工具。
                            items:
                              type: object
                              description: 一个工具定义。v1 目前仅记录函数工具。
                              properties:
                                type:
                                  type: string
                                  description: 请使用 `function`。
                                name:
                                  type: string
                                  description: 可供响应规划器调用的函数名称。
                                description:
                                  type: string
                                  description: 便于用户理解的工具使用场景说明。
                                parameters:
                                  type: object
                                  description: 描述函数参数的 JSON Schema 对象。
                              required:
                                - type
                                - name
                          response_defaults:
                            type: object
                            description: 后续轮次使用的默认响应生成设置。
                            properties:
                              temperature:
                                type: number
                                description: 生成响应文本时使用的采样温度。支持范围为 `0` 到 `2`。
                              max_output_tokens:
                                type: integer
                                description: 单次响应最多生成的文本 token 数。
                          turn_detection:
                            type: object
                            description: 实时用户输入使用的默认轮次处理方式。
                            properties:
                              type:
                                type: string
                                description: >-
                                  `manual` 表示由客户端显式启动响应；`server_vad`
                                  表示由服务端根据传入的用户音频检测轮次边界。
                              silence_duration_ms:
                                type: integer
                                description: >-
                                  兼容字段。不要使用它调整实际的语句结束时机。语音识别和轮次检测配置请参阅[语音识别配置](/cn/streaming-avatar/integrate/speech-recognition)。
                            required:
                              - type
                          input_audio_transcription:
                            type: object
                            description: 用户音频输入使用的默认转录设置。
                            properties:
                              enabled:
                                type: boolean
                                description: 是否转录用户音频。
                              language:
                                type: string
                                description: BCP-47 `language` 代码；也可设为 `auto`，以自动检测语言。
                      avatars:
                        type: array
                        description: 会话中实际生效的角色定义。结构和含义与请求中的 `avatars` 字段相同。
                        items:
                          type: object
                          properties:
                            avatar_id:
                              type: string
                              description: 由调用方定义的角色 ID，在会话内必须唯一。
                            persona:
                              type: string
                              description: >-
                                使用自然语言或 Markdown
                                描述角色的身份、性格、说话方式、回答习惯、动作偏好和聆听行为。Vivix 会根据这段
                                Persona 自动准备角色行为。请参阅[编写
                                Persona](/cn/streaming-avatar/character/persona)。
                            voice:
                              type: object
                              description: >-
                                多角色会话需要使用不同音色时，可为各角色提供 TTS 配置。请提供
                                `provider`、`provider_voice_id` 和
                                `model`。常规的会话级音色配置无需设置此对象，请改用
                                `pipeline_config.tts_config`。会话级 TTS
                                配置的优先级高于所有角色级音色配置。
                              properties:
                                provider:
                                  type: string
                                  description: >-
                                    TTS 后端，例如
                                    `qwen-audio-3.0-tts-flash_ws`、`elevenlabs` 或
                                    `qwen3tts`。与 `provider_voice_id` 和 `model`
                                    一起使用时必填。
                                provider_voice_id:
                                  type: string
                                  description: >-
                                    服务商侧的音色或风格 ID。与 `provider` 和 `model`
                                    一起使用时必填。
                                model:
                                  type: string
                                  description: >-
                                    服务商的 TTS 模型 ID。与 `provider` 和
                                    `provider_voice_id` 一起使用时必填。
                                speed:
                                  type: number
                                  description: 语速倍数。有效范围为 `0.7` 到 `1.2`。
                              required:
                                - provider
                                - provider_voice_id
                                - model
                            visual:
                              type: object
                              description: 视觉渲染设置。该角色用于视频渲染时必填。
                              properties:
                                source_images:
                                  type: array
                                  description: 该角色可用的已注册源图像。使用基于图像的角色视频渲染时必填。
                                  items:
                                    type: object
                                    description: 一张可选择用于角色视频渲染的源图像。
                                    properties:
                                      source_image_id:
                                        type: string
                                        description: 由调用方定义的源图像 ID，在角色内必须唯一。
                                      url:
                                        type: string
                                        description: 会话使用的起始图像 URL。
                                      description:
                                        type: string
                                        description: 对人物、姿势和场景的可选说明。
                                      media_type:
                                        type: string
                                        description: 图像媒体类型，例如 `image/png` 或 `image/jpeg`。
                                      opening:
                                        type: object
                                        description: >-
                                          可选的开场语音或动作。可提供 `dialogue`、`action`
                                          或同时提供两者。选择此图像并开始渲染时执行。
                                        properties:
                                          dialogue:
                                            type: string
                                            description: 要合成的准确开场台词。
                                          action:
                                            type: object
                                            properties:
                                              prompt:
                                                type: string
                                                description: 开场动作的视觉运动提示词。
                                              duration_ms:
                                                type: integer
                                                minimum: 1
                                                description: 开场动作时长，单位为毫秒。
                                            required:
                                              - prompt
                                              - duration_ms
                                            description: 以提示词和持续时间描述的开场动作。
                                          starting_at:
                                            type: integer
                                            minimum: 0
                                            default: 0
                                            description: 从首帧可用起到开场内容开始前的延迟，单位为毫秒。
                                    required:
                                      - source_image_id
                                      - media_type
                                      - url
                                default_source_image_id:
                                  type: string
                                  description: >-
                                    默认图像 ID。角色只有一张源图像时可省略；否则请设置此字段或
                                    `session.source_image_id`。
                              required:
                                - source_images
                          required:
                            - avatar_id
                        minItems: 1
                      delivery:
                        type: object
                        description: 服务端返回的媒体连接信息。当 `session.mode` 为 `video_avatar` 时提供。
                        properties:
                          media:
                            type: object
                            description: >-
                              临时媒体连接信息。在角色视频媒体可用时提供。根据 `transport`
                              的选择，只返回一种媒体类型。这些信息仅适用于本次会话，并非服务商账户凭证。
                            properties:
                              transport:
                                type: string
                                description: 用于区分返回哪种媒体类型的判别字段。支持 `trtc` 和 `agora`。
                              trtc:
                                type: object
                                description: '`trtc` 媒体类型对应的 TRTC 房间加入信息。'
                                properties:
                                  sdk_app_id:
                                    type: string
                                    description: >-
                                      客户端 SDK 使用的 TRTC 应用 ID。以字符串形式返回，符合 64
                                      位整数可能以字符串返回的约定。
                                  room_id:
                                    type: string
                                    description: 本次会话使用的 TRTC 房间 ID。
                                  user_id:
                                    type: string
                                    description: 分配给客户端的 TRTC 用户 ID。
                                  user_sig:
                                    type: string
                                    description: 用于加入 TRTC 房间的会话级签名。
                                  publisher_user_id:
                                    type: string
                                    description: TRTC 房间中发布角色视频的用户 ID。只订阅该用户 ID 即可接收角色视频流。
                                required:
                                  - sdk_app_id
                                  - room_id
                                  - user_id
                                  - user_sig
                                  - publisher_user_id
                              agora:
                                type: object
                                description: '`agora` 媒体类型对应的 Agora 频道加入信息。'
                                properties:
                                  app_id:
                                    type: string
                                    description: 客户端 SDK 使用的 Agora 应用 ID。
                                  channel_name:
                                    type: string
                                    description: 本次会话使用的 Agora 频道名称。
                                  token:
                                    type: string
                                    description: 用于加入 Agora 频道的会话级 token。
                                  user_id:
                                    type: string
                                    description: 分配给客户端的 Agora 用户 ID。
                                  publisher_user_id:
                                    type: string
                                    description: Agora 频道中发布角色视频的用户 ID。只订阅该用户 ID 即可接收角色视频流。
                                required:
                                  - app_id
                                  - channel_name
                                  - token
                                  - user_id
                                  - publisher_user_id
                            required:
                              - transport
                      model:
                        type: string
                        description: 请求中指定的模型。
                      expires_at:
                        type: string
                        format: date-time
                        description: 会话及其控制凭证的过期时间。服务端返回固定过期时间时提供，否则省略。
                      recording_mode:
                        type: string
                        description: 实际生效的录制模式：`on` 或 `off`。
                    required:
                      - session_id
                      - status
                      - auto_close
                      - session
                      - control
                      - conversation
                      - avatars
                      - model
                      - output
              example:
                code: 0
                message: success
                data:
                  session_id: avatar-session-123
                  status: active
                  session:
                    mode: video_avatar
                    active_avatar_id: companion
                    source_image_id: front
                  control:
                    url: >-
                      wss://api.vivix.ai/v1/realtime-avatar/control?session_id=avatar-session-123
                    client_secret: ctl_...
                  output:
                    aspect_ratio: '9:16'
                    resolution: 720p
                  delivery:
                    media:
                      transport: trtc
                      trtc:
                        sdk_app_id: '1400000000'
                        room_id: avatar-session-123
                        user_id: viewer
                        user_sig: ...
                        publisher_user_id: publisher_xxx
                  model: vivix-a1-stream
                  expires_at: '2026-07-16T10:05:00Z'
                  recording_mode: 'off'
                  auto_close:
                    disconnected_timeout_seconds: 0
                    interaction_idle_timeout_seconds: 0
                  conversation:
                    tools: []
                    turn_detection:
                      type: server_vad
                      silence_duration_ms: 500
                  avatars:
                    - avatar_id: companion
                      persona: >-
                        You are a warm, curious conversation companion. Speak in
                        relaxed English and keep everyday replies brief.
                        Acknowledge corrections without making excuses. Use
                        small smiles and gentle nods, then let your hands rest
                        while listening.
                      visual:
                        source_images:
                          - source_image_id: front
                            url: >-
                              https://static.vivi-x.ai/images/2026/07/20/b9b8e89651cd24ad.png
                            media_type: image/png
        '422':
          $ref: '#/components/responses/OpeningImageRejected'
components:
  schemas:
    ImageFit:
      type: object
      description: Vivix 将每张起始图像适配到视频角色会话画面的方式。会话级设置会覆盖已保存的角色设置。
      properties:
        mode:
          type: string
          enum:
            - auto
            - manual
          default: auto
          description: 自动模式会按比例填满画面并裁掉超出部分。手动模式不会裁剪或缩放，图像在应用 JPEG EXIF 方向信息后必须与目标尺寸完全一致。
        crop_anchor:
          type: object
          description: >-
            自动模式下，裁剪位置在可移动范围内的相对坐标。x 轴上 0 表示最左侧、1 表示最右侧；y 轴上 0 表示最上方、1
            表示最下方。省略时居中。
          required:
            - x
            - 'y'
          properties:
            x:
              type: number
              minimum: 0
              maximum: 1
            'y':
              type: number
              minimum: 0
              maximum: 1
  responses:
    OpeningImageRejected:
      description: 所选开场图像不符合视频会话的图像要求。
      content:
        application/json:
          schema:
            type: object
            required:
              - code
              - message
              - data
            properties:
              code:
                type: integer
                enum:
                  - 20021
                  - 20022
              message:
                type: string
              data:
                type: 'null'
          examples:
            faceTooSmall:
              summary: 使用主体更近的开场图像
              value:
                code: 20021
                message: >-
                  The avatar's face is too small in the opening image. Use a
                  closer shot with the full face clearly visible. See the
                  first-image guide:
                  https://docs.vivix.ai/streaming-avatar/character/first-image
                data: null
            solidBackground:
              summary: 选择包含背景细节的图像
              value:
                code: 20022
                message: >-
                  For better results, use an opening image with a background
                  that has some detail, such as a room or outdoor scene. See the
                  first-image guide:
                  https://docs.vivix.ai/streaming-avatar/character/first-image
                data: null
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: 你的 Vivix API 密钥。请仅保存在服务端。

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.