Hanzo
Hanzo Skills Reference

Hanzo JavaScript SDK

TypeScript-first client library for the Hanzo AI API, generated by Stainless with full type safety, streaming, auto-retry, and support for Node.js, Bun, Deno, and browsers.

Overview

Hanzo JS SDK is a TypeScript-first client library for the Hanzo AI API. Generated by Stainless for complete type safety and API coverage. Works in Node.js, Bun, Deno, and browsers with tree-shaking support.

Why Hanzo JS SDK?

  • Full type safety: Generated from OpenAPI spec via Stainless
  • OpenAI compatible: Same interface patterns, easy migration
  • Universal JS: Node.js, Bun, Deno, and browser support
  • Streaming: First-class SSE streaming with async iterators
  • Tree-shakable: Only import what you need
  • Auto-retry: Configurable retry with exponential backoff
  • Pagination: Auto-pagination helpers for list endpoints

OSS Base

Generated by Stainless. Repo: hanzoai/js-sdk.

When to use

  • TypeScript/JavaScript applications calling Hanzo API
  • Next.js, React, Vue, or Node.js projects
  • Browser-based AI applications
  • Replacing OpenAI SDK with Hanzo
  • Server-side API integration

Hard requirements

  1. Node.js 18+ (or Bun/Deno)
  2. HANZO_API_KEY for authentication
  3. TypeScript 4.7+ recommended

Quick reference

ItemValue
Packagehanzoai (npm)
Version0.1.0-alpha.2
Repogithub.com/hanzoai/js-sdk
Generated byStainless
LicenseApache-2.0
Node.js18+
TypeScript4.7+
Base URLhttps://api.hanzo.ai

Installation

# npm
npm install hanzoai

# pnpm (preferred)
pnpm add hanzoai

# yarn
yarn add hanzoai

# bun
bun add hanzoai

One-file quickstart

Chat Completion

import Hanzo from "hanzoai"

const client = new Hanzo({
  apiKey: process.env.HANZO_API_KEY,  // defaults to HANZO_API_KEY env var
  // baseURL: "https://api.hanzo.ai",  // default
})

const response = await client.chat.completions.create({
  model: "zen-70b",
  messages: [{ role: "user", content: "Hello, Hanzo!" }],
})
console.log(response.choices[0].message.content)

Streaming

const stream = await client.chat.completions.create({
  model: "zen-70b",
  messages: [{ role: "user", content: "Write a poem about code" }],
  stream: true,
})

for await (const chunk of stream) {
  const content = chunk.choices[0]?.delta?.content
  if (content) process.stdout.write(content)
}

Embeddings

const embedding = await client.embeddings.create({
  model: "zen-embedding",
  input: "Hello world",
})
console.log(embedding.data[0].embedding.length) // dimension count

Function Calling / Tools

const response = await client.chat.completions.create({
  model: "zen-70b",
  messages: [{ role: "user", content: "What's the weather in Tokyo?" }],
  tools: [{
    type: "function",
    function: {
      name: "get_weather",
      description: "Get current weather for a location",
      parameters: {
        type: "object",
        properties: {
          location: { type: "string", description: "City name" },
        },
        required: ["location"],
      },
    },
  }],
})

const toolCall = response.choices[0].message.tool_calls?.[0]
if (toolCall) {
  console.log(toolCall.function.name)       // "get_weather"
  console.log(toolCall.function.arguments)  // '{"location":"Tokyo"}'
}

Vision (Multimodal)

const response = await client.chat.completions.create({
  model: "zen-vision",
  messages: [{
    role: "user",
    content: [
      { type: "text", text: "What's in this image?" },
      { type: "image_url", image_url: { url: "https://example.com/photo.jpg" } },
    ],
  }],
})

API Surface

The SDK provides 187 endpoints across 51 resource namespaces, generated from the OpenAPI spec via Stainless.

Core Resources

ResourceMethodDescription
client.chat.completions.create()POSTChat completion (streaming optional)
client.completions.create()POSTText completion (legacy)
client.embeddings.create()POSTGenerate embeddings
client.models.list()GETList available models
client.models.retrieve(id)GETGet model details

File Management

