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

Use Hanzo AI with LangChain

Integrate LangChain with Hanzo AI to build chains, agents, and RAG pipelines using any model on Hanzo's gateway. Hanzo is OpenAI-compatible so ChatOpenAI just works.

Get API key — Free
LangChain Pythonpython
pip install langchain langchain-openai
 
from langchain_openai import ChatOpenAI
 
llm = ChatOpenAI(
    model="zen4-pro",
    openai_api_key="your-hanzo-api-key",
    openai_api_base="https://api.hanzo.ai/v1",
)
 
response = llm.invoke("What is the capital of France?")
print(response.content)
2 of 9 lines point at Hanzo

Chain with prompt

python

2 of 10 lines point at Hanzo
Chain with promptpython
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
 
prompt = ChatPromptTemplate.from_template("Summarize: {text}")
llm = ChatOpenAI(
    model="openai/gpt-4.1-mini",
    openai_api_key="your-hanzo-api-key",
    openai_api_base="https://api.hanzo.ai/v1",
)
chain = prompt | llm
result = chain.invoke({"text": "LangChain is a framework..."})

LangChain TypeScript

typescript

2 of 9 lines point at Hanzo
LangChain TypeScripttypescript
import { ChatOpenAI } from "@langchain/openai";
 
const model = new ChatOpenAI({
  modelName: "zen4-pro",
  openAIApiKey: process.env.HANZO_API_KEY,
  configuration: {
    baseURL: "https://api.hanzo.ai/v1",
  },
});
 
const response = await model.invoke("Hello!");

RAG with Hanzo

python

4 of 11 lines point at Hanzo
RAG with Hanzopython
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
 
embeddings = OpenAIEmbeddings(
    openai_api_key="your-hanzo-api-key",
    openai_api_base="https://api.hanzo.ai/v1",
    model="openai/text-embedding-3-large",
)
 
llm = ChatOpenAI(
    model="zen4-pro",
    openai_api_key="your-hanzo-api-key",
    openai_api_base="https://api.hanzo.ai/v1",
)

Created by LangChain AI

License: MIT · View source on GitHub →

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