๐
Languages
Use Hanzo AI with Python
Use Hanzo AI in Python with the official OpenAI SDK (fully compatible), the Anthropic SDK, or via HTTP with httpx/requests. Zero lock-in, standard interfaces.
Base URL: https://api.hanzo.ai/v1
API Key: Get yours at hanzo.ai/signup ยท Fully OpenAI-compatible ยท 390+ models available
๐
Created by Python Software Foundation
License: PSF License ยท View source on GitHub โ
Hanzo AI is OpenAI-compatible, so existing Python code works with zero refactoring. We deeply appreciate the Python Software Foundation team for building and maintaining this open-source project.
OpenAI SDK (recommended)
python
pip install openai
from openai import OpenAI
client = OpenAI(
base_url="https://api.hanzo.ai/v1",
api_key="your-hanzo-api-key",
)
response = client.chat.completions.create(
model="zen4-pro",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)httpx (raw HTTP)
python
import httpx, json
response = httpx.post(
"https://api.hanzo.ai/v1/chat/completions",
headers={"Authorization": "Bearer your-hanzo-api-key"},
json={
"model": "zen4-pro",
"messages": [{"role": "user", "content": "Hello!"}],
},
)
print(response.json()["choices"][0]["message"]["content"])Async with asyncio
python
import asyncio
from openai import AsyncOpenAI
client = AsyncOpenAI(
base_url="https://api.hanzo.ai/v1",
api_key="your-hanzo-api-key",
)
async def main():
response = await client.chat.completions.create(
model="zen4-pro",
messages=[{"role": "user", "content": "Hello async!"}],
)
print(response.choices[0].message.content)
asyncio.run(main())Environment setup
python
# .env
HANZO_API_KEY=your-hanzo-api-key
# Load in code
from dotenv import load_dotenv
import os
load_dotenv()
from openai import OpenAI
client = OpenAI(
base_url="https://api.hanzo.ai/v1",
api_key=os.environ["HANZO_API_KEY"],
)Ready to get started?
Create a free account and get your API key. 100K API calls/month free forever.