最近把 Claude 对话接到 Yuan API 的兼容接口上,生图另走 Yuan Image,按自己的踩坑记一版分步说明,方便以后复用,也欢迎一起补坑。

官方入口(只用这三个)

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

  • 对话:Claude 兼容或 OpenAI 兼容都可以

对话 Base 用 https://api.apixhm.com(多数客户端再拼 /v1,或按文档当时说明)。Key 自己在站点申请,下文一律写 YOUR_KEY,不要把真实 Key 贴到帖子或截图里。

以环境变量为例(把 API Key 写在 Base URL 前面):

export ANTHROPIC_API_KEY=YOUR_KEY export ANTHROPIC_BASE_URL=https://api.apixhm.com

如果客户端走 OpenAI 兼容协议,则用:

export OPENAI_API_KEY=YOUR_KEY export OPENAI_BASE_URL=https://api.apixhm.com/v1

模型名以 https://doc.apixhm.com 和 https://api.apixhm.com 当时的列表为准(会更新)。在 Claude 客户端或兼容工具里填好 Base / Key / 模型后,先发一句「你好」确认能通。

  1. 生图:不要混用对话 Base

文生图走 Yuan Image,不要把对话的 Base 拿去出图。

  • 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

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

{ "model": "按文档填写的模型名", "prompt": "a red apple on a wooden table, soft daylight", "size": "按文档填写,例如 1024x1024", "n": 1 }

一次 curl 示例:

curl -s https://image.apixhm.com/v1/images/generations \ -H "Authorization: Bearer YOUR_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "按文档填写的模型名", "prompt": "a red apple on a wooden table, soft daylight", "n": 1, "size": "1024x1024" }'

  1. 小结

  2. 对话 Base 是 https://api.apixhm.com(或 /v1,看客户端)。

  3. 生图 Base 是 https://image.apixhm.com/v1,路径 /images/generations。
  4. 文档以 https://doc.apixhm.com 为准。

如果你在 Claude 客户端、Claude Code 或其他兼容工具里接过 Yuan API / Yuan Image,欢迎留言分享鉴权、模型名或超时方面的坑。