{
  "openapi": "3.1.0",
  "info": {
    "title": "Video Extension API",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://api.cometapi.com"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/kling/v1/videos/video-extend": {
      "post": {
        "summary": "Video Extension",
        "operationId": "video_extension",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "video_id",
                  "task_id"
                ],
                "properties": {
                  "task_id": {
                    "type": "string",
                    "description": "Parent Kling task id for the extension-compatible video being extended."
                  },
                  "video_id": {
                    "type": "string",
                    "description": "Video id from a parent task result. The source video must be extension-compatible; unsupported videos return HTTP 400."
                  },
                  "prompt": {
                    "type": "string",
                    "description": "Text prompt describing the desired motion for the extended segment. Maximum 500 characters."
                  },
                  "callback_url": {
                    "type": "string",
                    "description": "Webhook URL to receive task status updates when the task completes."
                  },
                  "negative_prompt": {
                    "type": "string",
                    "description": "Elements to avoid in the extension."
                  },
                  "cfg_scale": {
                    "type": "number",
                    "description": "Prompt adherence strength for the extension. Range: 0-1."
                  }
                },
                "default": {
                  "task_id": "<parent_task_id>",
                  "video_id": "<video_id>",
                  "prompt": "Continue with the same calm morning atmosphere",
                  "cfg_scale": 0.5
                }
              },
              "examples": {
                "Default": {
                  "summary": "Video extension request with an extension-compatible parent task",
                  "value": {
                    "task_id": "<parent_task_id>",
                    "video_id": "<video_id>",
                    "prompt": "Continue with the same calm morning atmosphere",
                    "cfg_scale": 0.5
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "code",
                    "message",
                    "request_id",
                    "data"
                  ],
                  "properties": {
                    "code": {
                      "type": "integer",
                      "description": "Error code; specifically define the error code"
                    },
                    "message": {
                      "type": "string",
                      "description": "error message"
                    },
                    "request_id": {
                      "type": "string",
                      "description": "Request ID, system-generated, for tracking requests, troubleshooting issues"
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "task_id",
                        "task_status",
                        "task_status_msg",
                        "task_info",
                        "task_result",
                        "created_at",
                        "updated_at"
                      ],
                      "properties": {
                        "task_id": {
                          "type": "string",
                          "description": "Task ID, system generated"
                        },
                        "task_status": {
                          "type": "string",
                          "description": "Task status, enumerated values: submitted, processing, succeed, failed."
                        },
                        "task_status_msg": {
                          "type": "string"
                        },
                        "task_info": {
                          "type": "object",
                          "required": [
                            "parent_video"
                          ],
                          "properties": {
                            "parent_video": {
                              "type": "object",
                              "required": [
                                "id",
                                "url",
                                "duration"
                              ],
                              "properties": {
                                "id": {
                                  "type": "string"
                                },
                                "url": {
                                  "type": "string"
                                },
                                "duration": {
                                  "type": "string"
                                }
                              }
                            }
                          }
                        },
                        "task_result": {
                          "type": "object",
                          "required": [
                            "videos"
                          ],
                          "properties": {
                            "videos": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "id": {
                                    "type": "string"
                                  },
                                  "url": {
                                    "type": "string"
                                  },
                                  "duration": {
                                    "type": "string"
                                  }
                                }
                              }
                            }
                          }
                        },
                        "created_at": {
                          "type": "integer",
                          "description": "Task creation time, Unix timestamp, in ms."
                        },
                        "updated_at": {
                          "type": "integer",
                          "description": "Task update time, Unix timestamp, in ms."
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "description": "Only videos from supported generation types can be extended.",
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "Default",
            "source": "curl https://api.cometapi.com/kling/v1/videos/video-extend \\\n  -H \"Authorization: Bearer $COMETAPI_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n      \"task_id\": \"<parent_task_id>\",\n      \"video_id\": \"<video_id>\",\n      \"prompt\": \"Continue with the same calm morning atmosphere\",\n      \"cfg_scale\": 0.5\n    }'\n"
          },
          {
            "lang": "Python",
            "label": "Default",
            "source": "import os\nimport requests\n\nresponse = requests.post(\n    \"https://api.cometapi.com/kling/v1/videos/video-extend\",\n    headers={\"Authorization\": \"Bearer \" + os.environ[\"COMETAPI_KEY\"]},\n    json={\n      \"task_id\": \"<parent_task_id>\",\n      \"video_id\": \"<video_id>\",\n      \"prompt\": \"Continue with the same calm morning atmosphere\",\n      \"cfg_scale\": 0.5\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/video-extend\", {\n  method: \"POST\",\n  headers: {\n    Authorization: `Bearer ${process.env.COMETAPI_KEY}`,\n    \"Content-Type\": \"application/json\",\n  },\n  body: JSON.stringify({\n    \"task_id\": \"<parent_task_id>\",\n    \"video_id\": \"<video_id>\",\n    \"prompt\": \"Continue with the same calm morning atmosphere\",\n    \"cfg_scale\": 0.5\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."
      }
    }
  }
}
