How to Use GLM-4.5 with Claude Code (2026)
Step-by-step integration guide for running GLM-4.5 inside Claude Code
开始使用 Hypereal 构建
通过单个 API 访问 Kling、Flux、Sora、Veo 等。免费积分开始,扩展到数百万。
无需信用卡 • 10万+ 开发者 • 企业级服务
How to Use GLM-4.5 with Claude Code (2026)
GLM-4.5 is Zhipu AI's latest large language model, offering strong multilingual capabilities, improved reasoning, and competitive performance on coding benchmarks. Claude Code, Anthropic's CLI-based AI coding assistant, supports custom model providers through its configuration system. This guide walks you through connecting GLM-4.5 to Claude Code so you can leverage both tools in your development workflow.
Why Combine GLM-4.5 with Claude Code?
There are several practical reasons to integrate GLM-4.5 into your Claude Code setup:
- Multilingual support: GLM-4.5 excels at Chinese and other Asian language tasks, complementing Claude's English-first strengths.
- Cost optimization: Route simpler tasks to GLM-4.5 while reserving Claude for complex reasoning.
- Model diversity: Different models catch different bugs. Using multiple models improves code review coverage.
- Fallback availability: If one provider has downtime, you can switch to the other without changing your workflow.
Prerequisites
Before starting, make sure you have:
- Claude Code installed (version 1.0 or later):
npm install -g @anthropic-ai/claude-code
claude --version
A Zhipu AI API key: Sign up at open.bigmodel.cn and generate an API key from the console.
Node.js 18+ installed on your system.
Step 1: Get Your GLM-4.5 API Key
Navigate to the Zhipu AI developer console and create a new API key:
- Log in to open.bigmodel.cn.
- Go to API Keys in the sidebar.
- Click Create API Key and copy the generated key.
- Store it securely -- you will need it in the next step.
Step 2: Configure an OpenAI-Compatible Proxy
GLM-4.5 exposes an OpenAI-compatible API endpoint. You can use this directly with tools that support custom OpenAI base URLs. The base URL for Zhipu AI's API is:
https://open.bigmodel.cn/api/paas/v4
Set your environment variables:
export GLM_API_KEY="your-zhipu-api-key-here"
export GLM_BASE_URL="https://open.bigmodel.cn/api/paas/v4"
To make these persistent, add them to your shell profile (~/.bashrc, ~/.zshrc, etc.):
echo 'export GLM_API_KEY="your-zhipu-api-key-here"' >> ~/.zshrc
echo 'export GLM_BASE_URL="https://open.bigmodel.cn/api/paas/v4"' >> ~/.zshrc
source ~/.zshrc
Step 3: Use LiteLLM as a Bridge
The most reliable way to connect GLM-4.5 to Claude Code is through LiteLLM, which acts as a universal proxy between different LLM providers. Install it:
pip install litellm
Create a LiteLLM config file at ~/litellm_config.yaml:
model_list:
- model_name: glm-4.5
litellm_params:
model: openai/glm-4.5
api_key: os.environ/GLM_API_KEY
api_base: https://open.bigmodel.cn/api/paas/v4
- model_name: glm-4.5-flash
litellm_params:
model: openai/glm-4.5-flash
api_key: os.environ/GLM_API_KEY
api_base: https://open.bigmodel.cn/api/paas/v4
Start the LiteLLM proxy:
litellm --config ~/litellm_config.yaml --port 4000
Step 4: Point Claude Code at the Proxy
Now configure Claude Code to use GLM-4.5 through the LiteLLM proxy. You can do this per-session using the --model flag and environment variables:
ANTHROPIC_BASE_URL=http://localhost:4000 claude --model glm-4.5
Or for a more permanent setup, create a wrapper script:
#!/bin/bash
# ~/bin/claude-glm
export ANTHROPIC_BASE_URL=http://localhost:4000
claude --model glm-4.5 "$@"
Make it executable:
chmod +x ~/bin/claude-glm
Now you can run:
claude-glm "explain this function and suggest improvements"
Step 5: Verify the Connection
Test the setup with a simple prompt:
ANTHROPIC_BASE_URL=http://localhost:4000 claude --model glm-4.5 -p "What model are you? Respond in one sentence."
You should see a response identifying itself as GLM-4.5. If you get a connection error, verify that:
- The LiteLLM proxy is running on port 4000.
- Your
GLM_API_KEYenvironment variable is set. - The Zhipu AI API endpoint is reachable from your network.
GLM-4.5 Model Variants
Zhipu AI offers several model variants. Here is a comparison:
| Model | Context Window | Best For | Speed | Cost |
|---|---|---|---|---|
glm-4.5 |
128K tokens | Complex reasoning, coding | Medium | Higher |
glm-4.5-flash |
128K tokens | Fast responses, simple tasks | Fast | Lower |
glm-4.5-long |
1M tokens | Large codebase analysis | Slow | Higher |
glm-4.5-vision |
128K tokens | Image + code tasks | Medium | Higher |
Practical Use Cases
Translate documentation to Chinese:
claude-glm "translate this README.md to Chinese, preserving all markdown formatting"
Code review with a different perspective:
git diff --staged | claude-glm -p "review these changes for potential bugs"
Generate bilingual comments:
claude-glm "add bilingual (English/Chinese) JSDoc comments to all exported functions in src/utils/"
Troubleshooting
| Problem | Solution |
|---|---|
| Connection refused on port 4000 | Start LiteLLM with litellm --config ~/litellm_config.yaml --port 4000 |
| 401 Unauthorized | Check that your GLM_API_KEY is valid and not expired |
| Model not found | Verify the model name in your LiteLLM config matches exactly |
| Slow responses | Try glm-4.5-flash for faster inference |
| Garbled output | Ensure your terminal supports UTF-8 encoding |
Performance Comparison
In our testing, here is how GLM-4.5 compares to Claude when used through Claude Code:
| Task | Claude Sonnet 4 | GLM-4.5 | Notes |
|---|---|---|---|
| Python code generation | Excellent | Good | Claude handles edge cases better |
| Chinese documentation | Good | Excellent | GLM-4.5 produces more natural Chinese |
| Code review | Excellent | Good | Both catch common issues |
| Large file analysis | Good | Good | GLM-4.5-long handles 1M tokens |
| Response speed | Fast | Fast | GLM-4.5-flash is competitive |
Conclusion
Integrating GLM-4.5 with Claude Code gives you access to a powerful multilingual model directly in your terminal-based development workflow. The LiteLLM proxy approach is clean, flexible, and lets you switch between models without changing your tooling.
If you are building applications that need AI-powered media generation -- images, videos, audio, or talking avatars -- check out Hypereal AI. Hypereal provides a unified API with pay-as-you-go pricing and access to the latest generative models, so you can focus on building your product instead of managing infrastructure.
