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

Use Hanzo AI with LlamaIndex

Use LlamaIndex with Hanzo AI to build powerful RAG applications, data agents, and query pipelines. Drop in Hanzo as your LLM provider with zero friction.

Get API key — Free
Basic setuppython
pip install llama-index llama-index-llms-openai
 
from llama_index.llms.openai import OpenAI
from llama_index.core import Settings
 
Settings.llm = OpenAI(
    model="zen4-pro",
    api_key="your-hanzo-api-key",
    api_base="https://api.hanzo.ai/v1",
)
2 of 8 lines point at Hanzo

RAG pipeline

python

4 of 16 lines point at Hanzo
RAG pipelinepython
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.llms.openai import OpenAI
from llama_index.embeddings.openai import OpenAIEmbedding
 
Settings.llm = OpenAI(
    model="zen4-pro",
    api_key="your-hanzo-api-key",
    api_base="https://api.hanzo.ai/v1",
)
Settings.embed_model = OpenAIEmbedding(
    api_key="your-hanzo-api-key",
    api_base="https://api.hanzo.ai/v1",
)
 
documents = SimpleDirectoryReader("./data").load_data()
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()
response = query_engine.query("What is in these docs?")

Chat engine

python

Chat enginepython
chat_engine = index.as_chat_engine(
    chat_mode="condense_plus_context",
    verbose=True,
)
response = chat_engine.chat("Tell me more about this topic")

Streaming query

python

Streaming querypython
streaming_response = query_engine.query(
    "Summarize the key points",
    streaming=True,
)
streaming_response.print_response_stream()

Created by LlamaIndex

License: MIT · View source on GitHub →

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