🟦
Languages
Use Hanzo AI with TypeScript
Use Hanzo AI in TypeScript and Node.js with the OpenAI SDK, Vercel AI SDK, or raw fetch. Full type safety and async/streaming support.
Base URL: https://api.hanzo.ai/v1
API Key: Get yours at hanzo.ai/signup · Fully OpenAI-compatible · 390+ models available
🟦
Created by Microsoft
License: Apache-2.0 · View source on GitHub →
Hanzo AI is OpenAI-compatible, so existing TypeScript code works with zero refactoring. We deeply appreciate the Microsoft team for building and maintaining this open-source project.
OpenAI SDK
typescript
npm install openai
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.hanzo.ai/v1",
apiKey: process.env.HANZO_API_KEY,
});
const response = await client.chat.completions.create({
model: "zen4-pro",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0].message.content);Streaming
typescript
const stream = await client.chat.completions.create({
model: "zen4-pro",
messages: [{ role: "user", content: "Stream this" }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}Next.js API route
typescript
// app/api/generate/route.ts
import OpenAI from "openai";
import { NextResponse } from "next/server";
const client = new OpenAI({
baseURL: "https://api.hanzo.ai/v1",
apiKey: process.env.HANZO_API_KEY,
});
export async function POST(req: Request) {
const { prompt } = await req.json();
const response = await client.chat.completions.create({
model: "zen4-pro",
messages: [{ role: "user", content: prompt }],
});
return NextResponse.json(response.choices[0].message);
}List models
typescript
const models = await client.models.list();
console.log(`Available: ${models.data.length} models`);
models.data.slice(0, 5).forEach((m) => console.log(m.id));Ready to get started?
Create a free account and get your API key. 100K API calls/month free forever.