最近把 Claude 兼容接口接到 OpenAI 兼容中转上,用来写对话,顺手用 Yuan Image 出图,步骤很短,记一下方便以后复用。
相关入口(只用这三个):
官网 API:https://api.apixhm.com
文生图:https://image.apixhm.com
文档:https://doc.apixhm.com
说明:下面 Key 写成 YOUR_KEY;Claude 与生图型号以控制台或文档里实际开通的为准。对话 Base URL 记得带 /v1。
一、先测对话
对话接口:POST https://api.apixhm.com/v1/chat/completions
curl https://api.apixhm.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "文档中的 Claude 型号",
"messages": [
{"role": "user", "content": "用三句话介绍一次代码审查该看哪些地方"}
]
}'
模型名不要写死,去文档里选当前可用的 Claude 兼容型号。若返回 401 或 403,先核对 Key,以及是否开通了对应模型。
二、用对话模型写生图提示词,再调用 Yuan Image
文生图接口:POST https://image.apixhm.com/v1/images/generations
curl https://image.apixhm.com/v1/images/generations \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "文档中的生图型号",
"prompt": "A quiet workbench with a laptop and soft window light, photorealistic",
"n": 1,
"size": "1024x1024"
}'
成功时响应里一般会有图片 URL 或 b64 数据。生图型号同样以文档为准。
三、若在客户端里用
把对话 Base URL 设为 https://api.apixhm.com/v1 ,API Key 填 YOUR_KEY,模型选文档中的 Claude 型号;生图另走 https://image.apixhm.com/v1 。两个入口不要混用。
以上都是自己跑通的步骤,欢迎一起交流踩坑。
|