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

# Kling 4.0 Image Edit

> Kling's image-editing model for changing objects, style, or composition using one or more reference images.

Poll the returned task URL to retrieve the images. See [Query Task Result](https://docs.modellix.ai/api/get-task-result.md).


## OpenAPI

````yaml /media-model-api/kling/kling-i2i.json post /kling/kling-4.0-image-edit
openapi: 3.1.0
info:
  description: The image-to-image models API from Kling AI.
  version: 1.0.0
  contact:
    name: Modellix Support
    email: support@modellix.ai
  title: Kling Image-to-Image Models API
servers:
  - url: https://api.modellix.ai/api/v1
    description: The image-to-image models API from Kling AI.
security:
  - bearerAuth: []
paths:
  /kling/kling-4.0-image-edit:
    post:
      summary: Kling 4.0 Image Edit
      description: >-
        Kling's image-editing model for changing objects, style, or composition
        using one or more reference images.
      operationId: kling4ImageEditAsync
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Kling4ImageEditRequest'
            example:
              prompt: >-
                Keep the scones and composition, and give the image a warm
                morning light.
              images:
                - >-
                  https://storage.googleapis.com/cloud-samples-data/generative-ai/image/scones.jpg
              resolution: 2k
              'n': 1
      responses:
        '200':
          description: Task submitted successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AsyncTaskResponse'
              example:
                code: 0
                message: success
                data:
                  status: pending
                  task_id: task-kling-4-0-image-edit-001
                  model_id: kling/kling-4.0-image-edit
                  get_result:
                    method: GET
                    url: >-
                      https://api.modellix.ai/api/v1/tasks/task-kling-4-0-image-edit-001
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  schemas:
    Kling4ImageEditRequest:
      type: object
      required:
        - images
      additionalProperties: false
      properties:
        images:
          type: array
          minItems: 1
          description: >-
            Each image can be a URL string or an object with `image_url`. Use
            public HTTP(S) URLs without credentials, query strings, or
            fragments. If you include `reference_type`, use `refer_image`.
          items:
            oneOf:
              - type: string
                format: uri
              - allOf:
                  - $ref: '#/components/schemas/Kling4ImageReference'
                  - properties:
                      reference_type:
                        const: refer_image
        prompt:
          type: string
          pattern: \S
          description: >-
            Instructions for the edit. Provide non-blank text when you include
            this field.
        resolution:
          type: string
          enum:
            - 2k
            - 4k
          description: Output resolution.
        aspect_ratio:
          type: string
          pattern: ^(auto|[1-9][0-9]*:[1-9][0-9]*)$
          description: >-
            Use `auto` or a supported width-to-height ratio such as `1:1` or
            `16:9`.
        'n':
          type: integer
          minimum: 1
          maximum: 9
          description: Number of images to generate.
    AsyncTaskResponse:
      type: object
      required:
        - code
        - message
        - data
      properties:
        code:
          type: integer
          description: Response code, 0 indicates success
          example: 0
        message:
          type: string
          description: Response message
          example: success
        data:
          type: object
          required:
            - status
            - task_id
            - model_id
          properties:
            status:
              type: string
              enum:
                - pending
                - processing
              description: Task status
              example: pending
            task_id:
              type: string
              description: Unique task identifier
              example: task-abc123
            model_id:
              type: string
              description: Model ID
              example: model-123
            get_result:
              type: object
              description: API information to query the task result
              properties:
                method:
                  type: string
                  description: HTTP method
                  example: GET
                url:
                  type: string
                  description: Full URL to query the task result
                  example: https://api.modellix.ai/api/v1/tasks/task-abc123
          description: Detailed data about the submitted asynchronous task.
    Kling4ImageReference:
      type: object
      required:
        - image_url
      additionalProperties: false
      properties:
        image_url:
          type: string
          format: uri
          description: Public URL of the reference image.
        reference_type:
          type: string
          enum:
            - refer_image
            - style_refer_image
            - subject_refer_image
          description: Role of the reference image.
        id:
          type: string
          pattern: \S
          description: >-
            Optional image identifier. Refer to it in `prompt` with `@id`, for
            example `@id1`.
    ErrorResponse:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: integer
          description: Error code (equals HTTP status code)
          example: 400
        message:
          type: string
          description: 'Error message in format ''Category: detail'''
          example: 'Invalid parameters: parameter ''image'' is required'
  responses:
    BadRequest:
      description: Invalid request parameters
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            code: 400
            message: 'Invalid parameters: parameter ''image'' is required'
    Unauthorized:
      description: Unauthorized - Invalid or missing API Key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            code: 401
            message: 'Authentication failed: invalid API key'
    TooManyRequests:
      description: Too many requests - Rate limit exceeded
      headers:
        X-RateLimit-Limit:
          description: Maximum requests per minute
          schema:
            type: integer
            example: 100
        X-RateLimit-Remaining:
          description: Remaining quota in current window
          schema:
            type: integer
            example: 0
        X-RateLimit-Reset:
          description: Rate limit window reset time (Unix timestamp)
          schema:
            type: integer
            example: 1704067260
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            code: 429
            message: >-
              Rate limit exceeded: 100 requests per minute, retry after 60
              seconds
    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            code: 500
            message: Internal server error
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: 'API Key authentication. Format: `Bearer YOUR_API_KEY`.'

````

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