- Quickly migrate existing OpenAI applications
- Use familiar development patterns and tools
- Enjoy the powerful capabilities of Z.AI models
- Maintain code consistency and maintainability
Core Advantages
Zero Learning Cost
If you are already familiar with OpenAI SDK, you can start using it immediately
Quick Migration
Existing OpenAI applications can be quickly migrated to Z.AI platform
Ecosystem Compatibility
Compatible with various tools and frameworks in the OpenAI ecosystem
Continuous Updates
Follow OpenAI SDK updates to maintain latest feature support
Environment Requirements
Python Version
Python 3.7.1 or higher
OpenAI SDK
OpenAI SDK version 1.0.0 or higher
Install OpenAI Python SDK
Install using pip
Install using poetry
Quick Start
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.
Create Client
- Basic Configuration
- Environment Variables
- Configuration Class
Quick Start Examples
Basic Chat
Streaming Response
Multi-turn Conversation
Advanced Features
Thinking Mode
In thinking mode, GLM-4.6, GLM-4.5 and GLM-4.5-Air can solve complex reasoning problems, including mathematics, science, and logic problems. The paramthinking.type can be either enabled or disabled.
Function Calling
Parameter Configuration
Common Parameters
Note: The temperature parameter range is (0,1), do_sample = False (temperature = 0) is not applicable in OpenAI calls.
Best Practices
Performance Optimization
- Use connection pooling and session reuse
- Set reasonable timeout values
- Implement async calls for high concurrency
- Cache frequently used responses
Cost Control
- Set reasonable max_tokens limits
- Use appropriate models (don’t overuse powerful models)
- Implement request deduplication
- Monitor API usage
Security
- Use environment variables to store API keys
- Implement input validation and filtering
- Log and monitor API calls
- Rotate API keys regularly
Reliability
- Implement retry mechanisms and error handling
- Set reasonable timeout values
- Monitor API status and response times
- Prepare fallback solutions
Migration Guide
Migrating from OpenAI
If you’re already using OpenAI API, migrating to Z.AI is very simple:Getting Help
API Documentation
View complete API interface documentation
OpenAI Official Documentation
Refer to OpenAI official documentation for more usage
Z.AI is committed to maintaining compatibility with OpenAI API. If you encounter any issues during migration, please contact our technical support team.