跳转到内容
中文

Python SDK

HiAPI 完全兼容 OpenAI Python SDK。只需更改 base_url 即可。

Terminal window
pip install openai
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.hiapi.ai/v1"
)

或使用环境变量:

Terminal window
export OPENAI_API_KEY="YOUR_API_KEY"
export OPENAI_BASE_URL="https://api.hiapi.ai/v1"
from openai import OpenAI
client = OpenAI() # reads from env
response = client.images.generate(
model="qwen-image-2.0",
prompt="一张春季活动海报,包含中文标题",
size="2048x2048"
)
image_url = response.data[0].url
print(image_url)
import requests
response = requests.post(
"https://api.hiapi.ai/v1/chat/completions",
headers={
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
json={
"model": "Nano-Banana",
"stream": False,
"messages": [{"role": "user", "content": "draw a cute cat"}],
"extra_body": {
"google": {
"image_config": {"aspect_ratio": "1:1", "image_size": "1K"}
}
}
}
)
print(response.json()["choices"][0]["message"]["content"])

对于当前视频端点,请使用 requests

import requests
response = requests.post(
"https://api.hiapi.ai/v1/videos",
headers={
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
json={
"model": "wan2.7-t2v",
"prompt": "sunset timelapse over mountains",
"seconds": "5"
}
)
print(response.json())