Claude / OpenAI 兼容中转:本地客户端接 Yuan API + Yuan Image 分步
最近在本地客户端里同时跑 Claude 对话和文生图,踩了几次 base_url / 模型名的坑,记一版可复现步骤。## 1. 准备
- 中转文档:https://doc.apixhm.com
- 对话 API:https://api.apixhm.com
- 生图 API:https://image.apixhm.com
## 2. 对话(Claude,OpenAI 兼容)
Base URL 填 https://api.apixhm.com/v1 (有的客户端不要末尾 /v1);模型名以文档列表为准;API Key 填本地密钥。
from openai import OpenAI
client = OpenAI(base_url="https://api.apixhm.com/v1", api_key="YOUR_KEY")
r = client.chat.completions.create(
model="claude-sonnet-4-5",
messages=[{"role": "user", "content": "用三句话说明 OpenAI 兼容中转是什么"}],
)
print(r.choices.message.content)
## 3. 生图(Yuan Image)
文生图走 https://image.apixhm.com ;对话与生图域名不同,别混用。细节见 https://doc.apixhm.com 。
## 4. 常见问题
401:Key 或 Base URL 多/少了 /v1;模型不存在:换成文档当前可用名。
欢迎补充你们客户端的实际字段名。
页:
[1]