MethodDescription
client.files.create()Upload a file
client.files.retrieve(id)Get file metadata
client.files.list()List uploaded files
client.files.del(id)Delete a file
client.files.content(id)Get file content

Fine-Tuning

MethodDescription
client.fineTuning.jobs.create()Create fine-tuning job
client.fineTuning.jobs.retrieve(id)Get job status
client.fineTuning.jobs.list()List all jobs
client.fineTuning.jobs.cancel(id)Cancel a job
client.fineTuning.jobs.listEvents(id)List job events

Images

MethodDescription
client.images.generate()Generate images
client.images.edit()Edit images

Audio

MethodDescription
client.audio.transcriptions.create()Speech-to-text
client.audio.translations.create()Audio translation
client.audio.speech.create()Text-to-speech

Additional Resource Namespaces

The SDK also includes namespaces for: assistants, threads, runs, batches, vector stores, model management, key management, team management, organization, budget, guardrails, credentials, and more (51 total).

Configuration

const client = new Hanzo({
  apiKey: "your-key",                    // Required (or HANZO_API_KEY env)
  baseURL: "https://api.hanzo.ai",       // Default
  timeout: 60_000,                       // Request timeout (ms)
  maxRetries: 2,                         // Auto-retry count
  defaultHeaders: { "X-Custom": "val" }, // Extra headers
  defaultQuery: { version: "2" },        // Extra query params
})

Environment Variables

HANZO_API_KEY=your-api-key          # Required
HANZO_BASE_URL=https://...          # Override base URL
HANZO_LOG=debug                     # Enable debug logging

Auth Header

The gateway accepts the API key via:

  • x-litellm-api-key: <key> (used by the SDK internally)

Sandbox Environment

// Use sandbox for testing
const client = new Hanzo({
  apiKey: process.env.HANZO_SANDBOX_KEY,
  baseURL: "https://api.sandbox.hanzo.ai",
})

OpenAI Drop-In Replacement

import OpenAI from "openai"

const client = new OpenAI({
  baseURL: "https://api.hanzo.ai/v1",
  apiKey: process.env.HANZO_API_KEY,
})
// Everything works — same API shape
const response = await client.chat.completions.create({
  model: "zen-70b",
  messages: [{ role: "user", content: "Hello" }],
})

Framework Integration

Next.js (App Router)

// app/api/chat/route.ts
import Hanzo from "hanzoai"

const client = new Hanzo()

export async function POST(req: Request) {
  const { messages } = await req.json()

  const stream = await client.chat.completions.create({
    model: "zen-70b",
    messages,
    stream: true,
  })

  return new Response(stream.toReadableStream(), {
    headers: { "Content-Type": "text/event-stream" },
  })
}

Vercel AI SDK

import { createOpenAI } from "@ai-sdk/openai"
import { streamText } from "ai"

const hanzo = createOpenAI({
  baseURL: "https://api.hanzo.ai/v1",
  apiKey: process.env.HANZO_API_KEY,
})

const result = await streamText({
  model: hanzo("zen-70b"),
  prompt: "Write a haiku",
})

Error Handling

import Hanzo, { APIError, RateLimitError } from "hanzoai"

try {
  const response = await client.chat.completions.create({ ... })
} catch (err) {
  if (err instanceof RateLimitError) {
    console.log("Rate limited, retry after:", err.headers?.["retry-after"])
  } else if (err instanceof APIError) {
    console.log("API error:", err.status, err.message)
  }
}

Pagination

// Auto-pagination
for await (const model of client.models.list()) {
  console.log(model.id)
}

// Manual pagination
const page = await client.models.list()
console.log(page.data)
if (page.hasNextPage()) {
  const next = await page.getNextPage()
}

Runtime Support

RuntimeSupportNotes
Node.js 18+FullPrimary target
BunFullNative fetch
DenoFullnpm: specifier
BrowserFullTree-shakable
Edge RuntimeFullCloudflare Workers, Vercel Edge
  • hanzo/hanzo-chat.md - API reference and model catalog
  • hanzo/python-sdk.md - Python equivalent
  • hanzo/go-sdk.md - Go equivalent
  • hanzo/rust-sdk.md - Rust equivalent (infrastructure SDK)

How is this guide?

Last updated on

On this page