HTTP 节点卡 1
创建图片任务
把响应里的 task_id 保存为工作流变量,交给下一张卡。
- Method
POST
- URL
https://yuanjing-ai.com/api/v1/images/generations
- 认证
Authorization: Bearer 你的 API Key
- Header
Content-Type: application/json
- 输出
- 保存响应中的
task_id
{
"model": "gpt-image-2.0",
"prompt": "白底商品静物",
"aspect_ratio": "1:1",
"image_size": "1K",
"n": 1
}
HTTP 节点卡 2
查询并取得图片
未结束就等待指定秒数后继续查同一个 task_id,不要重发创建请求。
- Method
GET
- URL
https://yuanjing-ai.com/api/v1/tasks/{task_id}
- 认证
Authorization: Bearer 你的 API Key
- 未结束
task.terminal_status=false:等待 task.poll_after_seconds 秒后再查
- 拿图片
task.terminal_status=true 且有 task.images[0].url
自己写程序?展开 JavaScript、cURL、Python 示例
curl https://yuanjing-ai.com/api/v1/images/generations \
-H "Authorization: Bearer $YUANJING_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-image-2.0","prompt":"白底商品静物","aspect_ratio":"1:1","image_size":"1K","n":1}'
# 复制返回的 task_id,再查询:
curl https://yuanjing-ai.com/api/v1/tasks/TASK_ID \
-H "Authorization: Bearer $YUANJING_API_KEY"
# task.terminal_status 为 true 且有 images[0].url 时,取图片链接
const key = process.env.YUANJING_API_KEY;
const base = 'https://yuanjing-ai.com';
const headers = { Authorization: `Bearer ${key}`, 'Content-Type': 'application/json' };
const createdResponse = await fetch(`${base}/api/v1/images/generations`, {
method: 'POST', headers,
body: JSON.stringify({ model: 'gpt-image-2.0', prompt: '白底商品静物', aspect_ratio: '1:1', image_size: '1K', n: 1 })
});
const created = await createdResponse.json();
if (!createdResponse.ok) throw new Error(created.error_code || '创建任务失败');
for (;;) {
const response = await fetch(`${base}/api/v1/tasks/${created.task_id}`, { headers });
const result = await response.json();
if (!response.ok) throw new Error(result.error_code || '查询任务失败');
const task = result.task;
if (task.terminal_status) {
if (task.images[0]?.url) { console.log(task.images[0].url); break; }
throw new Error(task.error_code || `任务未返回图片:${task.status}`);
}
await new Promise(resolve => setTimeout(resolve, (task.poll_after_seconds || 5) * 1000));
}
import os, time, requests
headers = {"Authorization": f"Bearer {os.environ['YUANJING_API_KEY']}"}
created_response = requests.post("https://yuanjing-ai.com/api/v1/images/generations", headers=headers, json={
"model": "gpt-image-2.0", "prompt": "白底商品静物", "aspect_ratio": "1:1", "image_size": "1K", "n": 1
})
created_response.raise_for_status()
created = created_response.json()
while True:
response = requests.get(f"https://yuanjing-ai.com/api/v1/tasks/{created['task_id']}", headers=headers)
response.raise_for_status()
task = response.json()["task"]
if task["terminal_status"]:
if task["images"] and task["images"][0].get("url"):
print(task["images"][0]["url"])
break
raise RuntimeError(task.get("error_code") or f"任务未返回图片:{task['status']}")
time.sleep(task.get("poll_after_seconds") or 5)