Z.ai API Integration for Python

Integrate Z.ai’s GLM models in Python using the adapter’s native chat, streaming, and reasoning interfaces.

All providers

Installation

Use Python 3.10–3.14 and run this command in your virtual environment.

python -m pip install llm-api-adapter==0.11.0 llm-api-adapter-zai==0.1.3

Authentication

Open Z.ai API Keys. Sign in to the Z.ai Open Platform and create a key for the general model API. Set the following in the terminal where you will run the example.

export ZAI_API_KEY="your-api-key"

Quickstart

Send a message

Save the example as chat.py and run python chat.py.

import os

from llm_api_adapter.models.messages.chat_message import UserMessage
from llm_api_adapter.universal_adapter import UniversalLLMAPIAdapter

adapter = UniversalLLMAPIAdapter(
    organization="zai",
    model="glm-5.3-flash",
    api_key=os.environ["ZAI_API_KEY"],
)

response = adapter.chat(
    messages=[UserMessage("Explain what an API is in one sentence.")],
    max_tokens=1024,
    timeout_s=60,
)
print(response.content)

Supported models

Registry snapshot

Prices are first-tier base rates from the adapter registry. Open a model for all tiers, cache rates, pricing schedules, and capability notes. Unknown means the registry has no value.

  • glm-5.3-flash

    Context tokens
    1,000,000
    Base input per million tokens
    0.15 USD
    Maximum output tokens
    131,072
    Base output per million tokens
    0.5 USD
    Reasoning
    Supported
    Image URLs
    Unknown
    PDF URLs
    Unsupported
    PDF bytes
    Unsupported
    JSON Schema output
    Unsupported
    Pydantic output
    Unsupported
  • glm-5.3-flashx

    Context tokens
    1,000,000
    Base input per million tokens
    0.37 USD
    Maximum output tokens
    131,072
    Base output per million tokens
    1.25 USD
    Reasoning
    Supported
    Image URLs
    Unknown
    PDF URLs
    Unsupported
    PDF bytes
    Unsupported
    JSON Schema output
    Unsupported
    Pydantic output
    Unsupported
  • glm-5.3-flashx-legal

    Context tokens
    1,000,000
    Base input per million tokens
    0.37 USD
    Maximum output tokens
    131,072
    Base output per million tokens
    1.25 USD
    Reasoning
    Supported
    Image URLs
    Unknown
    PDF URLs
    Unsupported
    PDF bytes
    Unsupported
    JSON Schema output
    Unsupported
    Pydantic output
    Unsupported

Provider-specific features and limitations

  • Use tool_choice="auto" for application function tools and omit parallel_tool_calls. The adapter rejects unsupported tool options before sending the request.
  • Pass the complete message history on every turn. Opt in to separate reasoning events with capture_reasoning=True.

Resources