Kling Image 4.0 · 图片 API
用 Kling Image 4.0 生成单图、连贯组图、电商详情页和网页设计长图。
Kling Image 4.0
用 Kling Image 4.0 生成单图、连贯组图、电商详情页和网页设计长图。
接口
POST https://apimaster.ai/v1/kling/kling-image-4.0/image-generation·single,seriesPOST https://apimaster.ai/v1/kling/kling-image-4.0/long-image-generation·ecommerce,webpageGET https://apimaster.ai/v1/kling/kling-image-4.0/tasks/{task_id}
请求参数
| 字段 | 取值 |
|---|---|
contents |
JSON · type → prompt, refer_image, element, style_refer_image, subject_refer_image. |
contents[].text |
必须提供一项非空提示词。用 @id 在提示词中引用对应素材。 |
contents[].id |
每个参考素材在本次请求内的唯一标识。 |
contents[].url |
公开图片 URL 或 Base64。支持 JPG、JPEG、PNG,单张不超过 30 MB,宽高均至少 300 像素,比例为 2:5 至 5:2。 |
contents[].element_id |
本账号拥有的图片主体句柄或受支持的预设句柄。每个主体按一个参考素材计。 |
settings.result_type |
single, series. 默认 single. |
settings.n |
single → 1–9. 默认 1. |
settings.series_amount |
series → 2–10 / auto (2–10). 默认 4. |
settings.resolution |
single / series → 2k, 4k, 8k. 默认 2k. ecommerce / webpage → 1k, 2k. 默认 1k. |
settings.aspect_ratio |
single / series → auto, 16:9, 9:16, 1:1, 4:3, 3:4, 3:2, 2:3, 21:9. 默认 auto. |
settings.skill |
long-image-generation → ecommerce, webpage. |
settings.length |
ecommerce → short, medium, long. 默认 medium. |
options.watermark_info.enabled |
boolean. 默认 false. true → outputs[].watermark_url. |
options.callback_url |
可选回调地址,须先在本 APIMaster 账号下注册并验证。 |
options.external_task_id |
可选业务关联 ID,最多 128 字节,随任务返回。 |
普通图和组图的参考图与主体合计最多 10 个。电商需 1–3 项 refer_image。网页最多支持一项风格图和一项主体图。
普通图支持纯英文 50,000 字符或纯非英文 21,000 字符。长图分别为 166,000 和 71,000。混合输入时,两类字符数各除以上限,合计不得超过 1。
单图模式生成独立图片。组图模式按组内顺序返回连贯图片,同组共用 group_id。 长图每次返回一张完整图片。length 仅适用于电商,分别约 2–5、6–10 或 11–18 个内容模块。
调用示例
single
curl -sS "https://apimaster.ai/v1/kling/kling-image-4.0/image-generation" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: kling-image-example-001" \
-d '{"contents":[{"type":"prompt","text":"A blue ceramic cup in soft daylight"}],"settings":{"resolution":"2k","aspect_ratio":"1:1"}}'
series
{
"contents": [
{
"type": "prompt",
"text": "Create two coordinated studio photographs of the blue ceramic cup in @cup. Show a front view and a detail close-up."
},
{
"type": "refer_image",
"id": "cup",
"url": "https://example.com/cup.png"
}
],
"settings": {
"result_type": "series",
"series_amount": 2,
"resolution": "4k",
"aspect_ratio": "3:4"
},
"options": {
"watermark_info": {
"enabled": true
},
"external_task_id": "campaign-cup-001"
}
}
ecommerce
{
"contents": [
{
"type": "prompt",
"text": "Design a product detail page for @cup. Include a hero image, material details, and care instructions."
},
{
"type": "refer_image",
"id": "cup",
"url": "https://example.com/cup.png"
}
],
"settings": {
"skill": "ecommerce",
"length": "short",
"resolution": "1k"
}
}
webpage
{
"contents": [
{
"type": "prompt",
"text": "Design a long product landing page for a ceramic cup collection."
}
],
"settings": {
"skill": "webpage",
"resolution": "2k"
}
}
任务结果
保存 task_id,并使用同一账号查询。成功时 outputs 返回每张图的 URL,以及可选的 watermark_url 和 group_id。失败时读取 error。
curl -sS "https://apimaster.ai/v1/kling/kling-image-4.0/tasks/TASK_ID" \
-H "Authorization: Bearer YOUR_API_KEY"
{
"task_id": "task_example",
"object": "image",
"model": "kling-image-4.0",
"status": "completed",
"outputs": [{"type": "image", "url": "https://example.com/generated.png"}]
}
重试同一请求时沿用 Idempotency-Key。请求超时后查询原任务。
计费
费用为交付张数乘输出档位单价,加参考素材数乘输入单价。客户实时价格见模型广场。 Kling Image 4.0
