> ## 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 图像生成 kling-4.0

> 通过 `/kling/image-generation` 提交 Kling 4.0 文生单图或图生单图任务，单图模式可通过 `n` 生成多张独立图片。注意：平台暂时不对接主体（`element`）和音色（`voice`）相关能力，相关参数暂不支持传入。



## OpenAPI

````yaml api-reference/zh-Hans/zmodelImage/kling/kling-4.0-image-generations.json POST /kling/image-generation
openapi: 3.0.1
info:
  title: Kling 4.0 图像生成任务 - 提交任务
  version: 1.0.0
  description: >-
    通过 `/kling/image-generation` 提交 Kling 4.0
    文生单图或图生单图任务。注意：平台暂时不对接主体（`element`）和音色（`voice`）相关能力，相关参数暂不支持传入。
servers:
  - url: https://api.powertokens.ai
    description: ''
security: []
tags:
  - name: Kling
    description: Kling 原生异步任务端点
paths:
  /kling/image-generation:
    post:
      tags:
        - Kling
      summary: Kling 4.0 图像生成任务
      description: >-
        通过 `/kling/image-generation` 提交 Kling 4.0 文生单图或图生单图任务，单图模式可通过 `n`
        生成多张独立图片。注意：平台暂时不对接主体（`element`）和音色（`voice`）相关能力，相关参数暂不支持传入。
      operationId: createKlingImageGeneration4
      parameters:
        - name: Content-Type
          in: header
          required: true
          schema:
            type: string
            default: application/json
          description: 数据交换格式
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Kling4Request'
            examples:
              text_to_image:
                summary: 文生单图
                value:
                  model_name: kling-4.0
                  contents:
                    - type: prompt
                      text: 生成一张三维动画风格的角色海报，暖色灯光，背景简洁。
                  settings:
                    result_type: single
                    'n': 1
                    resolution: 2k
                    aspect_ratio: '1:1'
              image_to_image:
                summary: 图生单图
                value:
                  model_name: kling-4.0
                  contents:
                    - type: prompt
                      text: >-
                        以 @dog
                        中的小狗为主角，生成一张三维动画风格的故事图片，表现小狗在咖啡馆窗边落座的场景。保持小狗的毛色、外观和画面风格一致。
                    - 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: 任务已受理。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SubmitResponse'
              examples:
                response:
                  summary: 响应示例
                  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: 模型名称
          example: kling-4.0
        contents:
          type: array
          description: |-
            参考素材合集，如：提示词、图片、主体。

            参考格式如下，参数说明详见下文：

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

            - 提示词、参考图、主体的排列顺序即为分析顺序

            注意：主体（`element`）暂不对接，暂不支持传入。
          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: 错误码；0 为成功，具体定义见错误码文档。
          example: 0
        message:
          type: string
          description: 接口消息。
          example: SUCCEED
        request_id:
          type: string
          description: 请求跟踪 ID，由系统生成，用于跟踪请求、排查问题。
          example: example-request-id
        data:
          type: object
          properties:
            id:
              type: string
              description: 系统任务 ID，由平台生成。
              example: example-task-id
            status:
              type: string
              enum:
                - submitted
                - processing
                - succeeded
                - failed
              description: 任务状态：submitted（已提交）、processing（处理中）、succeeded（成功）、failed（失败）。
              example: submitted
            create_time:
              type: integer
              format: int64
              description: 任务创建时间，Unix 毫秒时间戳。
              example: 1790000000000
            update_time:
              type: integer
              format: int64
              description: 任务更新时间，Unix 毫秒时间戳。
              example: 1790000000000
            external_id:
              type: string
              description: 创建时指定的自定义任务 ID（如有）。
              example: string
    Kling4Content:
      type: object
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - prompt
            - refer_image
            - element
          description: |-
            素材类型，支持：提示词、参考图、主体。

            枚举值：`prompt` / `refer_image` / `element`

            素材必须包含提示词，`prompt` 必填且非空。

            图片和主体合计最多 10 个，提示词不占参考名额。

            注意：主体（`element`）暂不对接，暂不支持传入。
        text:
          type: string
          description: >-
            文本提示词，必填非空，可包含正向与负向描述。


            可将提示词模板化来满足不同的图像生成需求。


            提示词长度，纯英文不超过 50,000 字符，纯非英文不超过 21,000 字符；混合输入需满足：英文字符数/50000 +
            非英文字符数/21000 ≤ 1。


            可通过 `@<id>` 引用参考图或主体。


            并通过 JSON 的格式定义，具体如下：


            ```json

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

            ```
          x-valid-when:
            type:
              - prompt
        url:
          type: string
          description: |-
            支持传入图片 URL 或 Base64 编码，URL 必须可访问，值不得为空。

            图片格式支持 .jpg / .jpeg / .png。

            单张图片文件不超过 30 MB，宽、高均不小于 300 px，宽高比为 2:5–5:2。

            并通过 JSON 的格式定义，具体如下：

            ```json
            {
              "type": "refer_image",
              "url": "string", // 参考图 URL 或 Base64 编码
              "id": "string" // 素材索引 ID，用于在提示词中通过 @<id> 引用
            }
            ```
          x-valid-when:
            type:
              - refer_image
        element_id:
          type: string
          description: >-
            主体 ID，由系统生成，可通过查询主体 API 获取，`type=element` 时必填。注意：主体暂不对接，该参数暂不支持传入。


            仅支持多图主体（通过图片定制的主体）。不同类型主体，适用范围不同，请注意区分。


            参考图片数量与主体数量之和不得超过 10。


            更多官方主体信息详见：[主体库](https://app.klingai.com/cn/dev/document-api/apiReference/model/customElements)。


            并通过 JSON 的格式定义，具体如下：


            ```json

            {
              "type": "element",
              "element_id": "string", // 主体 ID，通过查询主体 API 获取
              "id": "string" // 素材索引 ID，用于在提示词中通过 @<id> 引用
            }

            ```
          x-valid-when:
            type:
              - element
        id:
          type: string
          description: 素材索引ID，用于在 prompt 中指定，同任务中当前参数不得重复
    Kling4Settings:
      type: object
      description: 输出配置相关参数，如清晰度、宽高比等。
      properties:
        result_type:
          type: string
          enum:
            - single
          default: single
          description: 生成结果类型，当前仅支持单图（`single`）：独立图片，可通过 `n` 生成多张。
        'n':
          type: integer
          minimum: 1
          maximum: 9
          default: 1
          description: 生成独立图片数量。选填；取值范围：[1,9]。
        resolution:
          type: string
          enum:
            - 2k
            - 4k
            - 8k
          default: 2k
          description: |-
            生成图片的清晰度。
            - `2k`：2K 高清
            - `4k`：4K 高清
            - `8k`：8K 超清
        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: 生成图片的宽高比。`auto` 表示根据传入内容智能生成图片宽高比。
    Kling4Options:
      type: object
      description: 通用配置，如回调地址、是否含水印等。
      properties:
        callback_url:
          type: string
          description: >-
            本次任务结果回调通知地址。如果配置，服务端会在任务状态发生变更时主动通知。具体通知的消息 schema 见 [Callback
            协议](https://app.klingai.com/cn/dev/document-api/api/get-started/callbacks)。
        external_task_id:
          type: string
          description: |-
            自定义任务ID。
            - 传入不会覆盖系统生成的任务ID，但支持通过该ID进行任务查询
            - 请注意，单用户下需要保证唯一性
        watermark_info:
          type: object
          description: |-
            是否同时生成含水印的结果。通过 `enabled` 参数定义，暂不支持自定义水印。

            ```json
            "watermark_info": {
              "enabled": false // 是否生成含水印结果，true 为生成，false 为不生成；默认为 false
            }
            ```
          properties:
            enabled:
              type: boolean
              default: false
              description: true 为生成，false 为不生成，默认 false。
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: '在请求头中传入 `Authorization: Bearer <token>`。'

````

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