|
|
最近在把 Claude Code 和常见的 OpenAI 兼容客户端接到 Yuan API,顺手用 Yuan Image 出图,把接入方式记一下。
文档:https://doc.apixhm.com/
接口:https://api.apixhm.com
出图:https://image.apixhm.com
一、Claude Code 根地址
把根地址指到 Yuan API:
export ANTHROPIC_BASE_URL="https://api.apixhm.com"
export ANTHROPIC_AUTH_TOKEN="你的 Yuan API Key"
claude
二、OpenAI 兼容 /v1(Python)
from openai import OpenAI
client = OpenAI(
api_key="你的 Yuan API Key",
base_url="https://api.apixhm.com/v1",
)
resp = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "你好,简单介绍一下你自己"}],
)
print(resp.choices[0].message.content)
三、OpenAI 兼容 /v1(bash)
curl https://api.apixhm.com/v1/chat/completions \
-H "Authorization: Bearer 你的YuanAPIKey" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-4o","messages":[{"role":"user","content":"hello"}]}'
Yuan Image 出图可以把客户端的图片接口指到 https://image.apixhm.com ,路径以文档 https://doc.apixhm.com/ 为准。
欢迎交流踩坑。
|
|