源景 AI 开发者 API G2 / G2-PRO / N2 / N2-PRO · 图片与直接视频

Base:https://yuanjing-ai.com · Auth:Bearer yj_live_... · 主路径:① generations 生图 → ② tasks 返图 · Key 在「获取 Key」· 不含网站工作流(见 完整包

第一次接入?两步生图地图

用 HTTP 节点生成第一张图

适用于 Dify、扣子、n8n、Apifox、Postman 等支持 HTTP 请求的工作流或调试工具。

1. 创建 Key打开开发者中心创建 Key,保存到你的工作流密钥/凭据区。
2. 配置两张 HTTP 卡先创建任务,保存返回的 task_id;再查询同一个任务。
3. 把图片交给下游任务结束且有图片时,取 task.images[0].url

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 示例
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));
}

模型、比例、视频和完整接口在下方 API Reference;不要重新创建同一任务。

完整 API Reference

按需打开完整接口、参数和响应说明。首次打开才加载完整文档组件。