The official Node.js SDK for ZhipuAI Open Platform Big Model API, enabling developers to easily integrate ZhipuAI's powerful AI capabilities into their Node.js applications.
- π Type-safe API: Complete TypeScript type definitions for excellent development experience
- π§ Easy Integration: Simple and intuitive API design for quick integration
- β‘ High Performance: Built with modern Node.js libraries for optimal performance
- π‘οΈ Secure: Built-in authentication and token management
- π¦ Lightweight: Minimal dependencies for easy project integration
- π Streaming Support: Full support for streaming response handling
- Node.js 14 or higher
- npm, yarn, or pnpm
npm install zhipuai-sdk-nodejs-v4
yarn add zhipuai-sdk-nodejs-v4
pnpm add zhipuai-sdk-nodejs-v4
This SDK uses the following core dependencies:
Library | Version |
---|---|
axios | ^1.6.7 |
jsonwebtoken | ^9.0.2 |
- Create a Client with your API key
- Call the desired API methods
import { ZhipuAI } from 'zhipuai-sdk-nodejs-v4';
// Use API key from environment variable
const ai = new ZhipuAI();
// Or pass API key directly
const ai = new ZhipuAI({
apiKey: 'your_api_key_here',
baseUrl: 'https://open.bigmodel.cn/api/paas/v4', // Optional, default value
timeout: 30000, // Optional, request timeout
cacheToken: true // Optional, whether to cache token
});
- Basic Chat
import { ZhipuAI } from 'zhipuai-sdk-nodejs-v4';
const dialogue = async () => {
const ai = new ZhipuAI();
const result = await ai.createCompletions({
model: "glm-4",
messages: [
{"role": "user", "content": "What is the relationship between ZhipuAI and ChatGLM?"}
],
stream: false
});
console.log(result);
};
dialogue();
- Basic Chat
import { ZhipuAI } from 'zhipuai-sdk-nodejs-v4';
const streamDialogue = async () => {
const ai = new ZhipuAI();
const stream = await ai.createCompletions({
model: "glm-4",
messages: [
{"role": "user", "content": "What is the relationship between ZhipuAI and ChatGLM?"}
],
stream: true
});
// Process streaming results
for await (const chunk of stream) {
console.log(chunk.toString());
}
};
streamDialogue();
This project is licensed under the MIT License - see the LICENSE file for details.
We welcome contributions! Please see our Contributing Guide for details.
- π Documentation: ZhipuAI Open Platform
- π Issues: GitHub Issues
- π¬ Community: ZhipuAI Developer Community
Note: This SDK is currently in active development. If you encounter any bugs or need additional features, please submit an issue.