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.