Skip to main content
Z.AI Python SDK is the official Python development toolkit provided by Z.AI, offering Python developers convenient and efficient AI model integration solutions.

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
Supports Python 3.8, 3.9, 3.10, 3.11, 3.12 versions, cross-platform compatible with Windows, macOS, Linux

Install SDK

Install using pip

Verify Installation

Get API Key

  1. Access Z.AI Open Platform, Register or Login.
  2. Create an API Key in the API Keys management page.
  3. Copy your API Key for use.
It is recommended to set the API Key as an environment variable: export ZAI_API_KEY=your-api-key
Domestic Z.AI platform uses ZaiClientDomestic API URL: https://api.z.ai/api/paas/v4/

Create Client

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.