Use Hanzo AI with DSPy
Use DSPy to program (not prompt) Hanzo AI models. DSPy's systematic approach to LM prompting works with any OpenAI-compatible provider.
Get API key — Freepip install dspy
import dspy
lm = dspy.LM(
model="openai/zen4-pro",
api_key="your-hanzo-api-key",
api_base="https://api.hanzo.ai/v1",
)
dspy.configure(lm=lm)
2 of 8 lines point at Hanzo
Signature and module
python
1 of 7 lines point at Hanzo
class QA(dspy.Signature):
"""Answer questions with short factual answers."""
question: str = dspy.InputField()
answer: str = dspy.OutputField(desc="often 1-3 sentences")
qa = dspy.Predict(QA)
response = qa(question="What is the Hanzo AI cloud?")
print(response.answer)
Chain of thought
python
class CoTQA(dspy.Signature):
"""Answer with step-by-step reasoning."""
question: str = dspy.InputField()
reasoning: str = dspy.OutputField(desc="think step by step")
answer: str = dspy.OutputField()
cot = dspy.ChainOfThought(CoTQA)
result = cot(question="Why is AI important for developers?")
Optimization with MIPROv2
python
from dspy.teleprompt import MIPROv2
teleprompter = MIPROv2(metric=my_metric, auto="medium")
optimized = teleprompter.compile(program, trainset=train_data)
Created by Stanford NLP / Omar Khattab
License: MIT · View source on GitHub →
Hanzo AI is OpenAI-compatible, so existing DSPy code works with zero refactoring. We deeply appreciate the Stanford NLP / Omar Khattab team for building and maintaining this open-source project.
Ready to get started?
Create a free account and get your API key. The Free plan includes free model requests and Kai decisions, no card.

