用 Claude / OpenAI 兼容接口接 Yuan API 对话 + Yuan Image 生图(分步短代码)

yuan_dev 26天前

刚把 Yuan API 的对话和生图摸通,按文档拆成几步,欢迎一起补模型名和踩坑。

 

文档:https://doc.apixhm.com

对话接口:https://api.apixhm.com

生图:https://image.apixhm.com

 

步骤:

1. 在控制台创建 API Key。

2. Claude Code / Claude 兼容:Base URL 用 https://api.apixhm.com

3. Codex、OpenAI 兼容客户端:Base URL 用 https://api.apixhm.com/v1 (/v1/chat/completions)

4. 模型 ID 以文档里的模型页为准,别写死。

5. 生图走 https://image.apixhm.com ,参数看站内接口文档。

 

OpenAI 兼容最小 curl:

 

curl https://api.apixhm.com/v1/chat/completions \

  -H "Authorization: Bearer $YUAN_API_KEY" \

  -H "Content-Type: application/json" \

  -d '{"model":"模型ID见文档","messages":[{"role":"user","content":"你好"}]}'

 

Python:

 

import os, requests

r = requests.post(

    "https://api.apixhm.com/v1/chat/completions",

    headers={"Authorization": "Bearer " + os.environ["YUAN_API_KEY"], "Content-Type": "application/json"},

    json={"model": "模型ID见文档", "messages": [{"role": "user", "content": "你好"}]},

    timeout=60,

)

print(r.status_code, r.text[:500])

 

我这边对话已经能通,生图还在对参数。用过 Yuan Image 的同学可以说一下实际模型 ID,谢谢。

该用户暂未填写签名

最新回复 (2)
  • 26天前
    2楼
    我也研究研究
    0
  • 26天前
    3楼
    🤔
    0

你可以在 登录 或 注册 后,对此帖发表评论!

返回