最近自己在接 Yuan Image 文生图,按 OpenAI 兼容的 /images/generations 走了一遍,把步骤记下来,方便以后自己复用,也欢迎大家一起踩坑补充。

官方入口(只用这三个)

  • API / 对话:https://api.apixhm.com
  • 文生图:https://image.apixhm.com
  • 文档:https://doc.apixhm.com

1. 注册并创建 API Key

先到文档站 https://doc.apixhm.com 注册账号,在控制台创建 API Key。下文一律用 YOUR_KEY / 「你的Key」占位,不要把真实 Key 贴到帖子或仓库里。

2. 文生图不要走对话接口

重点: 图片生成不是 chat 接口。

  • Image Base URL:https://image.apixhm.com/v1
  • 方法与路径:POST /v1/images/generations(完整即 https://image.apixhm.com/v1/images/generations)
  • Header:Authorization: Bearer YOUR_KEY,Content-Type: application/json

对话继续用 https://api.apixhm.com/v1,两套 Base 不要混用。

3. 模型名与尺寸

模型名、支持的 size 以 https://image.apixhm.com 页面说明和 https://doc.apixhm.com 文档当时为准(会更新)。请求体大致是:

{
  "model": "按文档填写的模型名",
  "prompt": "a calm lakeside cabin at dusk, soft light",
  "size": "按文档填写,例如 1024x1024",
  "n": 1
}

4. 对话 vs 文生图 Base 对照

| 用途 | Base | |------|------| | Chat / 对话 | https://api.apixhm.com/v1 | | Image / 文生图 | https://image.apixhm.com/v1 |

切记:文生图不要打到 chat 的 Base,否则会 404 或鉴权/路由报错。

5. 最短 curl 示例(中性英文 prompt)

curl -s https://image.apixhm.com/v1/images/generations \
  -H "Authorization: Bearer YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "按文档填写的模型名",
    "prompt": "a calm lakeside cabin at dusk, soft light",
    "n": 1,
    "size": "1024x1024"
  }'

返回里一般会有图片 URL 或 b64,按文档字段解析即可。

小结

  1. Key 在文档站创建,用 YOUR_KEY 占位。
  2. 文生图 Base 是 https://image.apixhm.com/v1,路径 /images/generations。
  3. Chat 仍走 https://api.apixhm.com/v1,两套分开。
  4. 模型与 size 以 image / doc 站点当前说明为准。

如果你在客户端(Cherry Studio、Codex、自写脚本等)里接过 Yuan Image,欢迎留言分享超时、尺寸、模型名或鉴权方面的坑,互相少走弯路。