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

# Kling 数字人

> 合成语音、创建 Kling 数字人视频并查询结果。

需要将文本转换为语音时，先调用 TTS，再把返回的 `audio_id` 传给数字人生成接口。如果已有音频文件，可通过 `sound_file` 直接提交并跳过 TTS。

<Tabs sync={false}>
  <Tab title="Avatar">
    ## 创建任务

    `POST /kling/v1/videos/avatar/image2video`

    <div className="kling-api-example-panel">
      ```bash cURL theme={null}
      curl --request POST \
        --url https://www.anyfast.ai/kling/v1/videos/avatar/image2video \
        --header 'Authorization: Bearer YOUR_API_KEY' \
        --header 'Content-Type: application/json' \
        --data '{
          "image": "https://example.com/portrait.png",
          "audio_id": "932365483050274872",
          "prompt": "人物自然看向镜头说话，神态友好，轻微点头。",
          "mode": "std",
          "watermark_info": {"enabled": true}
        }'
      ```
    </div>

    ## 请求头

    <ParamField header="Authorization" type="string" required>Bearer 鉴权，格式为 `Bearer YOUR_API_KEY`。</ParamField>
    <ParamField header="Content-Type" type="string" default="application/json" required>数据交换格式。</ParamField>

    ## 请求体

    <ParamField body="image" type="string" required>图片公网 URL 或纯 Base64。支持 JPG、JPEG、PNG，不超过 10 MB；宽高均不小于 300 px，比例介于 1:2.5～2.5:1。Base64 不要包含 data URI 前缀。</ParamField>
    <ParamField body="audio_id" type="string">30 天内生成的音频 ID，音频时长 2～300 秒。与 `sound_file` 必须二选一。</ParamField>
    <ParamField body="sound_file" type="string">音频公网 URL 或纯 Base64。支持 MP3、WAV、M4A、AAC，不超过 5 MB，时长 2～300 秒。与 `audio_id` 必须二选一。</ParamField>
    <ParamField body="prompt" type="string">动作、情绪和运镜提示词，最长 2,500 个字符。</ParamField>
    <ParamField body="mode" type="string" default="std">生成模式：`std` 或 `pro`。</ParamField>
    <ParamField body="watermark_info" type="object">水印配置。</ParamField>
    <ParamField body="watermark_info.enabled" type="boolean">是否生成含水印结果。</ParamField>
    <ParamField body="callback_url" type="string">任务状态通知的公网回调地址。</ParamField>

    ## 创建响应

    <div className="kling-api-example-panel">
      ```json 200 theme={null}
      {
        "id": "asyntask_6prd3xHk76S1sTivIgGjQzrA4ziDrRCX",
        "task_id": "asyntask_6prd3xHk76S1sTivIgGjQzrA4ziDrRCX",
        "object": "video",
        "model": "kling-v1",
        "status": "queued",
        "progress": 0,
        "created_at": 1790319846
      }
      ```
    </div>

    <ResponseField name="id" type="string">AnyFast 任务 ID。</ResponseField>
    <ResponseField name="task_id" type="string">AnyFast 任务 ID，与 `id` 相同。</ResponseField>
    <ResponseField name="object" type="string">返回对象类型，本接口为 `video`。</ResponseField>
    <ResponseField name="model" type="string">接口返回的底层请求模型标识。</ResponseField>
    <ResponseField name="status" type="string">AnyFast 初始状态；任务受理后为 `queued`。</ResponseField>
    <ResponseField name="progress" type="integer">初始进度百分比。</ResponseField>
    <ResponseField name="created_at" type="integer">创建时间，Unix 秒时间戳。</ResponseField>

    ## 查询任务

    `GET /kling/v1/videos/avatar/image2video/{task_id}`

    <div className="kling-api-example-panel">
      ```bash cURL theme={null}
      curl --request GET \
        --url https://www.anyfast.ai/kling/v1/videos/avatar/image2video/asyntask_6prd3xHk76S1sTivIgGjQzrA4ziDrRCX \
        --header 'Authorization: Bearer YOUR_API_KEY'
      ```
    </div>

    ## 请求头和路径

    <ParamField header="Authorization" type="string" required>Bearer 鉴权，格式为 `Bearer YOUR_API_KEY`。</ParamField>
    <ParamField path="task_id" type="string" required>创建数字人时返回的 AnyFast 任务 ID。</ParamField>

    ## 响应

    <div className="kling-api-example-panel">
      ```json 200 theme={null}
      {
        "code": 0,
        "message": "",
        "data": {
          "task_id": "asyntask_6prd3xHk76S1sTivIgGjQzrA4ziDrRCX",
          "task_status": "succeed",
          "task_result": {
            "videos": [
              {
                "url": "https://example.com/digital-human.mp4",
                "duration": "5"
              }
            ]
          },
          "created_at": 1790319846000,
          "updated_at": 1790320090000
        }
      }
      ```
    </div>

    <ResponseField name="code" type="integer">业务结果码，`0` 表示成功。</ResponseField>
    <ResponseField name="message" type="string">业务信息，成功时可能为空。</ResponseField>
    <ResponseField name="data.task_id" type="string">AnyFast 任务 ID。</ResponseField>
    <ResponseField name="data.task_status" type="string">任务状态：`submitted`、`processing`、`succeed` 或 `failed`。中间状态可能重复出现，也可能在 `submitted` 与 `processing` 之间切换；只有 `succeed` 和 `failed` 是终态。</ResponseField>
    <ResponseField name="data.task_status_msg" type="string">任务失败时的错误信息。</ResponseField>
    <ResponseField name="data.task_result.videos" type="object[]">任务成功后返回的视频结果。</ResponseField>
    <ResponseField name="data.task_result.videos[].url" type="string">生成视频 URL。</ResponseField>
    <ResponseField name="data.task_result.videos[].duration" type="string">接口返回的视频时长，单位为秒。</ResponseField>
    <ResponseField name="data.created_at" type="integer">创建时间，Unix 毫秒时间戳。</ResponseField>
    <ResponseField name="data.updated_at" type="integer">更新时间，Unix 毫秒时间戳。</ResponseField>
  </Tab>

  <Tab title="TTS">
    ## 生成语音

    `POST /kling/v1/audio/tts`

    <div className="kling-api-example-panel">
      ```bash cURL theme={null}
      curl --request POST \
        --url https://www.anyfast.ai/kling/v1/audio/tts \
        --header 'Authorization: Bearer YOUR_API_KEY' \
        --header 'Content-Type: application/json' \
        --data '{
          "text": "你好，欢迎使用 AnyFast 数字人服务。",
          "voice_id": "oversea_male1",
          "voice_language": "zh",
          "voice_speed": 1.0
        }'
      ```
    </div>

    ## 请求头

    <ParamField header="Authorization" type="string" required>Bearer 鉴权，格式为 `Bearer YOUR_API_KEY`。</ParamField>
    <ParamField header="Content-Type" type="string" default="application/json" required>数据交换格式。</ParamField>

    ## 请求体

    <ParamField body="text" type="string" required>需要合成的文本，最长 1,000 个字符。</ParamField>
    <ParamField body="voice_id" type="string" required>从 [Kling AI Voice List](https://docs.qingque.cn/s/home/eZQDvafJ4vXQkP8T9ZPvmye8S?identityId=2E1MlYrrPk4) 选择音色 ID；表中语言必须与 `voice_language` 一致。</ParamField>
    <ParamField body="voice_language" type="string" default="zh" required>音色语种，支持 `zh`、`en`。</ParamField>
    <ParamField body="voice_speed" type="number" default={1.0}>语速范围 `0.8`～`2.0`，超出一位小数的部分会四舍五入。</ParamField>

    ## 响应

    <div className="kling-api-example-panel">
      ```json 200 theme={null}
      {
        "code": 0,
        "message": "SUCCEED",
        "request_id": "request_01J8K7E7H4T7FQ6V6K6A",
        "data": {
          "task_id": "tts_task_01J8K7E7H4",
          "task_status": "succeed",
          "task_result": {
            "audios": [
              {
                "id": "932365483050274872",
                "url": "https://example.com/generated-speech.mp3",
                "duration": "4.067"
              }
            ]
          },
          "created_at": 1790321772436,
          "updated_at": 1790321774387,
          "final_unit_deduction": "0.05",
          "final_balance_deduction": {
            "quota": "0",
            "list_price": "0"
          }
        }
      }
      ```
    </div>

    <ResponseField name="code" type="integer">业务结果码，`0` 表示成功。</ResponseField>
    <ResponseField name="message" type="string">业务结果信息。</ResponseField>
    <ResponseField name="request_id" type="string">用于排查问题的请求 ID。</ResponseField>
    <ResponseField name="data.task_id" type="string">TTS 任务 ID。</ResponseField>
    <ResponseField name="data.task_status" type="string">TTS 状态；同步成功时返回 `succeed`。</ResponseField>
    <ResponseField name="data.task_result.audios" type="object[]">生成的音频结果。</ResponseField>
    <ResponseField name="data.task_result.audios[].id" type="string">数字人和对口型接口可使用的音频 ID。</ResponseField>
    <ResponseField name="data.task_result.audios[].url" type="string">生成音频的 URL。</ResponseField>
    <ResponseField name="data.task_result.audios[].duration" type="string">音频时长，单位为秒。</ResponseField>
    <ResponseField name="data.final_unit_deduction" type="string">Kling 最终扣减 Unit。</ResponseField>
    <ResponseField name="data.final_balance_deduction" type="object">供应商返回的余额扣减信息。</ResponseField>
    <ResponseField name="data.created_at" type="integer">创建时间，Unix 毫秒时间戳。</ResponseField>
    <ResponseField name="data.updated_at" type="integer">更新时间，Unix 毫秒时间戳。</ResponseField>
  </Tab>
</Tabs>

<script src="/public/feedback.js" />
