Hanzo

TypeScript SDK

The official Hanzo TypeScript/JavaScript SDK for Node.js, Deno, and browsers.

TypeScript SDK

The @hanzo/ai package provides a type-safe TypeScript client for the Hanzo LLM Gateway, compatible with the OpenAI SDK interface.

Installation

npm install @hanzo/ai

Quick Start

import Hanzo from '@hanzo/ai';

const client = new Hanzo({ apiKey: 'your-api-key' });

const response = await client.chat.completions.create({
  model: 'gpt-4o',
  messages: [
    { role: 'user', content: 'Hello, world!' }
  ],
});

console.log(response.choices[0].message.content);

Streaming

const stream = await client.chat.completions.create({
  model: 'claude-sonnet-4-5-20250929',
  messages: [
    { role: 'user', content: 'Write a haiku about AI' }
  ],
  stream: true,
});

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

Function Calling

const tools = [
  {
    type: 'function' as const,
    function: {
      name: 'get_weather',
      description: 'Get the current weather for a location',
      parameters: {
        type: 'object',
        properties: {
          location: { type: 'string', description: 'City name' },
          unit: { type: 'string', enum: ['celsius', 'fahrenheit'] }
        },
        required: ['location']
      }
    }
  }
]

const response = await client.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: "What's the weather in Tokyo?" }],
  tools,
  tool_choice: 'auto',
})

const message = response.choices[0].message
if (message.tool_calls) {
  for (const call of message.tool_calls) {
    const args = JSON.parse(call.function.arguments)
    console.log(`Call ${call.function.name}(${JSON.stringify(args)})`)
  }
}

Multiple Providers

// OpenAI
await client.chat.completions.create({ model: 'gpt-4o', ... })

// Anthropic
await client.chat.completions.create({ model: 'claude-sonnet-4-5-20250929', ... })

// Google
await client.chat.completions.create({ model: 'gemini-2.0-flash', ... })

// Meta (via Groq)
await client.chat.completions.create({ model: 'groq/llama-3.1-70b', ... })

Configuration

const client = new Hanzo({
  apiKey: 'your-api-key',
  baseURL: 'https://llm.hanzo.ai/v1', // default
  timeout: 60_000,
  maxRetries: 2,
});

Environment Variables

HANZO_API_KEY=your-api-key
HANZO_BASE_URL=https://llm.hanzo.ai/v1  # optional

Resources

How is this guide?

Last updated on

On this page