> ## 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.

# response.create

请求服务创建响应。普通响应使用模型推理。提供 `response.script` 时，服务会渲染给定的语音和视觉内容，并可选择改写视觉提示词。由会话状态决定哪个角色作出响应。

**`after_current_response`** 只允许一个响应处于等待状态。更长的队列应由应用维护，并按顺序提交。

**`response.input`** 会替换本次响应使用的默认上下文。`[]` 表示不提供上下文。可以直接发送完整的内联对话项；`item_reference` 必须已经存在。

## 事件字段

**event\_id** `string`

客户端为本事件生成的 ID。

**type** `string` *required*

事件类型。必须为 `response.create`。

**response** `object`

本次响应的创建参数。这里设置的字段只对本次响应生效。

**response.conversation** `string`

控制响应写入的位置。使用 `auto` 写入默认对话；使用 `none` 创建不将输出写入默认对话的带外响应。

**response.scheduling\_policy** `string`

控制会话已经忙碌时的处理方式。使用 `interrupt` 取消当前响应或渲染并开始本次响应；使用 `reject_if_busy` 拒绝本事件并返回 `error`；使用 `after_current_response` 在当前响应结束后立即运行本次响应。默认值为 `interrupt`。被打断的响应仍会发出已有的终态生命周期事件，例如先发出 `response.render.stopped`，再发出 `response.done`。

**response.input** `array`

请求模型回答时，需要加入模型上下文的输入项。数组中的每一项可以是 `item_reference` 或原始 `conversation_item`。提供该字段会创建本次响应专用的上下文，而不是使用默认对话；空数组会清除本次响应的上下文。提供 `script` 时不能使用该字段。

#### 变体：`item_reference`

引用会话中已经存在的对话项。

**response.input\[].type** `string` *required*

使用 `item_reference`。

**response.input\[].id** `string` *required*

需要加入响应上下文的已有对话项 ID。

#### 变体：`conversation_item`

原始对话项，使用 `conversation.item.create` 中记录的消息、函数调用和函数调用输出结构。

**response.max\_output\_tokens** `integer | string`

本次响应的最大输出 token 数，包括工具调用。使用整数或 `inf`。提供 `script` 时不能使用该字段。

**response.tools** `array`

本次响应可用的工具。提供时，只在本次响应中覆盖会话的对话工具。提供 `script` 时不能使用该字段。

**`response.tools[]` 中的函数工具**

函数工具包含 `type`、`name`、可选的 `description`，以及可选的 JSON Schema `parameters`。

**response.script** `object`

按照提供的内容直接渲染角色输出。提供时，不会执行 LLM 回答生成或工具调用，并且不能使用 `input`、`tools` 和 `max_output_tokens`。

**response.script.vocal** `object`

当前角色按原样输出的语音内容。`vocal` 和 `visual` 至少提供一个，也可以同时提供。

#### 变体：`speech`

根据准确文本合成语音。

**response.script.vocal.type** `string` *required*

使用 `speech`。

**response.script.vocal.text** `string` *required*

需要说出的准确文本。该文本也会通过 `response.output_text.delta` 和 `response.output_text.done` 流式返回。

#### 变体：`speech_asset`

根据可复用的语音文本资产合成语音。

**response.script.vocal.type** `string` *required*

使用 `speech_asset`。

**response.script.vocal.speech\_text\_asset\_id** `string` *required*

之前在 `assets.speech_text` 中注册的资产。资产文本会作为准确台词，并通过 `response.output_text.delta` 和 `response.output_text.done` 流式返回。

#### 变体：`audio`

使用提供的音频驱动角色。

**response.script.vocal.type** `string` *required*

使用 `audio`。

**response.script.vocal.mime\_type** `string` *required*

提供音频时必填的 MIME 类型。支持 `audio/wav` 和 `audio/mpeg`。`url` 返回的字节或 `audio` 中编码的字节必须与该值匹配。

提供 `script.accompaniment_audio` 时，`url` 应指向已经去除伴奏的独立人声。两条音轨均支持 WAV（`audio/wav`）或 MP3（`audio/mpeg`），包括浮点 WAV。省略该可选字段时，现有 WAV、MP3 和 Base64 音频行为保持不变。

**response.script.vocal.url** `string`

需要通过角色渲染的音频文件 HTTPS URL。Vivix 必须能够在不添加自定义请求头的情况下直接访问。`url` 和 `audio` 必须二选一。

**response.script.vocal.audio** `string`

