{
  "openapi": "3.1.0",
  "info": {
    "title": "Kling Image Expansion API",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://api.cometapi.com"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/kling/v1/images/editing/expand": {
      "post": {
        "summary": "Expand an image with Kling",
        "operationId": "kling_image_expansion",
        "parameters": [
          {
            "name": "Content-Type",
            "in": "header",
            "required": false,
            "description": "Must be `application/json`.",
            "schema": {
              "type": "string",
              "default": "application/json"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "image",
                  "up_expansion_ratio",
                  "down_expansion_ratio",
                  "left_expansion_ratio",
                  "right_expansion_ratio"
                ],
                "properties": {
                  "image": {
                    "type": "string",
                    "description": "Source image to expand. Image URL or raw Base64 string without a `data:` prefix. Supported formats: JPG, JPEG, PNG. Maximum 10 MB, minimum 300x300 px, aspect ratio between 1:2.5 and 2.5:1."
                  },
                  "up_expansion_ratio": {
                    "type": "number",
                    "description": "Upward expansion ratio as a multiple of the original image dimension. Range: 0-2. Send `0` for sides you do not want to expand.",
                    "minimum": 0,
                    "maximum": 2
                  },
                  "down_expansion_ratio": {
                    "type": "number",
                    "description": "Downward expansion ratio as a multiple of the original image dimension. Range: 0-2. Send `0` for sides you do not want to expand.",
                    "minimum": 0,
                    "maximum": 2
                  },
                  "left_expansion_ratio": {
                    "type": "number",
                    "description": "Leftward expansion ratio as a multiple of the original image dimension. Range: 0-2. Send `0` for sides you do not want to expand.",
                    "minimum": 0,
                    "maximum": 2
                  },
                  "right_expansion_ratio": {
                    "type": "number",
                    "description": "Rightward expansion ratio as a multiple of the original image dimension. Range: 0-2. Send `0` for sides you do not want to expand.",
                    "minimum": 0,
                    "maximum": 2
                  },
                  "prompt": {
                    "type": "string",
                    "description": "Optional text prompt to guide the expanded area content. Maximum 2500 characters."
                  },
                  "n": {
                    "type": "integer",
                    "description": "Number of expanded images to generate. Range: 1-9.",
                    "minimum": 1,
                    "maximum": 9,
                    "default": 1
                  },
                  "watermark_info": {
                    "type": "object",
                    "description": "Watermark options.",
                    "properties": {
                      "enabled": {
                        "type": "boolean"
                      }
                    }
                  },
                  "callback_url": {
                    "type": "string",
                    "description": "Webhook URL for task status notifications."
                  },
                  "external_task_id": {
                    "type": "string",
                    "description": "Optional user-defined task ID for your own tracking. Must be unique per account."
                  }
                },
                "default": {
                  "image": "https://your-image-host/source.jpg",
                  "up_expansion_ratio": 0.1,
                  "down_expansion_ratio": 0.1,
                  "left_expansion_ratio": 0.1,
                  "right_expansion_ratio": 0.1,
                  "prompt": "extend the soft studio background",
                  "n": 1
                }
              },
              "examples": {
                "Default": {
                  "summary": "Expand an image on all four sides",
                  "value": {
                    "image": "https://your-image-host/source.jpg",
                    "up_expansion_ratio": 0.1,
                    "down_expansion_ratio": 0.1,
                    "left_expansion_ratio": 0.1,
                    "right_expansion_ratio": 0.1,
                    "prompt": "extend the soft studio background",
                    "n": 1
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Task request accepted or an error response returned by the API.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "code",
                    "message",
                    "data"
                  ],
                  "properties": {
                    "code": {
                      "oneOf": [
                        {
                          "type": "integer"
                        },
                        {
                          "type": "string"
                        }
                      ],
                      "description": "Response code. `0` means the task request was accepted."
                    },
                    "message": {
                      "type": "string",
                      "description": "Response message."
                    },
                    "request_id": {
                      "type": "string",
                      "description": "Request identifier returned when present."
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "task_id",
                        "task_status",
                        "created_at",
                        "updated_at"
                      ],
                      "properties": {
                        "task_id": {
                          "type": "string",
                          "description": "System-generated task ID."
                        },
                        "task_status": {
                          "type": "string",
                          "description": "Task status.",
                          "enum": [
                            "submitted",
                            "processing",
                            "succeed",
                            "failed"
                          ]
                        },
                        "task_status_msg": {
                          "oneOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "Task status detail when present."
                        },
                        "task_info": {
                          "type": "object",
                          "properties": {
                            "external_task_id": {
                              "oneOf": [
                                {
                                  "type": "string"
                                },
                                {
                                  "type": "null"
                                }
                              ],
                              "description": "Caller-provided external task ID when supplied."
                            }
                          },
                          "additionalProperties": true
                        },
                        "task_result": {
                          "oneOf": [
                            {
                              "type": "object",
                              "additionalProperties": true
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "description": "Task result payload after the task completes."
                        },
                        "created_at": {
                          "type": "integer",
                          "description": "Task creation time as a Unix timestamp in milliseconds."
                        },
                        "updated_at": {
                          "type": "integer",
                          "description": "Task update time as a Unix timestamp in milliseconds."
                        }
                      },
                      "additionalProperties": true
                    }
                  },
                  "additionalProperties": true
                }
              }
            }
          }
        },
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "Default",
            "source": "curl https://api.cometapi.com/kling/v1/images/editing/expand \\\n  -H \"Authorization: Bearer $COMETAPI_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n  \"image\": \"https://your-image-host/source.jpg\",\n  \"up_expansion_ratio\": 0.1,\n  \"down_expansion_ratio\": 0.1,\n  \"left_expansion_ratio\": 0.1,\n  \"right_expansion_ratio\": 0.1,\n  \"prompt\": \"extend the soft studio background\",\n  \"n\": 1\n}'\n"
          },
          {
            "lang": "Python",
            "label": "Default",
            "source": "import os\nimport requests\n\nresponse = requests.post(\n    \"https://api.cometapi.com/kling/v1/images/editing/expand\",\n    headers={\"Authorization\": \"Bearer \" + os.environ[\"COMETAPI_KEY\"]},\n    json={\n    \"image\": \"https://your-image-host/source.jpg\",\n    \"up_expansion_ratio\": 0.1,\n    \"down_expansion_ratio\": 0.1,\n    \"left_expansion_ratio\": 0.1,\n    \"right_expansion_ratio\": 0.1,\n    \"prompt\": \"extend the soft studio background\",\n    \"n\": 1\n},\n)\n\nresult = response.json()\nprint(result[\"code\"], result.get(\"data\", {}).get(\"task_id\"))\n"
          },
          {
            "lang": "JavaScript",
            "label": "Default",
            "source": "const response = await fetch(\"https://api.cometapi.com/kling/v1/images/editing/expand\", {\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/source.jpg\",\n    \"up_expansion_ratio\": 0.1,\n    \"down_expansion_ratio\": 0.1,\n    \"left_expansion_ratio\": 0.1,\n    \"right_expansion_ratio\": 0.1,\n    \"prompt\": \"extend the soft studio background\",\n    \"n\": 1\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."
      }
    }
  }
}
