对接 OpenAI 的图像生成模型,按 token 计费,支持流式中帧和图生图 + mask。
基础生成
curl -X POST https://51kik.com/v1/image/v1/generations \
-H 'Authorization: Bearer sk-xxxxxxxx' \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-image-1",
"prompt": "isometric pixel-art spaceship launching",
"size": "1024x1024",
"upstream_options": { "quality": "high", "output_format": "png", "background": "auto" }
}'
计费方式
GPT Image 按 token 计费,usage 结构如下:
{
"usage": {
"input_tokens": { "image_tokens": 0, "text_tokens": 32 },
"output_tokens": { "image_tokens": 4096, "text_tokens": 0 },
"total_tokens": 4128
}
}
图生图 + 编辑 mask
curl -X POST https://51kik.com/v1/image/v1/generations \
-H 'Authorization: Bearer sk-xxxxxxxx' \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-image-1",
"prompt": "remove the background",
"image": "https://example.com/source.png",
"size": "1024x1024",
"upstream_options": { "quality": "high", "background": "transparent", "output_format": "png", "input_fidelity": "high", "mask": "https://example.com/mask.png" }
}'
流式(中间帧)
curl -N -X POST https://51kik.com/v1/image/v1/generations \
-H 'Authorization: Bearer sk-xxxxxxxx' \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-image-1",
"prompt": "watercolor cathedral at golden hour",
"size": "1024x1024",
"stream": true,
"upstream_options": { "partial_images": 3, "output_format": "png" }
}'
常用 upstream_options
| 参数 | 说明 |
|---|---|
quality | 质量:low / medium / high |
output_format | png / webp / jpeg |
background | 背景色 / transparent |
n | 生成张数 |
mask | 编辑遮罩 URL |
partial_images | 流式时返回中间帧数 |
input_fidelity | 参考图保真度 |