Zhipu AI Provider

Access Zhipu AI's GLM family of models through the Anthropic-compatible API. Includes GLM-5, GLM-4.7 with native chain-of-thought reasoning, and cost-effective flash variants.

Provider Namezhipuai
Moduleshared.plugins.model_provider.zhipuai
SDKanthropic (Anthropic-compatible API)
AuthAPI key

Highlights

  • GLM-5 - Flagship MoE model with agentic engineering focus
  • Extended thinking - Native chain-of-thought on GLM-5 and GLM-4.7
  • 200K context - Large context windows on flagship models
  • Dynamic model discovery - New models appear automatically
  • Function calling - Full tool use support via Anthropic-compatible API
API Compatibility
Zhipu AI exposes an Anthropic-compatible API endpoint. The provider extends AnthropicProvider and inherits all message handling, streaming, and converter logic.
Quick start
from jaato import JaatoClient

client = JaatoClient(provider_name="zhipuai")
client.connect(
    project=None,
    location=None,
    model="glm-5"
)
client.configure_tools(registry)

response = client.send_message(
    "Hello from GLM!",
    on_output=on_output
)
With extended thinking
from shared import load_provider, ProviderConfig

provider = load_provider("zhipuai")
provider.initialize(ProviderConfig(
    api_key="your-key",
    extra={
        'enable_thinking': True,
        'thinking_budget': 10000
    }
))
provider.connect("glm-5")

response = provider.send_message("Complex question")
print(f"Thinking: {response.thinking}")
print(f"Answer: {response.text}")

Available Models

Flagship Models (200K context)

ModelContextThinkingNotes
glm-5 200K Yes Flagship MoE, agentic focus
glm-4.7 200K Yes Native chain-of-thought
glm-4.7-flash 200K No Fast inference
glm-4.7-flashx 200K No Ultra-fast inference
glm-4.6 200K No Previous flagship, strong coding

Balanced Models (128K context)

ModelContextNotes
glm-4.5 128K Balanced reasoning and coding
glm-4.5-air 128K Lightweight, cost-effective
glm-4.5-airx 128K Lightweight variant
glm-4.5-flash 128K Free tier variant
glm-4.5-x 128K Extended variant
Dynamic Discovery
The provider automatically discovers new models via Z.AI's OpenAI-compatible /models endpoint. Newly released models appear without provider updates.
List available models
provider = load_provider("zhipuai")
provider.initialize(ProviderConfig(api_key="your-key"))

# Dynamic discovery (queries Z.AI API)
models = provider.list_models()
print(models)
# ['glm-4.5', 'glm-4.5-air', 'glm-4.5-airx',
#  'glm-4.5-flash', 'glm-4.5-x', 'glm-4.6',
#  'glm-4.7', 'glm-4.7-flash', 'glm-4.7-flashx',
#  'glm-5']

# Filter by prefix
flash_models = provider.list_models(prefix="glm-4.7")
print(flash_models)
# ['glm-4.7', 'glm-4.7-flash', 'glm-4.7-flashx']
Connect to a model
# Flagship model with thinking
provider.connect("glm-5")

# Fast inference
provider.connect("glm-4.7-flash")

# Cost-effective
provider.connect("glm-4.5-flash")

Authentication

Zhipu AI uses API key authentication. Keys can be obtained from the Z.AI platform.

Get Your API Key

Credential Priority

PrioritySource
1 (highest) ZHIPUAI_API_KEY environment variable
2 api_key in ProviderConfig
3 Stored credentials (.jaato/zhipuai_auth.json)

Credential Storage

Credentials are stored in JSON files with Unix permissions 0600:

  • Project: .jaato/zhipuai_auth.json (if .jaato/ exists)
  • User: ~/.jaato/zhipuai_auth.json (fallback)
Environment variable
# .env file
ZHIPUAI_API_KEY=your-api-key
JAATO_PROVIDER=zhipuai
ZHIPUAI_MODEL=glm-5
Interactive login (TUI)
# Login - validates and stores your API key
zhipuai-auth login

# Check status
zhipuai-auth status

# Logout - clears stored credentials
zhipuai-auth logout
Programmatic login
from shared.plugins.model_provider.zhipuai import (
    login_with_key,
    validate_api_key,
)

# Validate and store
creds = login_with_key(
    api_key="your-key",
    on_message=lambda msg: print(msg)
)

# Or just validate
valid, detail = validate_api_key("your-key")
print(f"Valid: {valid}")

Extended Thinking

GLM-5 and GLM-4.7 (non-flash variants) support native chain-of-thought reasoning. When enabled, the model shows its reasoning process before producing a final answer.

Supported Models

ModelThinking Support
glm-5Yes
glm-4.7Yes
glm-4.7-flashNo
glm-4.7-flashxNo
glm-4.6No
glm-4.5*No

