ZhipuAI is the official Python SDK for accessing the large model APIs from ZhipuAI Open Platform. It provides a convenient, type-safe, and high-performance interface for interacting with ZhipuAI models like GLM series, supporting chat completions, embeddings, and other AI capabilities. The library maintains an active development status, with frequent updates indicated by its versioning scheme, reflecting ongoing enhancements and feature additions to the ZhipuAI platform.
pip install zhipuaiVerified import paths — ran on the pinned version, not inferred.
Initializes the ZhipuAI client using an API key (preferably from an environment variable) and performs a simple chat completion request with the 'glm-4' model.
Review the official SDK documentation for v4.x to update API key initialization and method calls, especially for `chat.completions.create` and error handling logic.
Monitor ZhipuAI official announcements for migration guides and consider adopting the `z-ai-sdk-python` when its features and stability meet project requirements.
Store your ZhipuAI API key in an environment variable (e.g., `ZHIPUAI_API_KEY`) and retrieve it using `os.environ.get('ZHIPUAI_API_KEY')`.Explicitly specify a supported model (e.g., 'glm-4') in your `client.chat.completions.create` call. Refer to ZhipuAI's model documentation for the latest available models.
Ensure that messages within tool-use sequences adhere to the expected format, avoiding empty user content where the schema requires it, or restructure message chains to normalize them before sending.