Kling Image 4.0 API
Kling Image4.0 面向商业创作,支持原生8K、多语言文字与多图参考的一体化图像生成模型。
Kling Image4.0 是由 Kling AI(Kuaishou)推出的专业高质量图像生成模型,支持文本输入、图像输入和图像输出。模型支持原生8K图像生成,并兼容2K和4K输出;单张图像可生成最多2,000 characters 的文字内容,支持超过70种字体及多语言文字生成,包括英语、日语、韩语、西班牙语和葡萄牙语。
模型最多可使用10张参考图,帮助保持人物、产品和地点的一致性,也能生成最多包含10张图像的一致性图像组。它支持长篇布局和9种宽高比,适合制作产品广告、商业视觉、品牌营销素材、海报、传单、社交媒体图片、目录和宣传册。生成的图像还可作为 Kling4.0 视频生成的关键帧或参考素材。
更新时间:
模型 ID
kling-4.0/image-generation- 输入
- 文本 / 图像
- 输出
- 图像
核心要点
- 原生8K图像生成
- 支持2K和4K输出
- 最多10张参考图
- 超过70种字体
- 支持9种宽高比
- 衔接Kling4.0视频生成
供应商
最优价格比较不同供应商的调用价格,点击供应商可查看完整费用和适用条件。
| 可用率 | |
|---|---|
历史统计不等于实时健康检查,缺失数据不代表服务中断。
基准测试
- 15
图像排行榜
排名为15
分数来自模型厂商公布的数据,未独立验证。
快速开始
提交图片任务、轮询状态,再保存图片。以下示例使用 curl 和 Python 3(仅标准库,无需安装依赖)。
POST https://openapi.felo.ai/api/v1/images/generations
1填入 API key
从 Felo API Platform 账户创建 key,并设置为环境变量。
export FELO_API_KEY="YOUR_API_KEY"2发起第一次请求
可选参数的取值因模型而异,示例不预设这些值;添加前请在 Playground 确认。请求字段与 model、prompt 同级,不包在 input 中。
curl --fail-with-body --max-time 60 "https://openapi.felo.ai/api/v1/images/generations" \
-H "Authorization: Bearer $FELO_API_KEY" \
-H "Content-Type: application/json" \
-o created.json \
-d '{
"prompt": "A studio product photo of a ceramic coffee cup on warm linen, soft morning light",
"model": "kling-4.0/image-generation"
}'3轮询任务
提交后获得 task_id;queued、running 时每 3 秒查询一次,succeeded、failed 或 interrupted 时停止。示例最多等待 30 分钟。保留 created.json 可继续查询同一任务,避免重复提交。
python3 - <<'PY'
import json, os, time
from pathlib import Path
from urllib.parse import quote
from urllib.request import Request, urlopen
task = json.loads(Path("created.json").read_text())
task_id = task["task_id"]
url = "https://openapi.felo.ai/api/v1/images/generations/" + quote(task_id, safe="")
headers = {"Authorization": "Bearer " + os.environ["FELO_API_KEY"]}
deadline = time.monotonic() + 1800
while task["status"] in ("queued", "running"):
if time.monotonic() >= deadline:
raise TimeoutError(f"Keep task_id={task_id} to resume polling")
time.sleep(3)
with urlopen(Request(url, headers=headers), timeout=60) as response:
task = json.load(response)
if task.get("task_id") != task_id or task.get("kind") != "image":
raise ValueError("Unexpected task response")
print(task["status"])
if task["status"] != "succeeded":
raise RuntimeError(task.get("error") or task["status"])
if not task.get("outputs"):
raise ValueError("Task succeeded without image outputs")
Path("task.json").write_text(json.dumps(task))
print("Saved task.json")
PY4下载输出
成功后从 task.json 读取 outputs 并保存。结果兼容 HTTPS 地址、URL 对象和 b64_json。签名地址请及时下载;下载图片时无需携带 API Key。
python3 - <<'PY'
import base64, json
from pathlib import Path
from urllib.request import urlopen
task = json.loads(Path("task.json").read_text())
if task.get("status") != "succeeded" or not task.get("outputs"):
raise ValueError("No completed image outputs")
extensions = {"image/png": ".png", "image/jpeg": ".jpg", "image/webp": ".webp", "image/gif": ".gif", "image/avif": ".avif"}
for index, output in enumerate(task["outputs"], 1):
item = output if isinstance(output, dict) else {}
url = output if isinstance(output, str) else item.get("url") or item.get("unsigned_url")
mime = item.get("media_type") or "image/png"
if url and url.startswith("https://"):
with urlopen(url, timeout=60) as response:
data = response.read()
mime = response.headers.get_content_type()
elif url and url.startswith("data:image/") and ";base64," in url:
header, encoded = url.split(",", 1)
mime = header[5:].split(";", 1)[0]
data = base64.b64decode(encoded, validate=True)
elif item.get("b64_json"):
data = base64.b64decode(item["b64_json"], validate=True)
else:
raise ValueError("Unrecognized image output")
path = Path(f"image-{index}" + extensions.get(mime, ".bin"))
path.write_bytes(data)
print(path)
PYinput_references
编辑图片时,将示例地址替换为你的 HTTPS 图片地址或 base64 图片 data URL。提交一次后,沿用相同的轮询与保存步骤。
curl --fail-with-body --max-time 60 "https://openapi.felo.ai/api/v1/images/generations" \
-H "Authorization: Bearer $FELO_API_KEY" \
-H "Content-Type: application/json" \
-o created.json \
-d '{
"prompt": "Keep the product and framing. Replace the background with a sunlit marble countertop.",
"model": "kling-4.0/image-generation",
"input_references": [
{
"type": "image_url",
"image_url": {
"url": "https://example.com/product.png"
}
}
]
}'支持的参数
- n
- prompt
- resolution
- aspect_ratio
- input_references
想查看完整文档?
API 文档 →常见问题
什么是 Kling Image 4.0?
Kling Image4.0 是由 Kling AI(Kuaishou)推出的专业高质量图像生成模型,支持文本输入、图像输入和图像输出。模型支持原生8K图像生成,并兼容2K和4K输出;单张图像可生成最多2,000 characters 的文字内容,支持超过70种字体及多语言文字生成,包括英语、日语、韩语、西班牙语和葡萄牙语。 模型最多可使用10张参考图,帮助保持人物、产品和地点的一致性,也能生成最多包含10张图像的一致性图像组。它支持长篇布局和9种宽高比,适合制作产品广告、商业视觉、品牌营销素材、海报、传单、社交媒体图片、目录和宣传册。生成的图像还可作为 Kling4.0 视频生成的关键帧或参考素材。
如何计算调用费用?
费用取决于你使用的供应商、对应价格和实际用量。长文本输入等情况可能适用不同价格,详见计费明细。
Kling Image4.0 支持哪些输入和输出?
支持文本输入、图像输入和图像输出。
它能生成多长的图像文字?
单张图像可生成最多2,000 characters 的文字内容,并支持超过70种字体及多语言文字生成。
它支持多少张参考图?
最多可使用10张参考图,用于保持人物、产品和地点在生成结果中的一致性。
Kling Image4.0适合哪些任务?
适合产品广告、商业视觉、品牌营销、文字密集型设计,以及目录和宣传册等长篇布局内容。
它与同系列模型有什么差别?
资料显示 Kling Image4.0侧重专业图像生成,并支持原生8K、多图参考和与 Kling4.0 视频生成衔接。