▲
Frameworks
Use Hanzo AI with Vercel AI SDK
Use the Vercel AI SDK with Hanzo AI to build streaming AI UIs, chatbots, and generative interfaces in Next.js, React, and other frameworks.
Base URL: https://api.hanzo.ai/v1
API Key: Get yours at hanzo.ai/signup · Fully OpenAI-compatible · 390+ models available
▲
Created by Vercel
License: Apache-2.0 · View source on GitHub →
Hanzo AI is OpenAI-compatible, so existing Vercel AI SDK code works with zero refactoring. We deeply appreciate the Vercel team for building and maintaining this open-source project.
Setup provider
typescript
npm install ai @ai-sdk/openai
import { createOpenAI } from "@ai-sdk/openai";
const hanzo = createOpenAI({
baseURL: "https://api.hanzo.ai/v1",
apiKey: process.env.HANZO_API_KEY,
});generateText
typescript
import { generateText } from "ai";
import { createOpenAI } from "@ai-sdk/openai";
const hanzo = createOpenAI({
baseURL: "https://api.hanzo.ai/v1",
apiKey: process.env.HANZO_API_KEY,
});
const { text } = await generateText({
model: hanzo("zen4-pro"),
prompt: "Write a poem about AI",
});Streaming route handler
typescript
// app/api/chat/route.ts
import { streamText } from "ai";
import { createOpenAI } from "@ai-sdk/openai";
const hanzo = createOpenAI({
baseURL: "https://api.hanzo.ai/v1",
apiKey: process.env.HANZO_API_KEY,
});
export async function POST(req: Request) {
const { messages } = await req.json();
const result = streamText({
model: hanzo("zen4-pro"),
messages,
});
return result.toDataStreamResponse();
}useChat hook
typescript
"use client";
import { useChat } from "ai/react";
export default function Chat() {
const { messages, input, handleSubmit, handleInputChange } = useChat({
api: "/api/chat",
});
return (
<form onSubmit={handleSubmit}>
<input value={input} onChange={handleInputChange} />
<button type="submit">Send</button>
{messages.map((m) => <p key={m.id}>{m.content}</p>)}
</form>
);
}Ready to get started?
Create a free account and get your API key. 100K API calls/month free forever.