Z.AI GLM Coding Plan Setup
This guide walks you through setting up Z.AI GLM Coding Plan as an LLM provider in Crucible.
What is Z.AI GLM Coding Plan?
Section titled “What is Z.AI GLM Coding Plan?”Z.AI offers a GLM Coding Plan that provides two API endpoints for use with Crucible:
-
Native ZAI endpoint (recommended): An OpenAI-compatible API at
https://api.z.ai/api/coding/paas/v4. You use GLM model names likeGLM-4.7directly. Configure withtype = "zai". -
Anthropic proxy endpoint (alternative): An Anthropic-compatible API at
https://api.z.ai/api/anthropic. You send requests using Claude model names (e.g.,claude-sonnet-4-20250514), and Z.AI maps them to equivalent GLM models. Configure withtype = "anthropic".
Both endpoints use the same auth token via the x-api-key header.
Prerequisites
Section titled “Prerequisites”- Crucible CLI installed
- Z.AI GLM Coding Plan account with auth token
Step 1: Get Your Auth Token
Section titled “Step 1: Get Your Auth Token”- Log in to your Z.AI account
- Navigate to your API credentials or settings
- Copy your GLM Coding Plan auth token (typically 49 characters)
Step 2: Set the Environment Variable
Section titled “Step 2: Set the Environment Variable”export GLM_AUTH_TOKEN="your-token-here"Add this to your shell profile (~/.bashrc, ~/.zshrc, etc.) to persist across sessions.
Step 3: Configure the Provider
Section titled “Step 3: Configure the Provider”Add to your crucible.toml or llm_providers.toml.
Native ZAI (recommended):
[llm]default = "zai-coding"
[llm.providers.zai-coding]type = "zai"endpoint = "https://api.z.ai/api/coding/paas/v4"api_key = "{env:GLM_AUTH_TOKEN}"default_model = "GLM-4.7"temperature = 0.7max_tokens = 4096Anthropic proxy (alternative):
[llm.providers.zai-anthropic]type = "anthropic"endpoint = "https://api.z.ai/api/anthropic"api_key = "{env:GLM_AUTH_TOKEN}"default_model = "claude-sonnet-4-20250514"The {env:GLM_AUTH_TOKEN} syntax reads the key from your environment variable at runtime, keeping secrets out of config files.
Important: Model Names
Section titled “Important: Model Names”Which model names to use depends on which endpoint you configured:
- Native ZAI (
type = "zai"): Use GLM model names likeGLM-4.7 - Anthropic proxy (
type = "anthropic"): Use Claude model names likeclaude-sonnet-4-20250514
Mixing them up will return an “Unknown Model” error. GLM names won’t work on the Anthropic proxy, and Claude names won’t work on the native endpoint.
Start a Chat
Section titled “Start a Chat”# Use default Z.AI providercru chat
# Specify provider explicitlycru chat --provider zai-codingSwitch Models at Runtime
Section titled “Switch Models at Runtime”Inside a chat session, use the :model command to switch models without restarting:
:model GLM-4.7Use model names that match your configured endpoint type.
Troubleshooting
Section titled “Troubleshooting””Missing API key”
Section titled “”Missing API key””Ensure GLM_AUTH_TOKEN is set in your environment:
echo $GLM_AUTH_TOKENIf empty, set it and restart your terminal.
”Unknown Model”
Section titled “”Unknown Model””You’re using a model name that doesn’t match your endpoint type.
- Native ZAI (
type = "zai"): useGLM-4.7, notclaude-sonnet-4-20250514 - Anthropic proxy (
type = "anthropic"): useclaude-sonnet-4-20250514, notglm-4-flash
Empty response / no output
Section titled “Empty response / no output”Crucible surfaces this as: "LLM returned empty response — no content received from provider". The provider returned no content in its response.
Check:
- Your endpoint URL is correct for your provider type
- The model name matches the endpoint type (GLM names for native ZAI, Claude names for Anthropic proxy)
- Your auth token is valid and hasn’t expired
Stream timeout
Section titled “Stream timeout”Error: "LLM stream timed out — no response within timeout period". The provider is reachable but isn’t responding within the timeout window.
Check:
- Network connectivity to
api.z.ai - Z.AI service status
- Try again after a brief wait
”401 Unauthorized”
Section titled “”401 Unauthorized””Ensure GLM_AUTH_TOKEN is set in the environment where cru runs, not just where you configured it. The Crucible daemon inherits the environment from the shell that started it. If you set the variable after the daemon launched, restart the daemon:
cru daemon stopexport GLM_AUTH_TOKEN="your-token-here"cru chat # daemon auto-starts with the new environment