{"slug": "how-to-run-glm-5-2-in-claude-code-using-openrouter-a-5-minute-setup-guide", "title": "How to Run GLM 5.2 in Claude Code Using OpenRouter: A 5-Minute Setup Guide", "summary": "Developers can now run Zhipu AI's GLM 5.2 model inside Anthropic's Claude Code coding environment by routing API calls through OpenRouter, using the ANTHROPIC_BASE_URL environment variable to point to OpenRouter's endpoint. The five-minute setup allows teams to leverage GLM 5.2's strong bilingual performance and lower cost without switching tools.", "body_md": "# How to Run GLM 5.2 in Claude Code Using OpenRouter: A 5-Minute Setup Guide\n\nYou can run GLM 5.2 inside Claude Code's harness via OpenRouter in minutes. This guide covers setup, the anthropic_base_url trick, and web search integration.\n\n## Why Run a Different Model Inside Claude Code?\n\nClaude Code is a powerful agentic coding environment. It reads files, runs shell commands, edits code, and reasons across large contexts — all through Anthropic’s CLI. But locking it to a single model limits your options. Running **GLM 5.2 in Claude Code via OpenRouter** gives you access to Zhipu AI’s capable model family inside the same harness you already know, often at a lower cost per token.\n\nThis matters for teams experimenting with model diversity, developers working on multilingual codebases (GLM models handle Chinese-English tasks particularly well), or anyone who just wants to compare outputs from different frontier models without switching tools.\n\nThe setup takes about five minutes once you understand the key trick: Claude Code exposes an `ANTHROPIC_BASE_URL`\n\nenvironment variable that lets you point its API calls at any OpenAI-compatible or Anthropic-compatible endpoint — including OpenRouter.\n\nHere’s exactly how to do it.\n\n## What Is GLM 5.2 and Why Use It?\n\nGLM 5.2 is part of Zhipu AI’s General Language Model series. Zhipu AI, spun out of Tsinghua University, has steadily built one of the most competitive open-weight and API-accessible model families outside of the US.\n\nThe GLM line has earned a reputation for strong reasoning, solid code generation, and better-than-average bilingual (Chinese/English) performance. On standard benchmarks like MMLU and HumanEval, recent GLM models compete with similarly-sized models from Mistral and Meta.\n\nKey characteristics of GLM 5.2:\n\n**Strong multilingual capabilities**— particularly useful for teams working across Chinese and English documentation or codebases** Competitive context window**— handles long files and multi-file reasoning without degradation** Tool use support**— includes function calling, which matters if you want web search or custom integrations** Available on OpenRouter**— accessible through a single API without managing separate keys or accounts\n\nOpenRouter acts as a unified gateway to hundreds of models. Instead of signing up with Zhipu AI directly, you call one endpoint with one key and specify the model ID.\n\n## Prerequisites\n\nBefore you start, make sure you have the following:\n\n**Claude Code installed**— install it globally via`npm install -g @anthropic-ai/claude-code`\n\n**An OpenRouter account**— free to create at[openrouter.ai](https://openrouter.ai)** Some OpenRouter credits**— you can add as little as $5 to get started; GLM 5.2 is priced competitively** A terminal**— the setup involves a few environment variable exports\n\nYou do not need an Anthropic API key for this setup. You’re replacing the Anthropic endpoint entirely.\n\n## Step-by-Step Setup: Connecting GLM 5.2 to Claude Code via OpenRouter\n\n### Step 1: Get Your OpenRouter API Key\n\n- Log in to your OpenRouter account.\n- Navigate to\n**Settings → API Keys**. - Click\n**Create Key** and give it a name (e.g.,`claude-code-glm`\n\n). - Copy the key — it starts with\n`sk-or-v1-...`\n\n.\n\nKeep this key handy. You’ll set it as an environment variable in the next step.\n\n### Step 2: Set the Environment Variables\n\nClaude Code reads two key environment variables when it initializes:\n\n`ANTHROPIC_API_KEY`\n\n— the key used for authentication`ANTHROPIC_BASE_URL`\n\n— the base URL for API requests\n\nBy overriding both, you redirect all of Claude Code’s model calls to OpenRouter.\n\nIn your terminal, run:\n\n```\nexport ANTHROPIC_API_KEY=\"sk-or-v1-your-openrouter-key-here\"\nexport ANTHROPIC_BASE_URL=\"https://openrouter.ai/api/v1\"\n```\n\nFor a permanent setup, add these lines to your `~/.bashrc`\n\n, `~/.zshrc`\n\n, or equivalent shell config file:\n\n```\n# OpenRouter config for Claude Code\nexport ANTHROPIC_API_KEY=\"sk-or-v1-your-openrouter-key-here\"\nexport ANTHROPIC_BASE_URL=\"https://openrouter.ai/api/v1\"\n```\n\nThen reload your shell:\n\n```\nsource ~/.zshrc\n```\n\n### Step 3: Set the Model\n\nClaude Code needs to know which model to request. Use the `--model`\n\nflag when launching:\n\n```\nclaude --model zhipuai/glm-4-plus\n```\n\nOr, if you’re using a newer GLM 5.2 release that has a different slug on OpenRouter, substitute the correct model ID. You can find all available GLM models by searching “glm” in the [OpenRouter models directory](https://openrouter.ai/models).\n\nCommon GLM model IDs on OpenRouter include:\n\n`zhipuai/glm-4-plus`\n\n`zhipuai/glm-4-air`\n\n`zhipuai/glm-z1-air`\n\n`zhipuai/glm-z1-rumination`\n\nCheck the OpenRouter listing to confirm which ID corresponds to GLM 5.2 at the time you’re reading this — Zhipu AI pushes new versions regularly.\n\n### Step 4: Verify the Connection\n\nRun a simple test to confirm everything is wired up correctly:\n\n```\nclaude --model zhipuai/glm-4-plus \"What model are you?\"\n```\n\nIf the connection is working, you’ll get a response. The model may or may not accurately self-identify — that’s normal. What matters is that the request goes through without an authentication error or endpoint failure.\n\nIf you see a `401 Unauthorized`\n\nerror, double-check that your `ANTHROPIC_API_KEY`\n\nis set to your OpenRouter key, not an Anthropic key. If you see a `404 Not Found`\n\n, verify the model slug matches exactly what OpenRouter expects.\n\n## The ANTHROPIC_BASE_URL Trick Explained\n\nThis is the core mechanism worth understanding, because it opens the door to any model on OpenRouter — not just GLM 5.2.\n\nClaude Code is essentially an agentic shell that wraps Anthropic’s API. When you run a command, Claude Code packages your request into an Anthropic-formatted API call and sends it to `api.anthropic.com`\n\nby default. The `ANTHROPIC_BASE_URL`\n\nvariable overrides that destination.\n\nOpenRouter accepts Anthropic-formatted requests at `https://openrouter.ai/api/v1`\n\n. It translates them, routes them to the correct upstream model, and returns a response in a format Claude Code can parse.\n\nThis means the same trick works for other models too:\n\n```\n# Run Mistral instead\nclaude --model mistralai/mistral-large --model\n\n# Run Llama 4 instead\nclaude --model meta-llama/llama-4-maverick\n```\n\nThe `ANTHROPIC_BASE_URL`\n\napproach isn’t a hack — Anthropic built it in deliberately so developers could test against local servers and proxies. OpenRouter just happens to be a perfect fit for it.\n\nOne thing to be aware of: some Claude Code features depend on Anthropic-specific extensions or behaviors. Prompt caching, for instance, works differently across providers. Tool use generally works fine across OpenRouter, but if you notice unexpected behavior in complex multi-step tasks, the model’s native function-calling implementation may differ slightly from Claude’s.\n\n## Adding Web Search to Your GLM 5.2 Setup\n\nWeb search is one of the most useful capabilities to layer onto an agentic coding setup. GLM models support tool use, and OpenRouter makes it possible to pass tool definitions in your requests.\n\nThere are two main approaches:\n\n### Approach 1: Use Claude Code’s Built-in Web Tool (Where Supported)\n\nClaude Code has a built-in web fetch capability for some workflows. With OpenRouter routing, whether this works depends on whether the target model honors the tool call correctly. GLM models generally do support function calling, so you can pass a web search tool definition and the model will attempt to invoke it.\n\n### Approach 2: Use a System Prompt with Search Instructions\n\nA simpler workaround is to include instructions in your system prompt that tell the model to request web searches explicitly. Combine this with Claude Code’s ability to run shell commands — you can pipe results from `curl`\n\nor a search API into the model’s context.\n\nFor example, in your Claude Code session:\n\n```\nRun a web search for the latest Next.js 15 release notes and summarize the breaking changes.\n```\n\nClaude Code will attempt to use `curl`\n\nor its fetch tools to retrieve that information. With GLM 5.2 handling the reasoning, the results can be surprisingly coherent.\n\n### Approach 3: Add a Search Tool via MindStudio’s Agent Skills Plugin\n\nIf you want a more robust, production-ready web search capability without wiring it up yourself, MindStudio’s [Agent Skills Plugin](https://mindstudio.ai) gives Claude Code access to a `searchGoogle()`\n\nmethod as a simple function call. The plugin handles auth, rate limiting, and result formatting so you don’t have to. It takes about 10 minutes to set up and works with any model running through Claude Code — including GLM 5.2 via OpenRouter.\n\n## Where MindStudio Fits In\n\nOnce you’ve got GLM 5.2 running in Claude Code, you might start thinking about the next layer: connecting your agent to real tools and workflows.\n\nClaude Code is excellent for reasoning and code tasks. But the moment you need your agent to send emails, update a CRM, pull from a database, or trigger a business process, you’re looking at significant plumbing work.\n\nThat’s where [MindStudio](https://mindstudio.ai) becomes relevant. MindStudio’s Agent Skills Plugin (`@mindstudio-ai/agent`\n\n) is an npm SDK that exposes 120+ typed capabilities as simple method calls. When your Claude Code session (or any other agent) needs to call one, it’s as straightforward as:\n\n```\nawait agent.sendEmail({ to: \"team@company.com\", subject: \"Build complete\", body: summary });\nawait agent.searchGoogle({ query: \"GLM 5.2 benchmark results\" });\nawait agent.runWorkflow({ workflowId: \"summarize-pr-changes\", input: diffText });\n```\n\nThe plugin handles the infrastructure — retries, rate limits, authentication — so the agent focuses on reasoning rather than plumbing.\n\nThis makes MindStudio a natural complement to the OpenRouter + Claude Code setup described in this guide. You get model flexibility from OpenRouter, agentic reasoning from Claude Code’s harness, and real-world tool connectivity from MindStudio.\n\nYou can try MindStudio free at [mindstudio.ai](https://mindstudio.ai).\n\n## Troubleshooting Common Issues\n\nEven with a straightforward setup, a few things can go wrong. Here’s what to check:\n\n### The model returns generic “I’m Claude” responses\n\nThis is expected behavior for some models. GLM 5.2 may respond to identity questions in different ways. It doesn’t mean the routing is broken — test with a functional task instead, like asking it to write a function.\n\n### Authentication errors (401)\n\nMake sure `ANTHROPIC_API_KEY`\n\nis your OpenRouter key, not an Anthropic key. Run `echo $ANTHROPIC_API_KEY`\n\nto confirm the value is set correctly in your current shell session.\n\n### Model not found errors (404)\n\nThe model slug must match exactly what OpenRouter uses. Check the [OpenRouter models page](https://openrouter.ai/models) for the exact identifier. Slugs are case-sensitive.\n\n### Slow responses or timeouts\n\nGLM models on OpenRouter can occasionally have latency spikes, especially for long-context requests. If you’re consistently hitting timeouts, try a smaller model variant or reduce the context you’re sending.\n\n### Tool use not working as expected\n\nNot all models handle Anthropic’s tool-use format identically. If you’re relying on Claude Code’s built-in tools (file reads, shell commands), these should still work fine since they run locally. External tool calls that depend on the model’s function-calling behavior may need adjustment.\n\n### Environment variables not persisting\n\nIf your variables reset between sessions, confirm they’re in your shell config file (`.zshrc`\n\n, `.bashrc`\n\n, etc.) and that you’ve sourced the file after editing it.\n\n## FAQ\n\n### Can I use any model from OpenRouter with Claude Code, not just GLM 5.2?\n\nYes. The `ANTHROPIC_BASE_URL`\n\ntrick works with any model that OpenRouter hosts. You just change the `--model`\n\nflag to the appropriate model ID. Mistral, Llama, Qwen, Gemma, and hundreds of others are all accessible this way. The only constraint is that the model needs to support the message format Claude Code uses — which OpenRouter normalizes for you.\n\n### Do I still need an Anthropic API key?\n\nNo. When you set `ANTHROPIC_BASE_URL`\n\nto OpenRouter’s endpoint and use your OpenRouter API key as `ANTHROPIC_API_KEY`\n\n, Anthropic’s servers are bypassed entirely. You’re billed through OpenRouter, not Anthropic.\n\n### How does GLM 5.2 compare to Claude for coding tasks?\n\nGLM 5.2 performs well on code generation and reasoning tasks, particularly for multilingual projects. For pure English-language coding with complex, multi-step reasoning, Claude Sonnet or Claude Opus still tend to outperform GLM on the harder problems. That said, GLM 5.2 is competitive for standard coding tasks and significantly cheaper per token, which matters in high-volume agentic workflows.\n\n### Built like a system. Not vibe-coded.\n\nRemy manages the project — every layer architected, not stitched together at the last second.\n\n### Is this setup stable enough for production use?\n\nFor personal projects and experimentation, yes. For production workloads, you should account for OpenRouter’s uptime (which is generally good but adds a hop), potential model availability changes, and the fact that Claude Code itself is evolving. Test thoroughly before relying on this in critical pipelines.\n\n### Can I switch models mid-session?\n\nNot within an active session — the model is set at launch. You’d need to start a new Claude Code session with the new `--model`\n\nflag. Some teams use shell aliases to quickly switch between model configurations.\n\n### Does web search work out of the box with GLM 5.2 on OpenRouter?\n\nNot automatically. GLM models support function calling, so you can define a web search tool and pass it in your requests. But Claude Code doesn’t have a native integration with GLM’s tool ecosystem. The most practical approaches are using Claude Code’s shell commands to run searches locally, or using a plugin like MindStudio’s Agent Skills to handle the search infrastructure cleanly.\n\n## Key Takeaways\n\n- Claude Code’s\n`ANTHROPIC_BASE_URL`\n\nenvironment variable lets you route model calls to OpenRouter, giving you access to GLM 5.2 and hundreds of other models inside the same agentic harness. - The setup takes about five minutes: get an OpenRouter key, export two environment variables, and launch Claude Code with\n`--model zhipuai/glm-4-plus`\n\n(or the appropriate GLM 5.2 slug). - GLM 5.2 is a strong choice for multilingual codebases, cost-sensitive workflows, and model comparison experiments.\n- Web search integration requires a bit of extra setup — either through Claude Code’s shell tools, tool definitions passed in requests, or a plugin like MindStudio’s Agent Skills.\n- You don’t need an Anthropic API key when routing through OpenRouter — your OpenRouter key replaces it entirely.\n\nIf you want to extend this setup with real-world tool integrations — search, email, CRM updates, workflow triggers — [MindStudio](https://mindstudio.ai) is the fastest way to add those capabilities to any agent, including one running GLM 5.2 through Claude Code.", "url": "https://wpnews.pro/news/how-to-run-glm-5-2-in-claude-code-using-openrouter-a-5-minute-setup-guide", "canonical_source": "https://www.mindstudio.ai/blog/run-glm-5-2-claude-code-openrouter-setup/", "published_at": "2026-06-25 00:00:00+00:00", "updated_at": "2026-06-25 12:47:49.900884+00:00", "lang": "en", "topics": ["large-language-models", "ai-tools", "developer-tools", "ai-infrastructure"], "entities": ["GLM 5.2", "Zhipu AI", "Claude Code", "OpenRouter", "Anthropic", "Tsinghua University"], "alternates": {"html": "https://wpnews.pro/news/how-to-run-glm-5-2-in-claude-code-using-openrouter-a-5-minute-setup-guide", "markdown": "https://wpnews.pro/news/how-to-run-glm-5-2-in-claude-code-using-openrouter-a-5-minute-setup-guide.md", "text": "https://wpnews.pro/news/how-to-run-glm-5-2-in-claude-code-using-openrouter-a-5-minute-setup-guide.txt", "jsonld": "https://wpnews.pro/news/how-to-run-glm-5-2-in-claude-code-using-openrouter-a-5-minute-setup-guide.jsonld"}}