Y
Member
Yuan API 是 OpenAI 兼容网关,可切 Claude / GPT 等模型;文档见 https://doc.apixhm.com 。
对话 Base:https://api.apixhm.com
生图 Base:https://image.apixhm.com
## 1. 对话(Claude 兼容名,以文档为准)
```python
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["API_KEY"],
base_url="https://api.apixhm.com/v1",
)
r = client.chat.completions.create(
model="claude-sonnet-4-20250514",
messages=[{"role": "user", "content": "用三句话说明 OpenAI 兼容接口"}],
)
print(r.choices[0].message.content)
```
## 2. 文生图(Yuan Image)
```python
img = client.images.generate(
model="flux",
prompt="flat illustration of a coffee cup, soft light",
size="1024x1024",
)
# 若 SDK 指向对话 base,可另建 client(base_url="https://image.apixhm.com/v1")
print(img.data[0].url if hasattr(img.data[0], "url") else img)
```
密钥只放环境变量;模型名与路径以 https://doc.apixhm.com 为准。自用实测可用,欢迎交流。
对话 Base:https://api.apixhm.com
生图 Base:https://image.apixhm.com
## 1. 对话(Claude 兼容名,以文档为准)
```python
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["API_KEY"],
base_url="https://api.apixhm.com/v1",
)
r = client.chat.completions.create(
model="claude-sonnet-4-20250514",
messages=[{"role": "user", "content": "用三句话说明 OpenAI 兼容接口"}],
)
print(r.choices[0].message.content)
```
## 2. 文生图(Yuan Image)
```python
img = client.images.generate(
model="flux",
prompt="flat illustration of a coffee cup, soft light",
size="1024x1024",
)
# 若 SDK 指向对话 base,可另建 client(base_url="https://image.apixhm.com/v1")
print(img.data[0].url if hasattr(img.data[0], "url") else img)
```
密钥只放环境变量;模型名与路径以 https://doc.apixhm.com 为准。自用实测可用,欢迎交流。