需要通过角色渲染的 Base64 编码音频文件字节。不要包含 Data URL 前缀。`url` 和 `audio` 必须二选一。

#### 变体：`audio_asset`

使用可复用音频资产驱动角色。

**response.script.vocal.type** `string` *required*

使用 `audio_asset`。

**response.script.vocal.audio\_asset\_id** `string` *required*

之前在 `assets.audio` 中注册的资产。

**response.script.accompaniment\_audio** `object`

可选的伴奏或背景声音轨，在播放时与 `vocal` 混合。只有独立人声音轨会进入音频编码器和 DiT 以驱动嘴部动作；伴奏不会作为角色生成条件。省略该对象时，保留现有单音频脚本行为。

如果原始音频中的背景音乐使人声难以分辨，导致角色口型或时机不准确，可以尝试使用该字段。提供独立人声可以让模型获得更清晰的信号，并在已经对齐的伴奏继续同步播放时改善口型同步。

要求 `vocal.type: "audio"` 且提供 `vocal.url`。两个文件都接受可直接访问的 HTTPS WAV 或 MP3，与普通人声音频相同；WAV 可以使用整数或浮点采样。每个文件最长 300 秒、最大 32 MiB。在 `vocal.url` 中提供独立人声，在此字段中提供已对齐的音乐或背景声音轨。Vivix 不会从混合录音中分离人声。

Vivix 会自动解码两条音轨，并将其统一为 16 kHz 单声道 PCM16；无需预先转换采样格式、采样率或声道。两条音轨必须保留相同的原始时间零点，包括开头静音，并在统一格式后具有相同的采样点数量。不需要时间戳或偏移字段：一个文件的第 0 个采样点与另一个文件的第 0 个采样点对齐。Vivix 不会裁剪静音、循环、拉伸时间或推断偏移量。

提供该对象即可启用成对播放，无需单独的功能开关。它不能与文本语音、内联 Base64 音频或音频素材组合使用。下载、解码或长度检查失败时，成对响应会整体失败，不会只播放人声。

**response.script.accompaniment\_audio.url** `string` *required*

伴奏 WAV 或 MP3 的可直接获取 HTTPS URL。提供 `accompaniment_audio` 时必填。

**response.script.accompaniment\_audio.mime\_type** `string` *required*

WAV 使用 `audio/wav`，MP3 使用 `audio/mpeg`。提供 `accompaniment_audio` 时必填。

**response.script.accompaniment\_audio.gain\_db** `number`

伴奏播放增益，单位为分贝。可选，默认值为 `0`，接受 `-60` 到 `6` 之间的有限数值。它不会改变人声的生成条件。为两条音轨应用固定的共享增益，可以减少播放混音时的削波。

**response.script.visual** `object`

当前角色的动作指令。

**response.script.visual.prompt** `string`

描述角色动作、姿势、视线、手势或展示方式的内联指令。使用 `[SHOT_SEP]` 分隔多个有序动作描述。

**response.script.visual.visual\_prompt\_asset\_id** `string`

之前在 `assets.visual_prompts` 中注册的资产。`prompt` 和 `visual_prompt_asset_id` 必须二选一。

**response.script.visual.duration\_ms** `integer`

每个视觉动作片段的目标时长，单位为毫秒。省略时默认为 `5000`。当 `prompt` 包含 `[SHOT_SEP]` 时，该值分别应用于每个片段，而不是合并后的序列。例如三个片段各为 `5000` 毫秒，计划的动作总时长约为 15 秒。它不会改变所提供音频的时长，也不保证浏览器播放时机完全精确。

**response.script.visual.pe\_enabled** `boolean` (default: false)

