Python SDK
此内容尚不支持你的语言。
HiAPI is fully compatible with the OpenAI Python SDK. Just change the base_url.
Installation
Section titled “Installation”pip install openaifrom openai import OpenAI
client = OpenAI( api_key="YOUR_API_KEY", base_url="https://api.hiapi.ai/v1")Or using environment variables:
export OPENAI_API_KEY="YOUR_API_KEY"export OPENAI_BASE_URL="https://api.hiapi.ai/v1"from openai import OpenAIclient = OpenAI() # reads from envImage Generation
Section titled “Image Generation”response = client.images.generate( model="dall-e-3", prompt="a futuristic city at sunset", size="1024x1024")
image_url = response.data[0].urlprint(image_url)Chat Completions
Section titled “Chat Completions”response = client.chat.completions.create( model="gpt-4o", messages=[{"role": "user", "content": "Hello!"}])
print(response.choices[0].message.content)Video & Audio (requests)
Section titled “Video & Audio (requests)”For video and audio endpoints not covered by the OpenAI SDK, use 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())