npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ai-sdk-zhipu

v0.0.2

Published

Zhipu AI provider for Vercel AI SDK with full V3 specification support

Readme

ai-sdk-zhipu

Zhipu AI (智谱AI) provider for Vercel AI SDK with full V3 specification support.

NPM Version License

Features

  • AI SDK V3 Compatible - Fully implements the Language Model Specification V3
  • Compatibility - Supports ai v5-v6, @ai-sdk/provider v3.x, @ai-sdk/openai-compatible v2.x
  • OpenAI-Compatible API - Uses Zhipu AI's OpenAI-compatible API format
  • All Latest Models - Supports GLM-4.7, GLM-4.6, GLM-4.5, GLM-4-Flash, and more
  • Streaming Support - Full support for streaming responses
  • Multi-modal - Supports vision models (GLM-4V series)
  • Tool Calling - Supports function/tool calling
  • TypeScript - Written in TypeScript with full type definitions

Installation

npm install ai-sdk-zhipu
# or
pnpm add ai-sdk-zhipu
# or
yarn add ai-sdk-zhipu
# or
bun add ai-sdk-zhipu

Setup

  1. Get your API key from open.bigmodel.cn
  2. Set the ZHIPU_API_KEY environment variable:
export ZHIPU_API_KEY=your-api-key-here

Or create a .env file:

ZHIPU_API_KEY=your-api-key-here

Quick Start

import { generateText } from 'ai';
import { zhipu } from 'ai-sdk-zhipu';

const result = await generateText({
  model: zhipu('glm-4.7'),
  prompt: 'Why is the sky blue?',
});

console.log(result.text);

Usage Examples

Streaming

import { streamText } from 'ai';
import { zhipu } from 'ai-sdk-zhipu';

const result = await streamText({
  model: zhipu('glm-4.7'),
  prompt: 'Write a short story about a robot.',
});

for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}

Multi-turn Conversations

import { generateText } from 'ai';
import { zhipu } from 'ai-sdk-zhipu';

const result = await generateText({
  model: zhipu('glm-4.7'),
  messages: [
    { role: 'system', content: 'You are a helpful assistant.' },
    { role: 'user', content: 'What is the capital of France?' },
    { role: 'assistant', content: 'The capital of France is Paris.' },
    { role: 'user', content: 'And what about Germany?' },
  ],
});

console.log(result.text);

Custom Configuration

import { createZhipu } from 'ai-sdk-zhipu';

const zhipu = createZhipu({
  baseURL: 'https://open.bigmodel.cn/api/paas/v4',
  apiKey: process.env.ZHIPU_API_KEY,
});

const result = await generateText({
  model: zhipu('glm-4.7'),
  prompt: 'Hello, world!',
});

Vision Models (Multi-modal)

import { generateText } from 'ai';
import { zhipu } from 'ai-sdk-zhipu';

const result = await generateText({
  model: zhipu('glm-4.6v'), // Vision model
  messages: [
    {
      role: 'user',
      content: [
        { type: 'text', text: 'What do you see in this image?' },
        { type: 'image', image: 'https://example.com/image.jpg' },
      ],
    },
  ],
});

console.log(result.text);

Tool Calling

import { generateText } from 'ai';
import { zhipu } from 'ai-sdk-zhipu';

const result = await generateText({
  model: zhipu('glm-4.7'),
  tools: {
    weather: {
      description: 'Get the weather for a location',
      parameters: {
        type: 'object',
        properties: {
          location: {
            type: 'string',
            description: 'The city and state',
          },
        },
        required: ['location'],
      },
    },
  },
  prompt: 'What is the weather in San Francisco?',
});

console.log(result.toolCalls);

Available Models

Text Models (文本模型)

| Model ID | Description | Context | Max Output | |----------|-------------|---------|------------| | glm-4.7 | Latest flagship model | 200K | 128K | | glm-4.6 | High-performance model | 200K | 128K | | glm-4.5 | Excellent performance | 128K | 96K | | glm-4-plus | Excellent performance | 128K | 4K | | glm-4-air-250414 | High cost-performance | 128K | 16K | | glm-4-long | Ultra-long input | 1M | 4K | | glm-4-flash-250414 | Free model | 128K | 16K | | glm-4.5-flash | Free model | 128K | 96K |

Vision Models (视觉模型)

| Model ID | Description | Context | Max Output | |----------|-------------|---------|------------| | glm-4.6v | Flagship vision reasoning | 128K | 32K | | glm-4.5v | Vision reasoning | 64K | 16K | | glm-4.6v-flash | Free vision model | 128K | 32K | | glm-4v-flash | Free vision model | 16K | 1K |

For the complete model list, see the official documentation.

Full Model ID List

The full typed list is maintained in src/zhipu-chat-setting.ts and mirrors the official model overview (including less common and legacy IDs such as glm-4, glm-4-airx, glm-4-flashx-250414, glm-4.1v-thinking, and glm-4-0520).

Configuration

Provider Settings

import { createZhipu } from 'ai-sdk-zhipu';

const zhipu = createZhipu({
  baseURL: 'https://open.bigmodel.cn/api/paas/v4', // optional
  apiKey: 'your-api-key', // optional, defaults to ZHIPU_API_KEY env var
  headers: { // optional custom headers
    'X-Custom-Header': 'value',
  },
});

Model Settings

await generateText({
  model: zhipu('glm-4.7', {
    temperature: 0.7,
    maxTokens: 1000,
    topP: 0.9,
    topK: 40,
    stopSequences: ['END'],
    presencePenalty: 0.5,
    frequencyPenalty: 0.5,
  }),
  prompt: 'Your prompt here',
});

API Reference

createZhipu(settings?)

Creates a Zhipu AI provider instance.

Parameters:

  • settings.baseURL (string) - Base URL for the API
  • settings.apiKey (string) - API key
  • settings.headers (Record<string, string>) - Custom headers

Returns: Zhipu AI provider instance

zhipu(modelId, settings?)

Default provider instance.

Parameters:

  • modelId (string) - Model ID (e.g., 'glm-4.7')
  • settings (object) - Model-specific settings

Documentation

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

Acknowledgments

Support


Note: This is an unofficial community provider. Zhipu AI is a trademark of Beijing Zhipu Huazhang Technology Co., Ltd.