设为 `true` 时，Vivix 可以将简短动作提示扩展为适合当前场景的动作提示词。内联提示词和视觉提示资产均支持。如果增强不可用，Vivix 会继续使用原始提示词。示例请参阅[脚本表演](https://docs.vivix.ai/cn/streaming-avatar/interaction/scripted-performances.md#enhance-a-short-movement-instruction)。

**脚本行为。**

| | 行为 |
| - | - |
| **绕过模型** | 默认情况下，`script` 直接渲染提供的语音和视觉内容。可选的视觉改写只作用于视觉提示词。脚本语音文本会按原文渲染，不执行 LLM 回答生成或工具调用。 |
| **角色输出** | 语音输出驱动合成语音或所提供的音频，视觉文本则使用当前角色、音色和源图像，通过 RTC 媒体引导角色动作。 |
| **可选伴奏** | 独立人声驱动嘴部动作；对齐后的伴奏只在播放时混入。两条音轨属于同一个响应，共享调度、取消和完成状态。音频彼此对齐并不保证视觉动作逐拍精确。 |
| **写入对话** | 如果 `conversation` 为 `auto` 或省略，内联语音文本或语音文本资产会作为 `assistant` 消息写入。如果 `conversation` 为 `none`，则不会写入。 |

**响应调度。**

在当前活动响应到达终态 `response.done` 前，会话一直处于忙碌状态。如果已经开始渲染，会先发出 `response.render.stopped`，再发出 `response.done`。

| 策略 | 忙碌时 | 空闲时 |
| - | - | - |
| `interrupt`（默认） | 取消当前输出，清除等待中的任务，然后开始新响应。 | 立即开始。 |
| `reject_if_busy` | 返回 `error`。 | 立即开始。 |
| `after_current_response` | 将一个响应排队，等待当前响应结束。第二个等待请求会返回 `error`。 | 立即开始。 |

排队的响应使用提交时选中的输入、图像、角色行为和资产，之后的更新不会改变它。排队响应开始时会发出 `response.created`。

```json 默认 response.create theme={null}
{
  "event_id": "evt_response_create_001",
  "type": "response.create"
}
```

```json 忙碌时拒绝 theme={null}
{
  "event_id": "evt_response_create_reject_busy_001",
  "type": "response.create",
  "response": {
    "scheduling_policy": "reject_if_busy"
  }
}
```

```json 当前响应结束后执行 theme={null}
{
  "event_id": "evt_response_create_after_current_001",
  "type": "response.create",
  "response": {
    "scheduling_policy": "after_current_response",
    "script": {
      "vocal": {
        "type": "speech",
        "text": "I will cover that next."
      }
    }
  }
}
```

```json 带外响应 theme={null}
{
  "event_id": "evt_response_create_002",
  "type": "response.create",
  "response": {
    "tools": [],
    "conversation": "none",
    "input": [
      {
        "type": "item_reference",
        "id": "item_12345"
      },
      {
        "type": "message",
        "role": "user",
        "content": [
          {
            "type": "input_text",
            "text": "Summarize the product in one sentence."
          }
        ]
      }
    ]
  }
}
```

```json 脚本化语音与视觉资产 theme={null}
{
  "event_id": "evt_response_create_003",
  "type": "response.create",
  "response": {
    "script": {
      "vocal": {
        "type": "speech_asset",
        "speech_text_asset_id": "welcome_line"
      },
      "visual": {
        "visual_prompt_asset_id": "wave_small",
        "duration_ms": 2000
      }
    }
  }
}
```

```json 脚本化音频资产与视觉动作 theme={null}
{
  "event_id": "evt_response_create_004",
  "type": "response.create",
  "response": {
    "script": {
      "vocal": {
        "type": "audio_asset",
        "audio_asset_id": "welcome_jingle"
      },
      "visual": {
        "prompt": "smile and look into the camera",
        "duration_ms": 3000
      }
    }
  }
}
```

```json 独立人声与可选伴奏 theme={null}
{
  "event_id": "evt_paired_song_001",
  "type": "response.create",
  "response": {
    "conversation": "none",
    "script": {
      "vocal": {
        "type": "audio",
        "url": "https://YOUR_DOMAIN/isolated-vocals.wav",
        "mime_type": "audio/wav"
      },
      "accompaniment_audio": {
        "url": "https://YOUR_DOMAIN/accompaniment.wav",
        "mime_type": "audio/wav",
        "gain_db": 0
      }
    }
  }
}
```

```json 增强提示词的纯视觉脚本动作 theme={null}
{
  "event_id": "evt_response_create_005",
  "type": "response.create",
  "response": {
    "script": {
      "visual": {
        "prompt": "look toward the product and nod",
        "duration_ms": 2000,
        "pe_enabled": true
      }
    }
  }
}
```

```json 带外脚本化语音 theme={null}
{
  "event_id": "evt_response_create_006",
  "type": "response.create",
  "response": {
    "conversation": "none",
    "script": {
      "vocal": {
        "type": "speech",
        "text": "This line is rendered but not added to the conversation."
      }
    }
  }
}
```

```json 无效脚本响应（script 与 input 不能同时使用） theme={null}
{
  "event_id": "evt_response_create_007",
  "type": "response.create",
  "response": {
    "input": [],
    "script": {
      "vocal": {
        "type": "speech",
        "text": "Welcome back."
      }
    }
  }
}
```


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