🐍
AI SDKs
Use Hanzo AI with OpenAI Python SDK
Use the official OpenAI Python SDK with Hanzo AI by pointing it to our OpenAI-compatible API endpoint. Access 390+ models with your existing OpenAI code — no refactor needed.
Base URL: https://api.hanzo.ai/v1
API Key: Get yours at hanzo.ai/signup · Fully OpenAI-compatible · 390+ models available
🐍
Created by OpenAI
License: MIT · View source on GitHub →
Hanzo AI is OpenAI-compatible, so existing OpenAI Python SDK code works with zero refactoring. We deeply appreciate the OpenAI team for building and maintaining this open-source project.
Install & configure
python
pip install openai
from openai import OpenAI
client = OpenAI(
api_key="your-hanzo-api-key",
base_url="https://api.hanzo.ai/v1",
)
response = client.chat.completions.create(
model="zen4-pro",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)Streaming
python
stream = client.chat.completions.create(
model="openai/gpt-4.1",
messages=[{"role": "user", "content": "Write a haiku"}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")Vision model
python
response = client.chat.completions.create(
model="google/gemini-2.0-flash",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{"type": "image_url", "image_url": {"url": "https://example.com/img.png"}},
],
}],
)Environment variable
bash
export HANZO_API_KEY="your-hanzo-api-key"
export OPENAI_API_KEY="$HANZO_API_KEY"
export OPENAI_BASE_URL="https://api.hanzo.ai/v1"Ready to get started?
Create a free account and get your API key. 100K API calls/month free forever.