Skip to content

Python SDK

HiAPI is fully compatible with the OpenAI Python SDK. Just change the 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"
)

Or using environment variables:

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="dall-e-3",
prompt="a futuristic city at sunset",
size="1024x1024"
)
image_url = response.data[0].url
print(image_url)
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)

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())