Skip to main content
POST
cURL

图像生成

完整参数参考请见 Kling 官方文档
使用此端点通过 Kling 的图像生成 API 创建静态图像。它通过同一异步任务流程,同时支持纯文本请求和图像参考请求。

首次请求

model_name: kling-v3promptnaspect_ratio 开始。仅在首次请求返回可用任务后,再添加参考图像、保真度控制或高级字段。省略 model_name 会使用旧版兼容默认值,因此对于新的集成,请显式传入 kling-v3

读取响应

保存返回的 task_id,然后轮询对应的 Kling 图像查询路由,直到 task_status 到达终态。如果你的工作流需要持久化存储,请在生成完成后将最终资源复制到你自己的存储层中。

授权

Authorization
string
header
必填

Bearer token authentication. Use your CometAPI key.

请求头

Content-Type
string
默认值:application/json

Must be application/json.

请求体

application/json
prompt
string
必填

Text prompt describing the image to generate. Maximum 2500 characters.

model_name
enum<string>
默认值:kling-v1

Kling image model variant. Use kling-v3 for new requests. Omitting model_name uses the legacy CometAPI route default.

可用选项:
kling-v1,
kling-v1-5,
kling-v2,
kling-v2-1,
kling-v3
negative_prompt
string

Elements to exclude from the image. Maximum 2500 characters. Not supported when image is provided.

image
string

Reference image as a raw Base64 string without a data: prefix, or a public URL. Accepted formats: JPG, JPEG, PNG. Maximum 10 MB, minimum 300x300 px, aspect ratio between 1:2.5 and 2.5:1.

image_reference
enum<string>

Reference mode for legacy image-to-image requests when image is provided.

可用选项:
subject,
face
image_fidelity
number
默认值:0.5

How closely the output follows the reference image. Range: 0-1. Used by legacy image-reference models.

必填范围: 0 <= x <= 1
human_fidelity
number
默认值:0.45

Human-subject fidelity control. Range: 0-1. Used only by legacy subject-reference requests.

必填范围: 0 <= x <= 1
element_list
object[]

Optional Kling element references. The total count of element references and input images must not exceed 10.

resolution
enum<string>
默认值:1k

Output resolution. Defaults to 1k.

可用选项:
1k,
2k
n
integer
默认值:1

Number of images to generate. Range: 1-9.

必填范围: 1 <= x <= 9
aspect_ratio
enum<string>
默认值:16:9

Output aspect ratio (width:height).

可用选项:
16:9,
9:16,
1:1,
4:3,
3:4,
3:2,
2:3,
21:9
watermark_info
object

Watermark options.

callback_url
string

Webhook URL to receive task status updates when the task completes.

external_task_id
string

Optional user-defined task ID for your own tracking. Must be unique per account.

响应

200 - application/json

Task request accepted or an error response returned by the API.

code
必填

Response code. 0 means the task request was accepted.

message
string
必填

Response message.

data
object
必填
request_id
string

Request identifier returned when present.