大家好,之前写过 Node 里同时接 Claude/GPT、Cherry Studio,以及用 Codex 写服务再出图。这次单独补一份在 Node 里调用 Yuan Image 文生图的走法,接口是 OpenAI 兼容的 images generations。文档公开,密钥请自己申请,下面只用占位 sk-xxx。
相关地址: 对话:https://api.apixhm.com 生图:https://image.apixhm.com 文档:https://doc.apixhm.com
环境变量:
OPENAI_API_KEY=sk-xxx OPENAI_BASE_URL=https://api.apixhm.com/v1
简要步骤:
- 打开文档确认 Yuan Image 的路径、模型名和请求字段,在控制台申请自己的 key,替换 sk-xxx。
- 生图请求发到 https://image.apixhm.com ,按文档提交 prompt。
- 如需先用对话模型打草稿提示词,把 Base URL 设为 https://api.apixhm.com/v1 。
- 先用下面的小样例确认能出图,再接到自己的 Node 服务里。
curl 生图示例:
curl https://image.apixhm.com/v1/images/generations
-H "Authorization: Bearer sk-xxx"
-H "Content-Type: application/json"
-d '{"model":"yuan-image","prompt":"一只在终端前写 Node 服务的小猫,扁平插画,浅色背景","size":"1024x1024"}'
Node fetch 示例:
const res = await fetch("https://image.apixhm.com/v1/images/generations", { method: "POST", headers: { Authorization: "Bearer sk-xxx", "Content-Type": "application/json" }, body: JSON.stringify({ model: "yuan-image", prompt: "一只在终端前写 Node 服务的小猫,扁平插画,浅色背景", size: "1024x1024" }) }); console.log(await res.json());
模型名、字段和返回结构以文档为准。有问题欢迎回帖一起看。