使用 Kling 生成圖片
透過 CometAPI 使用 Kling 生成圖片:POST /kling/v1/images/generations 支援由 prompt 驅動的圖片建立,以及參考圖片生成。
圖片生成
第一個請求
先從model_name: kling-v3、prompt、n 和 aspect_ratio 開始。只有在第一個請求回傳可用的任務後,再加入參考圖片、保真度控制或進階欄位。省略 model_name 會使用舊版相容性的預設值,因此新的整合請明確傳送 kling-v3。
讀取回應
儲存回傳的task_id,然後輪詢對應的 Kling 圖片查詢路由,直到 task_status 進入終態。如果你的工作流程需要可持久保存的儲存,請在生成完成後,將最終資產複製到你自己的儲存層。授權
Bearer token authentication. Use your CometAPI key.
標頭
Must be application/json.
主體
Text prompt describing the image to generate. Maximum 2500 characters.
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 Elements to exclude from the image. Maximum 2500 characters. Not supported when image is provided.
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.
Reference mode for legacy image-to-image requests when image is provided.
subject, face How closely the output follows the reference image. Range: 0-1. Used by legacy image-reference models.
0 <= x <= 1Human-subject fidelity control. Range: 0-1. Used only by legacy subject-reference requests.
0 <= x <= 1Optional Kling element references. The total count of element references and input images must not exceed 10.
Output resolution. Defaults to 1k.
1k, 2k Number of images to generate. Range: 1-9.
1 <= x <= 9Output aspect ratio (width:height).
16:9, 9:16, 1:1, 4:3, 3:4, 3:2, 2:3, 21:9 Watermark options.
Webhook URL to receive task status updates when the task completes.
Optional user-defined task ID for your own tracking. Must be unique per account.