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

# Kling Expand

> Use DeerAPI to call the Kling Expand endpoint with request details, response details, examples, and an OpenAPI playground.

## Overview

Use this endpoint to call the Kling Expand workflow through DeerAPI. The API reference on this page shows the request schema, response schema, authentication requirements, and runnable examples for the configured endpoint.

## Before you start

Use the DeerAPI base URL and pass your API Key in the `Authorization` header:

```text theme={null}
https://api.deerapi.com
```

```text theme={null}
Authorization: Bearer $DEERAPI_KEY
```

## Model selection

Choose a current model ID from the [live pricing page](https://api.deerapi.com/pricing). Model availability changes over time, so avoid copying a model ID from an old project without checking the live list first.

## Implementation notes

* Use the OpenAPI playground for the exact request fields accepted by this endpoint.
* Keep API Keys on the server side when you build production applications.
* Log the request ID from failed calls so support can investigate the request.
* Retry `429`, `500`, and `503` responses with exponential backoff.


## OpenAPI

````yaml /api/openapi/image/kling/post-expand-img.openapi.json POST /kling/v1/images/editing/expand
openapi: 3.1.0
info:
  title: Image Expansion API
  version: 1.0.0
  description: >-
    Request an outpainting task for a source image. This route may not be
    available on DeerAPI; verify availability before integrating.
servers:
  - url: https://api.deerapi.com
security:
  - bearerAuth: []
paths:
  /kling/v1/images/editing/expand:
    post:
      summary: Request a Kling image-expansion task
      description: >-
        Expand a source image beyond its original borders. Verify route
        availability before integrating.
      operationId: image_expansion
      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
                - up_expansion_ratio
                - right_expansion_ratio
                - left_expansion_ratio
                - bottom_expansion_ratio
              properties:
                image:
                  type: string
                  description: >-
                    Source image to expand. Accepts an image URL or raw Base64
                    string (no `data:` prefix). Supported formats: JPG, JPEG,
                    PNG. Max 10 MB, minimum 300×300 px, aspect ratio between
                    1:2.5 and 2.5:1.
                  default: >-
                    https://cdn.britannica.com/70/234870-050-D4D024BB/Orange-colored-cat-yawns-displaying-teeth.jpg
                up_expansion_ratio:
                  type: number
                  description: >-
                    Upward expansion as a multiple of the original image height.
                    Range: 0–2. The resulting image area must not exceed 3× the
                    original.
                  default: 1
                right_expansion_ratio:
                  type: number
                  description: >-
                    Rightward expansion as a multiple of the original image
                    width. Range: 0–2. The resulting image area must not exceed
                    3× the original.
                  default: 1
                left_expansion_ratio:
                  type: number
                  description: >-
                    Leftward expansion as a multiple of the original image
                    width. Range: 0–2. The resulting image area must not exceed
                    3× the original.
                  default: 1
                prompt:
                  type: string
                  description: >-
                    Optional text prompt to guide the expanded area content. Max
                    2500 characters.
                bottom_expansion_ratio:
                  type: number
                  description: >-
                    Downward expansion as a multiple of the original image
                    height. Range: 0–2. The resulting image area must not exceed
                    3× the original.
                  default: 1
                'n':
                  type: string
                  description: Number of expanded images to generate.
                callback_url:
                  type: string
                  description: >-
                    Webhook URL for task status notifications. The server sends
                    a callback when the task status changes.
                external_task_id:
                  type: string
                  description: >-
                    Optional user-defined task ID for your own tracking. Does
                    not replace the system-generated task ID. Must be unique per
                    account.
              default:
                image: >-
                  https://cdn.britannica.com/70/234870-050-D4D024BB/Orange-colored-cat-yawns-displaying-teeth.jpg
                up_expansion_ratio: 0.1
                right_expansion_ratio: 0.1
                left_expansion_ratio: 0.1
                bottom_expansion_ratio: 0.1
            example:
              image: >-
                https://cdn.britannica.com/70/234870-050-D4D024BB/Orange-colored-cat-yawns-displaying-teeth.jpg
              up_expansion_ratio: 0.1
              right_expansion_ratio: 0.1
              left_expansion_ratio: 0.1
              bottom_expansion_ratio: 0.1
            examples:
              Default:
                summary: Default request
                value:
                  image: >-
                    https://cdn.britannica.com/70/234870-050-D4D024BB/Orange-colored-cat-yawns-displaying-teeth.jpg
                  up_expansion_ratio: 0.1
                  right_expansion_ratio: 0.1
                  left_expansion_ratio: 0.1
                  bottom_expansion_ratio: 0.1
      responses:
        '200':
          description: Task accepted when the route is available.
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - message
                  - 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
                      - 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.
                      created_at:
                        type: integer
                        description: Task creation time, Unix timestamp, in ms.
                      updated_at:
                        type: integer
                        description: Task update time, Unix timestamp, in ms.
        '404':
          description: Route not available.
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type:
                      - integer
                      - 'null'
                  message:
                    type: string
                example:
                  code: null
                  message: '404'
      x-codeSamples:
        - lang: Shell
          label: cURL
          source: |
            curl https://api.deerapi.com/kling/v1/images/editing/expand \
              -H "Content-Type: application/json" \
              -H "Authorization: Bearer $DEERAPI_KEY" \
              -d '{
                "image": "https://cdn.britannica.com/70/234870-050-D4D024BB/Orange-colored-cat-yawns-displaying-teeth.jpg",
                "up_expansion_ratio": 0.1,
                "right_expansion_ratio": 0.1,
                "left_expansion_ratio": 0.1,
                "bottom_expansion_ratio": 0.1
              }'
        - lang: Python
          label: requests
          source: |
            import os
            import requests

            url = "https://api.deerapi.com/kling/v1/images/editing/expand"
            headers = {
                "Authorization": "Bearer " + os.environ["DEERAPI_KEY"],
                "Content-Type": "application/json",
            }
            payload = {
              "image": "https://cdn.britannica.com/70/234870-050-D4D024BB/Orange-colored-cat-yawns-displaying-teeth.jpg",
              "up_expansion_ratio": 0.1,
              "right_expansion_ratio": 0.1,
              "left_expansion_ratio": 0.1,
              "bottom_expansion_ratio": 0.1
            }

            response = requests.post(url, headers=headers, json=payload)
            print(response.json())
        - lang: JavaScript
          label: fetch
          source: >
            const response = await
            fetch("https://api.deerapi.com/kling/v1/images/editing/expand", {
              method: "POST",
              headers: {
                Authorization: `Bearer ${process.env.DEERAPI_KEY}`,
                "Content-Type": "application/json",
              },
              body: JSON.stringify({
                "image": "https://cdn.britannica.com/70/234870-050-D4D024BB/Orange-colored-cat-yawns-displaying-teeth.jpg",
                "up_expansion_ratio": 0.1,
                "right_expansion_ratio": 0.1,
                "left_expansion_ratio": 0.1,
                "bottom_expansion_ratio": 0.1
              }),
            });


            console.log(await response.json());
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Use a DeerAPI API Key as a Bearer token.

````