Core Advantages
Simple and Easy
Pythonic API design, comprehensive documentation and examples for quick start
Complete Features
Supports Z.AI’s full range of models, including language, vision, image generation, etc.
High Performance
Async support, connection pool management, optimized network request handling
Type Safety
Complete type hints, IDE-friendly, reducing development errors
Supported Features
- 💬 Chat Conversations: Support for single-turn and multi-turn conversations, streaming and non-streaming responses
- 🔧 Function Calling: Enable AI models to call your custom functions
- 👁️ Vision Understanding: Image analysis, visual understanding
- 🎨 Image Generation: Generate high-quality images from text descriptions
- 🎬 Video Generation: Creative content generation from text to video
- 🔊 Speech Processing: Speech-to-text, text-to-speech
- 📊 Text Embedding: Text vectorization, supporting semantic search
- 🤖 Intelligent Assistants: Build professional AI assistant applications
- 🛡️ Content Moderation: Text and image content safety detection
Technical Specifications
Environment Requirements
- Python Version: Python 3.8 or higher
- Package Manager: pip or poetry
- Network Requirements: HTTPS connection support
- API Key: Valid Z.AI API key required
Dependency Management
The SDK adopts a modular design, allowing you to selectively install functional modules as needed:- Core Module: Basic API calling functionality
- Async Module: Asynchronous and concurrent processing support
- Utility Module: Utility tools and auxiliary functions
Quick Start
Environment Requirements
Python Version
Python 3.8 or higher
Package Manager
poetry (recommended), uv (recommended), pip
Install SDK
Install using pip
Verify Installation
Get API Key
- Access Z.AI Open Platform, Register or Login.
- Create an API Key in the API Keys management page.
- Copy your API Key for use.
Domestic Z.AI platform uses ZaiClientDomestic API URL: https://api.z.ai/api/paas/v4/
Create Client
- Environment Variable
- Direct Setting
Basic Conversation
Streaming Conversation
Multi-turn Conversation
Complete Example
Error Handling
Advanced Configuration
Advanced Features
Function Calling
Function calling allows AI models to call functions you define to get real-time information or perform specific operations.Defining and Using Functions
Web Search Tool
Video Generation
Streaming Processing
Getting Help
GitHub Repository
View source code, submit issues, contribute
API Reference
View complete API documentation
Example Projects
Browse more practical application examples
Best Practices
Learn best practices for SDK usage
This SDK is developed based on the latest API specifications from Z.AI, ensuring synchronization with platform features. It is recommended to regularly update to the latest version for the best experience.