悬赏1资源点 未解决
最近用 Claude Code 走 Yuan API 的 OpenAI 兼容接口写代码,生图还是单独走 Yuan Image,按自己的踩坑记一版分步,方便以后复用,也欢迎一起补坑。
官方入口(只用这三个)
API / 对话与代码:https://api.apixhm.com
文生图:https://image.apixhm.com
文档:https://doc.apixhm.com
1. 写代码:走 OpenAI 兼容
Claude Code 或其他兼容工具里,对话/代码 Base 用 https://api.apixhm.com(多数客户端再拼 /v1,或按文档当时说明)。Key 自己在站点申请,下文一律写 YOUR_KEY,不要把真实 Key 贴到帖子或截图里。
以环境变量为例:
export OPENAI_API_KEY=YOUR_KEY
export OPENAI_BASE_URL=https://api.apixhm.com/v1
在 Claude Code 里填好 Base / Key / 模型后,先让它跑一个最小任务(比如打印 hello)确认能通。模型名以 https://doc.apixhm.com 和 https://api.apixhm.com 当时的列表为准(会更新)。
2. 生图:不要混用对话 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" }'
小结
对话/代码 Base 是 https://api.apixhm.com(或 /v1,看客户端)。
生图 Base 是 https://image.apixhm.com/v1,路径 /images/generations。
文档以 https://doc.apixhm.com 为准。
如果你在 Claude Code 或其他 OpenAI 兼容工具里接过 Yuan API / Yuan Image,欢迎留言分享鉴权、模型名或超时方面的经验。最近用 Claude Code 走 Yuan API 的 OpenAI 兼容接口写代码,生图还是单独走 Yuan Image,按自己的踩坑记一版分步,方便以后复用,也欢迎一起补坑。
官方入口(只用这三个)
API / 对话与代码:https://api.apixhm.com
文生图:https://image.apixhm.com
文档:https://doc.apixhm.com
1. 写代码:走 OpenAI 兼容
Claude Code 或其他兼容工具里,对话/代码 Base 用 https://api.apixhm.com(多数客户端再拼 /v1,或按文档当时说明)。Key 自己在站点申请,下文一律写 YOUR_KEY,不要把真实 Key 贴到帖子或截图里。
以环境变量为例:
export OPENAI_API_KEY=YOUR_KEY
export OPENAI_BASE_URL=https://api.apixhm.com/v1
在 Claude Code 里填好 Base / Key / 模型后,先让它跑一个最小任务(比如打印 hello)确认能通。模型名以 https://doc.apixhm.com 和 https://api.apixhm.com 当时的列表为准(会更新)。
2. 生图:不要混用对话 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" }'
小结
对话/代码 Base 是 https://api.apixhm.com(或 /v1,看客户端)。
生图 Base 是 https://image.apixhm.com/v1,路径 /images/generations。
文档以 https://doc.apixhm.com 为准。
如果你在 Claude Code 或其他 OpenAI 兼容工具里接过 Yuan API / Yuan Image,欢迎留言分享鉴权、模型名或超时方面的经验。
|
|