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

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.

Get API key — Free
Setup providertypescript
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,
});
3 of 6 lines point at Hanzo

generateText

typescript

4 of 10 lines point at Hanzo
generateTexttypescript
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

4 of 15 lines point at Hanzo
Streaming route handlertypescript
// app/v1/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

useChat hooktypescript
"use client";
import { useChat } from "ai/react";
 
export default function Chat() {
  const { messages, input, handleSubmit, handleInputChange } = useChat({
    api: "/v1/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>
  );
}

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.

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.