{
  "openapi": "3.1.0",
  "info": {
    "title": "Counterpart Creating Tasks API",
    "version": "1.0.0",
    "description": "Create an advanced Kling lip-sync task after face identification has produced a session id and face ids."
  },
  "servers": [
    {
      "url": "https://api.cometapi.com"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/kling/v1/videos/advanced-lip-sync": {
      "post": {
        "summary": "Create an advanced Kling lip-sync task",
        "operationId": "counterpart_creating_tasks",
        "description": "Submit the `session_id` returned by face identification plus one or more `face_choose` mappings that connect target faces to audio segments.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "session_id",
                  "face_choose"
                ],
                "properties": {
                  "session_id": {
                    "type": "string",
                    "description": "Session id returned by identify-face."
                  },
                  "face_choose": {
                    "type": "array",
                    "description": "One or more face/audio mappings to synthesize.",
                    "minItems": 1,
                    "items": {
                      "type": "object",
                      "required": [
                        "face_id"
                      ],
                      "properties": {
                        "face_id": {
                          "type": "string",
                          "description": "Face id returned by identify-face."
                        },
                        "audio_id": {
                          "type": "string",
                          "description": "Audio id from a prior audio task."
                        },
                        "sound_file": {
                          "type": "string",
                          "description": "Public audio URL when you provide your own audio."
                        },
                        "sound_start_time": {
                          "type": "string",
                          "description": "Start time within the audio source, in milliseconds."
                        },
                        "sound_end_time": {
                          "type": "string",
                          "description": "End time within the audio source, in milliseconds. The clipped segment must be at least 2000 ms and must not exceed the source audio duration."
                        },
                        "sound_insert_time": {
                          "type": "string",
                          "description": "Insertion time in the target video, in milliseconds."
                        },
                        "sound_volume": {
                          "type": "number",
                          "description": "Volume for the inserted audio."
                        },
                        "original_sound_volume": {
                          "type": "number",
                          "description": "Volume for the original video audio."
                        }
                      }
                    }
                  },
                  "callback_url": {
                    "type": "string",
                    "description": "Webhook URL to receive task status updates."
                  },
                  "external_task_id": {
                    "type": "string",
                    "description": "Custom task id for your own tracking. Must be unique per account."
                  }
                },
                "default": {
                  "session_id": "<session_id>",
                  "face_choose": [
                    {
                      "face_id": "<face_id>",
                      "sound_file": "https://your-audio-host/speech.wav",
                      "sound_start_time": "0",
                      "sound_end_time": "2000",
                      "sound_insert_time": "0",
                      "sound_volume": 1,
                      "original_sound_volume": 0
                    }
                  ]
                }
              },
              "examples": {
                "Default": {
                  "summary": "Advanced lip-sync request",
                  "value": {
                    "session_id": "<session_id>",
                    "face_choose": [
                      {
                        "face_id": "<face_id>",
                        "sound_file": "https://your-audio-host/speech.wav",
                        "sound_start_time": "0",
                        "sound_end_time": "2000",
                        "sound_insert_time": "0",
                        "sound_volume": 1,
                        "original_sound_volume": 0
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "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",
                      "properties": {
                        "task_id": {
                          "type": "string"
                        },
                        "task_status": {
                          "type": "string"
                        },
                        "created_at": {
                          "type": "integer"
                        },
                        "updated_at": {
                          "type": "integer"
                        }
                      },
                      "additionalProperties": true
                    }
                  }
                }
              }
            }
          }
        },
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "Default",
            "source": "curl https://api.cometapi.com/kling/v1/videos/advanced-lip-sync \\\n  -H \"Authorization: Bearer $COMETAPI_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n      \"session_id\": \"<session_id>\",\n      \"face_choose\": [\n        {\n          \"face_id\": \"<face_id>\",\n          \"sound_file\": \"https://your-audio-host/speech.wav\",\n          \"sound_start_time\": \"0\",\n          \"sound_end_time\": \"2000\",\n          \"sound_insert_time\": \"0\",\n          \"sound_volume\": 1,\n          \"original_sound_volume\": 0\n        }\n      ]\n    }'\n"
          },
          {
            "lang": "Python",
            "label": "Default",
            "source": "import os\nimport requests\n\nresponse = requests.post(\n    \"https://api.cometapi.com/kling/v1/videos/advanced-lip-sync\",\n    headers={\"Authorization\": \"Bearer \" + os.environ[\"COMETAPI_KEY\"]},\n    json={\n      \"session_id\": \"<session_id>\",\n      \"face_choose\": [\n        {\n          \"face_id\": \"<face_id>\",\n          \"sound_file\": \"https://your-audio-host/speech.wav\",\n          \"sound_start_time\": \"0\",\n          \"sound_end_time\": \"2000\",\n          \"sound_insert_time\": \"0\",\n          \"sound_volume\": 1,\n          \"original_sound_volume\": 0\n        }\n      ]\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/advanced-lip-sync\", {\n  method: \"POST\",\n  headers: {\n    Authorization: `Bearer ${process.env.COMETAPI_KEY}`,\n    \"Content-Type\": \"application/json\",\n  },\n  body: JSON.stringify({\n    \"session_id\": \"<session_id>\",\n    \"face_choose\": [\n      {\n        \"face_id\": \"<face_id>\",\n        \"sound_file\": \"https://your-audio-host/speech.wav\",\n        \"sound_start_time\": \"0\",\n        \"sound_end_time\": \"2000\",\n        \"sound_insert_time\": \"0\",\n        \"sound_volume\": 1,\n        \"original_sound_volume\": 0\n      }\n    ]\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."
      }
    }
  }
}
