Skip to content
Try Hanzo
Language: English (United States)

Use Hanzo AI with Haystack

Build NLP pipelines and RAG systems with Haystack. Point OpenAIChatGenerator at api.hanzo.ai/v1, name a Hanzo model, and the pipeline runs unchanged.

Get API key — Free
Haystack + Hanzopython
pip install haystack-ai
 
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack.utils import Secret
 
generator = OpenAIChatGenerator(
    model="zen4-pro",
    api_key=Secret.from_token("your-hanzo-api-key"),
    api_base_url="https://api.hanzo.ai/v1",
)
 
messages = [ChatMessage.from_user("What is RAG?")]
result = generator.run(messages=messages)
2 of 11 lines point at Hanzo

RAG pipeline

python

2 of 15 lines point at Hanzo
RAG pipelinepython
from haystack import Pipeline
from haystack.components.builders import PromptBuilder
from haystack.components.generators.chat import OpenAIChatGenerator
 
prompt_template = """
Context: {% for doc in documents %}{{ doc.content }}{% endfor %}
Question: {{ question }}
Answer:
"""
 
pipeline = Pipeline()
pipeline.add_component("prompt", PromptBuilder(template=prompt_template))
pipeline.add_component("llm", OpenAIChatGenerator(
    model="zen4-pro",
    api_key=Secret.from_token("your-hanzo-api-key"),
    api_base_url="https://api.hanzo.ai/v1",
))

Embeddings

python

2 of 6 lines point at Hanzo
Embeddingspython
from haystack.components.embedders import OpenAITextEmbedder
 
embedder = OpenAITextEmbedder(
    model="openai/text-embedding-3-large",
    api_key=Secret.from_token("your-hanzo-api-key"),
    api_base_url="https://api.hanzo.ai/v1",
)

Install

bash

1 of 2 lines point at Hanzo
Installbash
pip install haystack-ai
export HANZO_API_KEY="your-hanzo-api-key"

Created by deepset.ai

License: Apache-2.0 · View source on GitHub →

Hanzo AI is OpenAI-compatible, so existing Haystack code works with zero refactoring. We deeply appreciate the deepset.ai 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.