IMG
图片生成 API
通过统一的接口调用多家顶级图片生成模型,支持文生图、图片编辑、蒙版修复和多图融合。
快速开始
1
从控制台获取 API 密钥2
选择下方图片生成模型3
发送 POST 请求创建任务4
轮询 GET 请求获取图片链接认证方式
所有请求需在 Header 中携带 Bearer Token:
Authorization: Bearer YOUR_API_KEY
接口端点
POST
/api/v1/images/generations创建图片生成任务
GET
/api/v1/images/generations?task_id=xxx查询任务状态并获取图片链接
API 参考
选择模型提供商查看对应的参数和示例
SparkPix
SparkPix
SparkPix 出品的超快图片模型,两个独立端点。SparkPix Image 文生图不到 1 秒,支持 LoRA 自定义风格。SparkPix Image Edit 支持多图参考编辑。均为同步 API,直接返回结果,无需轮询。
可用模型
SparkPix Image
POST /api/v1/images/generations-sync$0.0100/张
文生图,同步,<1 秒,支持 LoRA
SparkPix Image Edit
POST /api/v1/images/edit$0.0130/张
多图编辑,同步,<1 秒
请求参数
── SparkPix Image 参数 ──
POST /api/v1/images/generations-syncprompt必填
string图片描述aspect_ratio
string"custom"(默认,自动尺寸)、"1:1"、"16:9"、"9:16"、"4:3"、"3:4"、"3:2"、"2:3"width
integer仅 aspect_ratio="custom" 时生效,256-1440,须为 16 的倍数height
integer仅 aspect_ratio="custom" 时生效,256-1440,须为 16 的倍数prompt_upsampling
boolean用 LLM 自动扩写优化提示词(默认 false)seed
integer随机种子,用于复现生成结果lora_weights
stringHuggingFace LoRA 权重 URL,格式: huggingface.co/<owner>/<model>[/<file.safetensors>]lora_scale
numberLoRA 强度,-1 到 3,默认 0.5callBackUrl
string任务完成后的回调 URL── SparkPix Image Edit 参数 ──
POST /api/v1/images/editprompt必填
string编辑指令,可用 "image 1"、"image 2" 引用输入图片images
string[]参考图片 URL 数组,第一张为主图aspect_ratio
string"match_input_image"(默认,匹配第一张图)、"1:1"、"16:9"、"9:16"、"4:3"、"3:4"、"3:2"、"2:3"turbo
boolean加速模式(默认 true),复杂任务建议关闭seed
integer随机种子,用于复现生成结果callBackUrl
string任务完成后的回调 URL说明
- -两个模型使用不同的 API 端点,不是同一个接口
- -SparkPix Image(文生图): POST /api/v1/images/generations-sync
- -SparkPix Image Edit(图片编辑): POST /api/v1/images/edit
- -两个接口都是同步 API,直接返回图片 URL,无需轮询
- -响应格式: { code: 200, data: { url, model, credits, duration } }
- -SparkPix Image 的 aspect_ratio 默认 "custom"(自动),SparkPix Image Edit 默认 "match_input_image"(匹配输入图尺寸)
代码示例
# SparkPix Image: Text-to-image (sync, sub-1-second)
curl -X POST https://apimodels.app/api/v1/images/generations-sync \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A cute cat wearing a space helmet, digital art",
"aspect_ratio": "16:9",
"seed": 42
}'
# SparkPix Image Edit: Multi-image editing (sync)
curl -X POST https://apimodels.app/api/v1/images/edit \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Make the background a sunset beach",
"images": ["https://example.com/photo.jpg"],
"aspect_ratio": "16:9"
}'响应格式
创建任务响应
{
"code": 200,
"msg": "success",
"data": {
"taskId": "clxxx...",
"state": "pending"
}
}成功响应
{
"code": 200,
"msg": "success",
"data": {
"taskId": "clxxx...",
"state": "completed",
"resultUrls": ["https://r2.apimodels.app/images/xxx.jpeg"],
"createTime": 1705123450000,
"completeTime": 1705123465000
}
}失败响应
{
"code": 200,
"msg": "success",
"data": {
"taskId": "clxxx...",
"state": "failed",
"failMsg": "Content policy violation"
}
}任务状态
pending任务已排队,等待处理processing图片生成中completed生成成功,可获取图片链接failed生成失败错误码
400请求参数错误或缺失401API 密钥无效402积分不足404任务 ID 不存在500服务器内部错误注意事项
- -图片文件保存 7 天,请及时下载
- -生成失败不扣费
- -建议每 2-3 秒轮询一次任务状态
- -生产环境建议使用 callback_url 避免轮询
- -请妥善保管 API 密钥