Configuration

OptionTypeDefaultDescription
enable_thinking bool False Enable chain-of-thought reasoning
thinking_budget int 10000 Max tokens for thinking
Enable via config
provider.initialize(ProviderConfig(
    api_key="your-key",
    extra={
        'enable_thinking': True,
        'thinking_budget': 15000
    }
))
provider.connect("glm-5")
Enable via environment
# .env file
ZHIPUAI_ENABLE_THINKING=true
ZHIPUAI_THINKING_BUDGET=15000
Access thinking in response
response = provider.send_message(
    "Analyze the trade-offs of this architecture"
)

if response.has_thinking:
    print("=== Reasoning ===")
    print(response.thinking)
    print()

print("=== Answer ===")
print(response.text)

Configuration

Environment Variables

VariableDefaultDescription
ZHIPUAI_API_KEY - API key (required)
ZHIPUAI_BASE_URL https://api.z.ai/api/anthropic API base URL
ZHIPUAI_MODEL glm-4.7 Default model name
ZHIPUAI_CONTEXT_LENGTH Per-model Override context window size
ZHIPUAI_ENABLE_THINKING false Enable extended thinking
ZHIPUAI_THINKING_BUDGET 10000 Max thinking tokens

ProviderConfig.extra Options

KeyTypeDefaultDescription
base_url str See env Override API base URL
context_length int Per-model Override context window
enable_thinking bool False Enable chain-of-thought
thinking_budget int 10000 Max thinking tokens
Base URL
The default endpoint is https://api.z.ai/api/anthropic. Do not include /v1 in the base URL — the Anthropic SDK appends it internally.
Full .env example
# .env
JAATO_PROVIDER=zhipuai
ZHIPUAI_API_KEY=your-api-key
ZHIPUAI_MODEL=glm-5
ZHIPUAI_ENABLE_THINKING=true
ZHIPUAI_THINKING_BUDGET=10000
Full programmatic config
from shared import load_provider, ProviderConfig

provider = load_provider("zhipuai")
provider.initialize(ProviderConfig(
    api_key="your-key",
    extra={
        'base_url': 'https://api.z.ai/api/anthropic',
        'context_length': 204800,
        'enable_thinking': True,
        'thinking_budget': 10000,
    }
))

provider.connect("glm-5")

provider.create_session(
    system_instruction="You are a helpful assistant.",
    tools=[...]
)

response = provider.send_message("Hello!")
print(response.text)

Function Calling

Zhipu AI supports function calling through the Anthropic-compatible API. Tool schemas are automatically converted to the correct format by the inherited Anthropic provider logic.

Supported Features

  • Parallel tool calls
  • Tool result streaming
  • Automatic schema conversion
Prompt Caching
Prompt caching is not supported by Zhipu AI's Anthropic-compatible endpoint. The provider automatically disables caching regardless of configuration.
Function calling example
from jaato import JaatoClient

client = JaatoClient(provider_name="zhipuai")
client.connect(None, None, "glm-5")
client.configure_tools(registry)

# Model will use tools as needed
response = client.send_message(
    "List the files in the current directory",
    on_output=on_output
)
# Model calls list_files tool

Error Handling

The provider includes Zhipu AI-specific error interpretation with actionable messages.

ExceptionCause
ZhipuAIAPIKeyNotFoundError No API key in env, config, or stored credentials
ZhipuAIConnectionError Auth failure (401/403) or connection issue
RuntimeError Rate limit (429) or model not found (404)
Handle errors
from shared.plugins.model_provider.zhipuai import (
    ZhipuAIAPIKeyNotFoundError,
    ZhipuAIConnectionError,
)

try:
    provider.initialize(config)
    provider.send_message("Hello")
except ZhipuAIAPIKeyNotFoundError:
    print("Set ZHIPUAI_API_KEY or run: zhipuai-auth login")
except ZhipuAIConnectionError as e:
    print(f"Connection failed: {e}")
except RuntimeError as e:
    if "rate limit" in str(e).lower():
        print("Rate limited, retry later")
    elif "not found" in str(e).lower():
        print("Invalid model name")

Corporate Proxy Support

The provider supports corporate proxy environments including:

  • HTTP/HTTPS proxies via standard environment variables
  • Custom CA certificate bundles
  • Kerberos/SPNEGO proxy authentication

Configuration uses the same proxy settings as other jaato providers. See the Proxy & Kerberos guide for details.

Proxy configuration
# Standard proxy
export HTTPS_PROXY=http://proxy.corp.com:8080

# Corporate CA bundle
export REQUESTS_CA_BUNDLE=/path/to/ca-bundle.crt

# Kerberos proxy auth
export JAATO_KERBEROS_PROXY=true