{
  "openapi": "3.1.0",
  "info": {
    "title": "Avatar API",
    "version": "1.0.0",
    "description": "Create a Kling avatar video task from one source image plus one audio source."
  },
  "servers": [
    {
      "url": "https://api.cometapi.com"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/kling/v1/videos/avatar/image2video": {
      "post": {
        "summary": "Create a Kling avatar task",
        "operationId": "avatar",
        "description": "Submit one avatar image and exactly one audio source. Poll the returned task id through the generic Kling query route.",
        "parameters": [
          {
            "name": "Content-Type",
            "in": "header",
            "required": false,
            "description": "Optional content type header.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "image",
                  "prompt"
                ],
                "oneOf": [
                  {
                    "required": [
                      "audio_id"
                    ]
                  },
                  {
                    "required": [
                      "sound_file"
                    ]
                  }
                ],
                "properties": {
                  "image": {
                    "type": "string",
                    "description": "Avatar image URL or base64 image string. Use an image that meets Kling pixel requirements; very small thumbnails are rejected."
                  },
                  "prompt": {
                    "type": "string",
                    "description": "Prompt describing the desired avatar performance."
                  },
                  "audio_id": {
                    "type": "string",
                    "description": "Audio id from a prior Kling audio task."
                  },
                  "sound_file": {
                    "type": "string",
                    "description": "Public audio URL when you provide your own audio."
                  },
                  "task_id": {
                    "type": "string",
                    "description": "Optional prior task id associated with the referenced audio asset."
                  },
                  "mode": {
                    "type": "string",
                    "description": "Generation mode. Use `std` or `pro`; omitted requests use `std`.",
                    "enum": [
                      "std",
                      "pro"
                    ]
                  }
                },
                "default": {
                  "image": "https://your-image-host/avatar.jpg",
                  "prompt": "The speaker talks naturally to camera",
                  "sound_file": "https://your-audio-host/speech.wav",
                  "mode": "std"
                }
              },
              "examples": {
                "Default": {
                  "summary": "Avatar image-to-video request",
                  "value": {
                    "image": "https://your-image-host/avatar.jpg",
                    "prompt": "The speaker talks naturally to camera",
                    "sound_file": "https://your-audio-host/speech.wav",
                    "mode": "std"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Task accepted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "code",
                    "message",
                    "data"
                  ],
                  "properties": {
                    "code": {
                      "type": "integer"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "task_id",
                        "task_status",
                        "created_at",
                        "updated_at"
                      ],
                      "properties": {
                        "task_id": {
                          "type": "string"
                        },
                        "task_status": {
                          "type": "string"
                        },
                        "task_info": {
                          "type": "object",
                          "additionalProperties": true
                        },
                        "created_at": {
                          "type": "integer"
                        },
                        "updated_at": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "Default",
            "source": "curl https://api.cometapi.com/kling/v1/videos/avatar/image2video \\\n  -H \"Authorization: Bearer $COMETAPI_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n      \"image\": \"https://your-image-host/avatar.jpg\",\n      \"prompt\": \"The speaker talks naturally to camera\",\n      \"sound_file\": \"https://your-audio-host/speech.wav\",\n      \"mode\": \"std\"\n    }'\n"
          },
          {
            "lang": "Python",
            "label": "Default",
            "source": "import os\nimport requests\n\nresponse = requests.post(\n    \"https://api.cometapi.com/kling/v1/videos/avatar/image2video\",\n    headers={\"Authorization\": \"Bearer \" + os.environ[\"COMETAPI_KEY\"]},\n    json={\n      \"image\": \"https://your-image-host/avatar.jpg\",\n      \"prompt\": \"The speaker talks naturally to camera\",\n      \"sound_file\": \"https://your-audio-host/speech.wav\",\n      \"mode\": \"std\"\n    },\n)\n\nresult = response.json()\nprint(result.get(\"code\"), result.get(\"data\", {}).get(\"task_id\"))\n"
          },
          {
            "lang": "JavaScript",
            "label": "Default",
            "source": "const response = await fetch(\"https://api.cometapi.com/kling/v1/videos/avatar/image2video\", {\n  method: \"POST\",\n  headers: {\n    Authorization: `Bearer ${process.env.COMETAPI_KEY}`,\n    \"Content-Type\": \"application/json\",\n  },\n  body: JSON.stringify({\n    \"image\": \"https://your-image-host/avatar.jpg\",\n    \"prompt\": \"The speaker talks naturally to camera\",\n    \"sound_file\": \"https://your-audio-host/speech.wav\",\n    \"mode\": \"std\"\n  }),\n});\n\nconst result = await response.json();\nconsole.log(result.code, result.data?.task_id);\n"
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Bearer token authentication. Use your CometAPI key."
      }
    }
  }
}
