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

# Kling으로 이미지 확장하기

> CometAPI를 통해 Kling Image Expansion API를 사용하여 원본 경계를 넘어 이미지를 확장하고 제어 가능한 아웃페인팅을 수행합니다.

이 엔드포인트를 사용하면 원본 콘텐츠 주변에 더 넓은 캔버스가 필요할 때 이미지의 원래 경계를 넘어 아웃페인팅할 수 있습니다.

## 확장 비율의 작동 방식

* 각 비율은 원본 너비 또는 높이를 기준으로 측정됩니다
* 확장된 전체 캔버스는 여전히 Kling 문서에 명시된 면적 제한 내에 있어야 합니다
* 더 큰 확장을 시도하기 전에 각 면에서 `0.1`과 같은 작은 값으로 시작하세요

## 요청 흐름

* 네 개의 ratio 필드를 모두 전송하고, 확장하지 않으려는 면에는 `0`을 사용하세요
* 반환된 `task_id`를 저장하세요
* 작업이 종료 상태에 도달할 때까지 해당하는 Kling 이미지 조회 경로를 폴링하세요

<Tip>
  전체 파라미터 참조는 [공식 Kling 문서](https://kling.ai/document-api/api/image/common/outpainting)를 참고하세요.
</Tip>


## OpenAPI

````yaml api/openapi/image/kling/post-image-expansion.openapi.json POST /kling/v1/images/editing/expand
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 \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
              "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
            }'
        - lang: Python
          label: Default
          source: |
            import os
            import requests

            response = requests.post(
                "https://api.cometapi.com/kling/v1/images/editing/expand",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={
                "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
            },
            )

            result = response.json()
            print(result["code"], result.get("data", {}).get("task_id"))
        - lang: JavaScript
          label: Default
          source: >
            const response = await
            fetch("https://api.cometapi.com/kling/v1/images/editing/expand", {
              method: "POST",
              headers: {
                Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                "Content-Type": "application/json",
              },
              body: JSON.stringify({
                "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
            }),

            });


            const result = await response.json();

            console.log(result.code, result.data?.task_id);
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````