Registry / llm-agents / zhipuai

zhipuai

JSON →
library2.1.5.20250825pypypiunverified

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 zhipuai
INSTALL
IMPORT
SIG · ZHIPUAI
Z
zhipuai
llm-agentspythonv2.1.5.20250825
Install
4.0s avg
Import
Disk
32MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.1.5.20250825 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 33.7MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 4.0s · import 0.000s · 33MB
32MB installed
● package 32MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ZhipuAI
from zhipuai import ZhipuAI
import zhipuai

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.

import os from zhipuai import ZhipuAI # It's recommended to set your API key as an environment variable (ZHIPUAI_API_KEY) # For quick testing, you can pass it directly, but avoid in production. api_key = os.environ.get('ZHIPUAI_API_KEY', 'YOUR_API_KEY_HERE') if api_key == 'YOUR_API_KEY_HERE': print("Warning: Please set the ZHIPUAI_API_KEY environment variable or replace 'YOUR_API_KEY_HERE'.") exit() client = ZhipuAI(api_key=api_key) try: response = client.chat.completions.create( model="glm-4", messages=[ {"role": "user", "content": "Hello, ZhipuAI!"} ] ) print("ZhipuAI Response:") print(response.choices[0].message.content) except Exception as e: print(f"An error occurred: {e}")
Debug
Known issues
breakingWhen upgrading from v3.x to v4.x (current major version), significant changes were introduced including simplified API key configuration, modified method signatures for improved type safety, and more specific exception types for error handling. Code written for v3.x will likely require adaptation.
fix
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.
affects: >=4.0.0
gotchaZhipuAI has released a new Python SDK, `z-ai-sdk-python`, and recommends using it for better, faster, and long-term support. While `zhipuai` is currently active, users should be aware of this future-oriented recommendation.
fix
Monitor ZhipuAI official announcements for migration guides and consider adopting the `z-ai-sdk-python` when its features and stability meet project requirements.
affects: All
gotchaAPI keys should never be hardcoded in your application. They are sensitive credentials and should be managed securely, ideally using environment variables.
fix
Store your ZhipuAI API key in an environment variable (e.g., `ZHIPUAI_API_KEY`) and retrieve it using `os.environ.get('ZHIPUAI_API_KEY')`.
affects: All
gotchaThe SDK might default to specific models in some integrations that could become deprecated or invalid over time, leading to 'Model does not exist' errors.
fix
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.
affects: All
gotchaUsing consecutive `tool_use`/`tool_result` chains with empty user content can result in 'API Error 1214 — Invalid message format'.
fix
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.
affects: All
Upgrade
Version history
2.1.5.20250825latest on PyPI · released Aug 25, 2025
Audit
Dependencies
pythonrequiredRequired Python version for the SDK.
httpxrequiredHTTP client for making API requests.
pydanticrequiredData validation and serialization for API models.
typing-extensionsrequiredEnhanced type hints support.
Agent activity
131 hits · last 30 days
node
122
Perplexity
1
OpenAI (training)
1
Resources
zhipuai — pip install zhipuai · libregistry