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

# Kling Image Generation kling-4.0

> Submit a Kling 4.0 text-to-image or image-to-image task via `/kling/image-generation`. The single-image mode can generate multiple independent images via `n`. Note: The platform does not yet integrate elements (`element`) or voices (`voice`); the related parameters are not supported yet.



## OpenAPI

````yaml api-reference/en/zmodelImage/kling/kling-4.0-image-generations.json POST /kling/image-generation
openapi: 3.0.1
info:
  title: Kling 4.0 Image Generation Task - Submit Task
  version: 1.0.0
  description: >-
    Submit a Kling 4.0 text-to-image or image-to-image task via
    `/kling/image-generation`. Note: The platform does not yet integrate
    elements (`element`) or voices (`voice`); the related parameters are not
    supported yet.
servers:
  - url: https://api.powertokens.ai
    description: ''
security: []
tags:
  - name: Kling
    description: Kling native async task endpoints
paths:
  /kling/image-generation:
    post:
      tags:
        - Kling
      summary: Kling 4.0 Image Generation Task
      description: >-
        Submit a Kling 4.0 text-to-image or image-to-image task via
        `/kling/image-generation`. The single-image mode can generate multiple
        independent images via `n`. Note: The platform does not yet integrate
        elements (`element`) or voices (`voice`); the related parameters are not
        supported yet.
      operationId: createKlingImageGeneration4
      parameters:
        - name: Content-Type
          in: header
          required: true
          schema:
            type: string
            default: application/json
          description: Data exchange format
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Kling4Request'
            examples:
              text_to_image:
                summary: Text to single image
                value:
                  model_name: kling-4.0
                  contents:
                    - type: prompt
                      text: >-
                        Generate a 3D animation style character poster, warm
                        lighting, simple background.
                  settings:
                    result_type: single
                    'n': 1
                    resolution: 2k
                    aspect_ratio: '1:1'
              image_to_image:
                summary: Image to single image
                value:
                  model_name: kling-4.0
                  contents:
                    - type: prompt
                      text: >-
                        Using the puppy in @dog as the main character, generate
                        a 3D animation style story image of the puppy sitting by
                        the cafe window. Keep the puppy's coat color,
                        appearance, and visual style consistent.
                    - type: refer_image
                      url: >-
                        https://p1-kling.klingai.com/kcdn/cdn-kcdn112452/kling-qa-test/dog.png
                      id: dog
                  settings:
                    result_type: single
                    'n': 1
                    resolution: 2k
                    aspect_ratio: '3:4'
                  options:
                    watermark_info:
                      enabled: false
      responses:
        '200':
          description: Task accepted.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SubmitResponse'
              examples:
                response:
                  summary: Response example
                  value:
                    code: 0
                    message: SUCCEED
                    request_id: example-request-id
                    data:
                      id: example-task-id
                      status: submitted
                      create_time: 1790000000000
                      update_time: 1790000000000
                      external_id: string
      security:
        - bearerAuth: []
