> ## 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 Generate

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

## Overview

Use this endpoint to call the Kling Generate 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-image-gen.openapi.json POST /kling/v1/images/generations
openapi: 3.1.0
info:
  title: Image Generation API
  version: 1.0.0
servers:
  - url: https://api.deerapi.com
security:
  - bearerAuth: []
paths:
  /kling/v1/images/generations:
    post:
      summary: Image Generation
      operationId: image_generation
      parameters:
        - name: Content-Type
          in: header
          required: false
          description: Must be `application/json`.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - prompt
              properties:
                prompt:
                  type: string
                  description: >-
                    Text prompt describing the image to generate. Maximum 500
                    characters.
                  default: Hello
                negative_prompt:
                  type: string
                  description: Elements to exclude from the image. Maximum 200 characters.
                image:
                  type: string
                  description: >-
                    Reference image as a Base64 string (without `data:` prefix)
                    or public URL. Accepted formats: JPG, JPEG, PNG. Maximum 10
                    MB, minimum 300×300 px.
                image_fidelity:
                  type: number
                  description: >-
                    How closely the output follows the reference image. Range:
                    0–1.
                'n':
                  type: integer
                  description: 'Number of images to generate. Range: 1–9.'
                aspect_ratio:
                  type: string
                  description: >-
                    Output aspect ratio (width:height). Options: `16:9`, `9:16`,
                    `1:1`, `4:3`, `3:4`, `3:2`, `2:3`.
                callback_url:
                  type: string
                  description: >-
                    Webhook URL to receive task status updates when the task
                    completes.
                model_name:
                  type: string
                  description: >-
                    Kling image model variant to use. See the [Models
                    page](https://api.deerapi.com/pricing) for current options.
              default:
                prompt: A paper boat floating on calm water at sunrise.
            examples:
              Default:
                summary: Default
                value:
                  prompt: cry
                  model_name: kling-v2
                  image: >-
                    https://p2-kling.klingai.com/kcdn/cdn-kcdn112452/kling-op/effects_raw_pic/magic_fireball-raw.png
              Example 2:
                summary: Example 2
                value:
                  prompt: A happy scene of a vacation on the beach.
                  model_name: kling-v2
                  image: >-
                    iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAMAAABF0y+mAAABFFBMVEUAAAABFBYFZWoHeoMHd4MFXmsBFhoAeGUC1MYI+fsP+P8P8f8N5v8K1/8Hq9wDXHwAUDEA6KQA/80E990J9e4R9/8K1vkHyPYEsfgBk9sAKy0AkUsA/5YA/aQA+rkG+NEN+egFgvoAP/0AMf8ARv8AGFsBn0YG/3wA/YQF/aoQ/MQInv8AUP8BW/8CYf8AdS8Y+m0g/5wo/rMd5OcCTqMAEEIBJEoDadEAGC8AEwcR/WIs92FU+2xT/XpP/o1U/6ctwqMAABEFhc4Fn/YBFyQlpT5l/1+G+F6Z+2SW/4BUuG8COEcIwvpmpzzP/17c+VyIz3EGmqqkqTz//1nS+oIAACEZrpkATUkAwrbg+nSWzmECZ//nXTRpAAABDklEQVR4AbXQA0+wYRjF8XO9RjaGPGU3Ztv4mtnmEKZsDtk4PUZrXv/pbL+HN74mcW6tp8/wtwK6X35EH1G6+38n/0TpyIXhonYq+B4gApF1B8aJ3HjKqedZpCgGyrKNSYJ7+Ss7Ci0gU86A4FkTc8wvkRGo5Qtk0EQUicbd0KuQ8SvYVVXX1NTCyqMOzuobGptg9TcMbm22d0sr3LW22Lu53m1hAfZuamtwa52HvdtraqqrnMcXjPQu6JWTIDlgYSHBYajlkdR1xsTsUyCI88gg73ntwb/gEkxEx0oCsMKg6X8e/K8o12BjLN9EXm+v8Z+KkIdwIMKodEfyP5Uu4ELA2/qUR8BEu1/U/at7B7OBbYeTZaCnAAAAAElFTkSuQmCC
            example:
              prompt: cry
              model_name: kling-v2
              image: >-
                https://p2-kling.klingai.com/kcdn/cdn-kcdn112452/kling-op/effects_raw_pic/magic_fireball-raw.png
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - data
                  - message
                properties:
                  code:
                    type: integer
                    description: Error code; specifically define the error code
                  data:
                    type: object
                    required:
                      - created_at
                      - task_id
                      - task_info
                      - task_result
                      - task_status
                      - task_status_msg
                      - updated_at
                    properties:
                      created_at:
                        type: integer
                        description: Task creation time, Unix timestamp, in ms.
                      task_id:
                        type: string
                        description: Task ID, system generated
                      task_info:
                        type: object
                        required:
                          - external_task_id
                        properties:
                          external_task_id:
                            type: 'null'
                      task_result:
                        type: 'null'
                      task_status:
                        type: string
                        description: >-
                          Task status, enumerated values: submitted, processing,
                          succeed, failed.
                      task_status_msg:
                        type: 'null'
                      updated_at:
                        type: integer
                        description: Task update time, Unix timestamp, in ms.
                  message:
                    type: string
                    description: error message
      x-codeSamples:
        - lang: Shell
          label: cURL
          source: |
            curl https://api.deerapi.com/kling/v1/images/generations \
              -H "Content-Type: application/json" \
              -H "Authorization: Bearer $DEERAPI_KEY" \
              -d '{
                "prompt": "cry",
                "model_name": "kling-v2",
                "image": "https://p2-kling.klingai.com/kcdn/cdn-kcdn112452/kling-op/effects_raw_pic/magic_fireball-raw.png"
              }'
        - lang: Python
          label: requests
          source: |
            import os
            import requests

            url = "https://api.deerapi.com/kling/v1/images/generations"
            headers = {
                "Authorization": "Bearer " + os.environ["DEERAPI_KEY"],
                "Content-Type": "application/json",
            }
            payload = {
              "prompt": "cry",
              "model_name": "kling-v2",
              "image": "https://p2-kling.klingai.com/kcdn/cdn-kcdn112452/kling-op/effects_raw_pic/magic_fireball-raw.png"
            }

            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/generations", {
              method: "POST",
              headers: {
                Authorization: `Bearer ${process.env.DEERAPI_KEY}`,
                "Content-Type": "application/json",
              },
              body: JSON.stringify({
                "prompt": "cry",
                "model_name": "kling-v2",
                "image": "https://p2-kling.klingai.com/kcdn/cdn-kcdn112452/kling-op/effects_raw_pic/magic_fireball-raw.png"
              }),
            });


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

````