适用站点:
https://api.ideamine.cn更新时间:2026-11-05
| 同步 | 异步 | |
|---|---|---|
| 接口 | POST /v1/images/generations |
POST /v1/images/async + 轮询 |
| 什么时候返回 | 出好图才返回(20–40 秒) | 立刻返回任务 ID(1–2 秒) |
| 客户端超时 | 建议 ≥ 300 秒 | 只需 10 秒 |
| 适合 | 单张、交互式、页面里等结果 | 批量、并发高、后台跑 |
并发高(一次十几张以上)请用异步,否则容易触发客户端超时。
所有请求都需要 Header:
Authorization: Bearer sk-你的令牌
令牌在控制台「令牌」页创建。
curl -X POST https://api.ideamine.cn/v1/images/generations \
-H "Authorization: Bearer $KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2.5-sunburst",
"prompt": "一只橘猫坐在木桌上,阳光斜射,写实风格",
"size": "1024x1024",
"n": 1
}'
返回:
{
"created": 1762300000,
"data": [
{ "url": "https://pub-xxxx.r2.dev/image-hub/2026/11/05/xxxx.png" }
],
"usage": {
"input_tokens": 78,
"output_tokens": 229
}
}
import requests
KEY = "sk-你的令牌"
resp = requests.post(
"https://api.ideamine.cn/v1/images/generations",
headers={"Authorization": f"Bearer {KEY}"},
json={
"model": "gpt-image-2.5-sunburst",
"prompt": "一只橘猫坐在木桌上",
"size": "1024x1024",
"n": 1,
},
timeout=300, # 同步接口要留足时间
)
resp.raise_for_status()
url = resp.json()["data"][0]["url"]
# 下载图片
img = requests.get(url, timeout=60)
with open("cat.png", "wb") as f:
f.write(img.content)
const r = await fetch("https://api.ideamine.cn/v1/images/generations", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "gpt-image-2.5-sunburst",
prompt: "一只橘猫坐在木桌上",
size: "1024x1024",
n: 1,
}),
});
const data = await r.json();
console.log(data.data[0].url);
curl -X POST https://api.ideamine.cn/v1/images/async \
-H "Authorization: Bearer $KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2.5-sunburst",
"prompt": "一只橘猫坐在木桌上",
"size": "1024x1024",
"n": 1
}'
立刻返回(约 0.3–2 秒):
{
"id": "imgtask_5f86d0d6d8c44de2bc75277c2bec60be",
"object": "image.task",
"status": "queued",
"poll": "/v1/images/async/imgtask_5f86d0d6d8c44de2bc75277c2bec60be"
}
提交时不扣费,任务真正执行时才扣。
curl https://api.ideamine.cn/v1/images/async/imgtask_5f86d0d6... \
-H "Authorization: Bearer $KEY"
状态只有四种:
| status | 含义 | 建议动作 |
|---|---|---|
queued |
排队中 | 继续等 |
running |
出图中 | 继续等 |
succeeded |
完成,data[].url 可用 |
下载图片 |
failed |
失败,看 error.message |
按错误提示处理 |
成功:
{
"id": "imgtask_...",
"status": "succeeded",
"data": [
{ "url": "https://pub-xxxx.r2.dev/image-hub/2026/11/05/xxxx.png" }
],
"usage": { "input_tokens": 78, "output_tokens": 229 }
}
失败:
{
"id": "imgtask_...",
"status": "failed",
"error": { "message": "内容可能违反使用政策" }
}
import time
import requests
KEY = "sk-你的令牌"
BASE = "https://api.ideamine.cn"
HEAD = {"Authorization": f"Bearer {KEY}"}
def submit(prompt, model="gpt-image-2.5-sunburst", size="1024x1024"):
r = requests.post(f"{BASE}/v1/images/async", headers=HEAD,
json={"model": model, "prompt": prompt, "size": size, "n": 1},
timeout=30)
r.raise_for_status()
return r.json()["id"]
def wait(tid, timeout=900, interval=3):
deadline = time.time() + timeout
while time.time() < deadline:
r = requests.get(f"{BASE}/v1/images/async/{tid}", headers=HEAD, timeout=20)
r.raise_for_status()
d = r.json()
if d["status"] == "succeeded":
return d["data"][0]["url"]
if d["status"] == "failed":
raise RuntimeError(d.get("error", {}).get("message", "生成失败"))
time.sleep(interval)
raise TimeoutError("等待超时")
tid = submit("一只橘猫坐在木桌上")
url = wait(tid)
print("图片地址:", url)
prompts = ["一只橘猫", "一只蓝猫", "一只白猫", "一只黑猫", "一只花猫",
"一只灰猫", "一只黄猫", "一只斑点猫", "一只长毛猫", "一只短毛猫"]
ids = [submit(p) for p in prompts] # 10 个请求,2 秒内全部提交完
urls = [wait(tid) for tid in ids] # 依次等待,总体 30 秒左右
异步接口同样支持图生图。参考图放在 image 字段,支持三种写法:
| 写法 | 示例 | 说明 |
|---|---|---|
| URL 字符串 | "image": "https://xxx/a.png" |
最常用,图片需公网可访问 |
| URL 数组 | "image": ["https://xxx/a.png", "https://xxx/b.png"] |
多张参考图 |
| base64 data URL | "image": "data:image/png;base64,iVBOR..." |
本地文件直接内联上传,单张 ≤ 4 MB |
请求示例(curl,参考图用 URL):
curl -X POST https://api.ideamine.cn/v1/images/async \
-H "Authorization: Bearer $KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2.5-sunburst",
"prompt": "把背景换成蓝色,保持主体不变",
"size": "1024x1024",
"image": "https://api.ideamine.cn/uploads/1/975489846acc4f8521c17d6eb5038001.png"
}'
返回里 mode 字段会标明这次是文生图还是图生图:
{"id":"imgtask_...","status":"queued","mode":"edit","poll":"/v1/images/async/imgtask_..."}
Python 示例(本地文件 → base64 内联上传):
import base64, time, requests
KEY = "sk-你的令牌"
BASE = "https://api.ideamine.cn"
HEAD = {"Authorization": f"Bearer {KEY}"}
with open("input.png", "rb") as f:
data_url = "data:image/png;base64," + base64.b64encode(f.read()).decode()
r = requests.post(f"{BASE}/v1/images/async", headers=HEAD, json={
"model": "gpt-image-2.5-sunburst",
"prompt": "换成水彩风格",
"size": "1024x1024",
"image": data_url,
}, timeout=60)
tid = r.json()["id"]
while True:
d = requests.get(f"{BASE}/v1/images/async/{tid}", headers=HEAD, timeout=20).json()
if d["status"] == "succeeded":
print(d["data"][0]["url"]); break
if d["status"] == "failed":
raise RuntimeError(d["error"]["message"])
time.sleep(3)
说明:
image为 data URL 时,服务端会先落盘到公网地址再交给模型,因此单张建议 ≤ 4 MB(base64 后约 5.3 MB),过大请改用 URL 方式。
把图片先传到我们的对象存储(传输加速),再拿 URL 提交任务。图片不经过 API 服务器,所以最快。
# 1) 换一个直传地址(0.5 秒)
curl -X POST https://api.ideamine.cn/v1/images/presign \
-H "Authorization: Bearer $KEY" -H "X-File-Ext: png"
# → {"upload_url":"https://depuyixin-img.oss-accelerate.aliyuncs.com/ref/xxx.png?签名",
# "url":"https://depuyixin-img.oss-cn-hongkong.aliyuncs.com/ref/xxx.png",
# "method":"PUT","headers":{"Content-Type":"application/octet-stream"},"expires_in":1800}
# 2) 直接 PUT 图片(1 MB 约 0.3 秒)
curl -X PUT -H "Content-Type: application/octet-stream" \
--data-binary @input.png "<upload_url>"
# 3) 用返回的 url 提交任务(0.3 秒)
curl -X POST https://api.ideamine.cn/v1/images/async \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-d '{"model":"gpt-image-2.5-sunburst","prompt":"换成浅色墙面",
"size":"1024x1024","image":"https://depuyixin-img.oss-cn-hongkong.aliyuncs.com/ref/xxx.png"}'
Python(可直接跑):
def upload_reference(path):
ext = path.rsplit(".", 1)[-1].lower()
s = requests.post(f"{BASE}/v1/images/presign",
headers={**HEAD, "X-File-Ext": ext}).json()
requests.put(s["upload_url"], data=open(path, "rb").read(),
headers=s["headers"]).raise_for_status()
return s["url"]
完整可运行脚本(含提交、轮询、下载):仓库内 docs/example-image-async.py。
| 方式 | 总耗时 | 说明 |
|---|---|---|
base64 内联在 image 字段 |
55–64 秒 | 只适合 <200 KB 的小图 |
上传到 POST /v1/images/upload |
约 14 秒 | 图片经我们服务器中转 |
/v1/images/presign + 直传 OSS |
约 1 秒 | 推荐 |
strict_reference图生图时,如果提示词把画面描述得很完整,模型可能「按文字重画」而丢掉参考图。
在请求里加一个开关,我们会在提示词前自动加上约束:
{
"model": "gpt-image-2.5-sunburst",
"prompt": "只把墙面改成奶油米白,床头板换成软包",
"size": "1024x1024",
"image": "https://.../ref.png",
"strict_reference": true
}
实际发给模型的提示词会变成:
以参考图为基础:严格保留参考图中的主体、构图、比例和透视关系,
只按下面要求做修改,其余元素一律保持原样。
只把墙面改成奶油米白,床头板换成软包
image 的请求生效| 模型 | 价格 | 支持图生图 |
|---|---|---|
gpt-image-2 |
¥0.019 / 张 | ✅ |
gpt-image-2.5 |
¥0.019 / 张 | ✅ |
gpt-image-2.5-flare |
¥0.019 / 张 | ✅ |
gpt-image-2.5-sunburst |
¥0.019 / 张 | ✅ |
qwen-image-2.0 |
见控制台 | ✅ |
Doubao-Seedream-4.5 / 5.0-lite |
见控制台 | ❌ |
Midjourney |
见控制台 | ❌ |
图生图用 POST /v1/images/edits(multipart,字段 image 传文件或 URL)。
| HTTP | 含义 | 处理 |
|---|---|---|
| 401 | 令牌无效/过期 | 检查 Authorization |
| 402/403 | 余额或额度不足 | 控制台充值 |
| 400 | 参数不对(缺 prompt、size 非法等) | 按 error.message 修正 |
| 429 | 请求过于频繁 | 降低并发,或改用异步 |
| 500/502/503 | 上游临时故障 | 重试(建议 3 次,间隔 2–5 秒) |
failed 且 error.message 含「超时 / 繁忙 / 502」时重试;内容审核类错误重试无用。