components:
  schemas:
    Kling4Request:
      type: object
      required:
        - model_name
        - contents
      properties:
        model_name:
          type: string
          enum:
            - kling-4.0
          description: Model name
          example: kling-4.0
        contents:
          type: array
          description: >-
            Materials for generation, such as prompts, images, and elements.


            The reference format is as follows. See the parameter descriptions
            below:


            ```json

            "contents": [
              {
                "type": "prompt",
                "text": "string"
              },
              {
                "type": "refer_image",
                "url": "string",
                "id": "string"
              },
              {
                "type": "element",
                "element_id": "string",
                "id": "string"
              }
            ]

            ```


            - The order of prompts, reference images, and elements is the
            analysis order


            Note: Elements (`element`) are not yet integrated and cannot be
            used.
          minItems: 1
          items:
            $ref: '#/components/schemas/Kling4Content'
        settings:
          $ref: '#/components/schemas/Kling4Settings'
        options:
          $ref: '#/components/schemas/Kling4Options'
    SubmitResponse:
      type: object
      properties:
        code:
          type: integer
          description: >-
            Error code; 0 means success. See the error code documentation for
            details.
          example: 0
        message:
          type: string
          description: Response message.
          example: SUCCEED
        request_id:
          type: string
          description: Request tracking ID generated by the system for troubleshooting.
          example: example-request-id
        data:
          type: object
          properties:
            id:
              type: string
              description: System task ID generated by the platform.
              example: example-task-id
            status:
              type: string
              enum:
                - submitted
                - processing
                - succeeded
                - failed
              description: 'Task status: submitted, processing, succeeded, or failed.'
              example: submitted
            create_time:
              type: integer
              format: int64
              description: Task creation time as a Unix timestamp in milliseconds.
              example: 1790000000000
            update_time:
              type: integer
              format: int64
              description: Task update time as a Unix timestamp in milliseconds.
              example: 1790000000000
            external_id:
              type: string
              description: Custom task ID specified at creation, if any.
              example: string
    Kling4Content:
      type: object
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - prompt
            - refer_image
            - element
          description: >-
            Material type. Supported values: prompt, reference image, element.


            Enum: `prompt` / `refer_image` / `element`


            Materials must include a prompt; `prompt` is required and must not
            be empty.


            Images and elements total at most 10; the prompt does not count
            toward this limit.


            Note: Elements (`element`) are not yet integrated and cannot be
            used.
        text:
          type: string
          description: >-
            Text prompt. Required and must not be empty; may include both
            positive and negative descriptions.


            You can template the prompt to meet different image generation
            needs.


            Prompt length: up to 50,000 characters for pure English, 21,000
            characters for pure non-English; mixed input must satisfy: English
            characters/50000 + non-English characters/21000 ≤ 1.


            Reference images or elements can be referenced with `@<id>`.


            The JSON definition is as follows:


            ```json

            { "type": "prompt", "text": "string" }

            ```
          x-valid-when:
            type:
              - prompt
        url:
          type: string
          description: >-
            Accepts an image URL or Base64 content. The URL must be accessible
            and the value must not be empty.


            Supported image formats: .jpg / .jpeg / .png.


            Each image file must be under 30 MB, at least 300 px in width and
            height, with an aspect ratio between 2:5 and 5:2.


            The JSON definition is as follows:


            ```json

            {
              "type": "refer_image",
              "url": "string", // Image URL or Base64 content
              "id": "string" // Material index ID, referenced in the prompt via @<id>
            }

            ```
          x-valid-when:
            type:
              - refer_image
        element_id:
          type: string
          description: >-
            Element ID generated by the system, required when `type=element`.
            You can retrieve it via the element query API. Note: Elements are
            not yet integrated; this parameter is not supported yet.


            Only multi-image elements (created from images) are supported.
            Different element types have different applicable scopes, so
            distinguish them carefully.


            The number of reference images plus the number of elements must not
            exceed 10.


            For more official element information, see: [Element
            library](https://app.klingai.com/cn/dev/document-api/apiReference/model/customElements).


            The JSON definition is as follows:


            ```json

            {
              "type": "element",
              "element_id": "string", // Element ID retrieved via the element query API
              "id": "string" // Material index ID, referenced in the prompt via @<id>
            }

            ```
          x-valid-when:
            type:
              - element
        id:
          type: string
          description: >-
            Material index ID, used to specify in the prompt; this parameter
            must not be repeated in the same task.
    Kling4Settings:
      type: object
      description: >-
        Parameters related to output configuration, such as resolution and
        aspect ratio.
      properties:
        result_type:
          type: string
          enum:
            - single
          default: single
          description: >-
            Result type. Only `single` (independent images) is currently
            supported; generate multiple images with `n`.
        'n':
          type: integer
          minimum: 1
          maximum: 9
          default: 1
          description: >-
            Number of independent images to generate. Optional; value range:
            [1,9].
        resolution:
          type: string
          enum:
            - 2k
            - 4k
            - 8k
          default: 2k
          description: |-
            Image resolution.
            - `2k`: 2K HD
            - `4k`: 4K HD
            - `8k`: 8K ultra HD
        aspect_ratio:
          type: string
          enum:
            - '16:9'
            - '9:16'
            - '1:1'
            - '4:3'
            - '3:4'
            - '3:2'
            - '2:3'
            - '21:9'
            - auto
          default: auto
          description: >-
            Aspect ratio of the generated image. `auto` means the ratio is
            determined from the input.
    Kling4Options:
      type: object
      description: >-
        General configuration, such as the callback URL and whether to include a
        watermark.
      properties:
        callback_url:
          type: string
          description: >-
            Callback URL for task results. When configured, the server notifies
            you whenever the task status changes. See the [Callback
            protocol](https://app.klingai.com/global/dev/document-api/api/get-started/callbacks)
            for the notification message schema.
        external_task_id:
          type: string
          description: >-
            Custom task ID.

            - It does not override the system-generated task ID, but can be used
            to query the task

            - Must be unique per user
        watermark_info:
          type: object
          description: >-
            Whether to also generate a watermarked result. Configured with
            `enabled`; custom watermarks are not supported.


            ```json

            "watermark_info": {
              "enabled": false // Whether to generate a watermarked result; true to generate, false not to; defaults to false
            }

            ```
          properties:
            enabled:
              type: boolean
              default: false
              description: true generates, false does not; defaults to false.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: 'Pass `Authorization: Bearer <token>` in the request header.'

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.