OpenRouter Coding Guide
This guide is only for OpenRouter cloud models and OpenAI-compatible coding applications.
0. macOS And Windows Notes
This guide works for both macOS and Windows, but commands and config paths differ.
macOS
Common shell:
zsh
Temporary environment variables:
export OLLAMA_HOST=http://153.75.90.251:11434
export OPENROUTER_API_KEY="YOUR_OPENROUTER_API_KEY"
export OPENAI_API_KEY="$OPENROUTER_API_KEY"
export OPENAI_BASE_URL="https://openrouter.ai/api/v1"
Remove temporary variables:
unset OLLAMA_HOST
unset OPENROUTER_API_KEY
unset OPENAI_API_KEY
unset OPENAI_BASE_URL
Permanent shell aliases:
/Users/zarachtech/.zshrc
Claude Code settings:
/Users/zarachtech/.claude/settings.json
Codex config:
/Users/zarachtech/.codex/config.toml
Project folder example:
cd ~/Documents/Codes/testglmmodel
Windows PowerShell
Use PowerShell, preferably Windows Terminal.
Temporary environment variables for the current PowerShell window:
$env:OLLAMA_HOST = "http://153.75.90.251:11434"
$env:OPENROUTER_API_KEY = "YOUR_OPENROUTER_API_KEY"
$env:OPENAI_API_KEY = $env:OPENROUTER_API_KEY
$env:OPENAI_BASE_URL = "https://openrouter.ai/api/v1"
Remove temporary variables:
Remove-Item Env:\OLLAMA_HOST -ErrorAction SilentlyContinue
Remove-Item Env:\OPENROUTER_API_KEY -ErrorAction SilentlyContinue
Remove-Item Env:\OPENAI_API_KEY -ErrorAction SilentlyContinue
Remove-Item Env:\OPENAI_BASE_URL -ErrorAction SilentlyContinue
Claude Code settings:
C:\Users\YOUR_WINDOWS_USERNAME\.claude\settings.json
Codex config:
C:\Users\YOUR_WINDOWS_USERNAME\.codex\config.toml
Project folder example:
cd C:\Users\YOUR_WINDOWS_USERNAME\Documents\Codes\testglmmodel
If a command in this guide uses export, use $env:NAME = "value" on Windows.
If a command uses unset, use Remove-Item Env:\NAME.
If a path starts with /Users/zarachtech, replace it with your Windows user path.
Windows Command Prompt
PowerShell is recommended, but Command Prompt also works.
Set variables:
set OLLAMA_HOST=http://153.75.90.251:11434
set OPENROUTER_API_KEY=YOUR_OPENROUTER_API_KEY
set OPENAI_API_KEY=%OPENROUTER_API_KEY%
set OPENAI_BASE_URL=https://openrouter.ai/api/v1
Remove variables:
set OLLAMA_HOST=
set OPENROUTER_API_KEY=
set OPENAI_API_KEY=
set OPENAI_BASE_URL=
SSH Tunnel On macOS
ssh -L 11434:127.0.0.1:11434 root@153.75.90.251
In another terminal:
export OLLAMA_HOST=http://127.0.0.1:11434
ollama list
SSH Tunnel On Windows PowerShell
Windows 10/11 usually includes OpenSSH.
ssh -L 11434:127.0.0.1:11434 root@153.75.90.251
Keep that PowerShell window open. In another PowerShell window:
$env:OLLAMA_HOST = "http://127.0.0.1:11434"
ollama list
If ssh is not found, install OpenSSH Client from:
Settings -> Apps -> Optional Features -> OpenSSH Client
1. OpenRouter With Claude Code And Other Applications
OpenRouter is separate from Ollama and should normally run from your laptop.
For your current setup, OpenRouter is the main workflow. The VPS/Ollama setup is secondary and only needed when you specifically want to use models installed on a VPS.
Use Ollama when:
Your app -> Ollama -> local MacBook model or VPS model
Use OpenRouter from your laptop when:
Your app -> OpenRouter API -> cloud model provider
This does not need your VPS.
OpenRouter does not use models installed on your VPS. For example, qwen2.5-coder:7b and qwen3-coder:30b installed in Ollama are not OpenRouter model IDs unless OpenRouter separately supports a model with that exact ID.
Claude Code OpenRouter Settings
Claude Code reads settings from:
/Users/zarachtech/.claude/settings.json
On Windows:
C:\Users\YOUR_WINDOWS_USERNAME\.claude\settings.json
A basic OpenRouter setup looks like this:
{
"env": {
"ANTHROPIC_BASE_URL": "https://openrouter.ai/api",
"ANTHROPIC_AUTH_TOKEN": "YOUR_OPENROUTER_API_KEY",
"ANTHROPIC_API_KEY": "",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "anthropic/claude-sonnet-4.5",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "anthropic/claude-opus-4.1",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "anthropic/claude-haiku-4.5"
}
}
Use your real OpenRouter key in ANTHROPIC_AUTH_TOKEN.
Validate the JSON after editing:
python3 -m json.tool /Users/zarachtech/.claude/settings.json
On Windows PowerShell, if Python is installed:
python -m json.tool C:\Users\YOUR_WINDOWS_USERNAME\.claude\settings.json
If validation fails, Claude Code may skip the whole settings file.
Switching Claude Code To A Different OpenRouter Model
Edit:
nano /Users/zarachtech/.claude/settings.json
Change the model names:
{
"env": {
"ANTHROPIC_BASE_URL": "https://openrouter.ai/api",
"ANTHROPIC_AUTH_TOKEN": "YOUR_OPENROUTER_API_KEY",
"ANTHROPIC_API_KEY": "",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "openai/gpt-4.1",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "google/gemini-2.5-pro",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "meta-llama/llama-3.3-70b-instruct"
}
}
Then validate:
python3 -m json.tool /Users/zarachtech/.claude/settings.json
Start Claude Code inside your project:
cd /path/to/your/project
claude
Add Or Include More OpenRouter Models
OpenRouter models are selected by exact model ID. Do not guess the ID from the display name.
For example, a model may be displayed as:
GLM 5.2
but the actual OpenRouter model ID may look like:
z-ai/glm-5.2
or another provider-prefixed slug. Always copy the exact ID from:
https://openrouter.ai/models
Search for the model, open its model page, then copy the model ID shown by OpenRouter.
Common examples of OpenRouter model IDs:
anthropic/claude-sonnet-4.5
anthropic/claude-opus-4.1
openai/gpt-4.1
google/gemini-2.5-pro
z-ai/glm-4.5-air:free
z-ai/glm-5.2
If z-ai/glm-5.2 does not work, check OpenRouter's model page for the exact current ID. OpenRouter model names can change, and not every model shown elsewhere is available through OpenRouter.
Test A New OpenRouter Model Before Using It In Apps
Use this terminal test first:
export OPENROUTER_API_KEY="YOUR_OPENROUTER_API_KEY"
curl https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "z-ai/glm-5.2",
"messages": [
{ "role": "user", "content": "Reply with exactly: ready" }
]
}'
On Windows PowerShell:
$env:OPENROUTER_API_KEY = "YOUR_OPENROUTER_API_KEY"
curl.exe https://openrouter.ai/api/v1/chat/completions `
-H "Authorization: Bearer $env:OPENROUTER_API_KEY" `
-H "Content-Type: application/json" `
-d '{ "model": "z-ai/glm-5.2", "messages": [ { "role": "user", "content": "Reply with exactly: ready" } ] }'
If the test returns model not found, use the exact model ID from OpenRouter's website.
If the test returns 402 Insufficient credits, add credits or choose a free model.
If the test returns a normal response, the model can be used in Claude Code, Codex CLI, Codex App, or other OpenAI-compatible tools.
Use GLM 5.2 With Claude Code Through OpenRouter
Edit:
nano /Users/zarachtech/.claude/settings.json
On Windows:
C:\Users\YOUR_WINDOWS_USERNAME\.claude\settings.json
Example using GLM 5.2:
{
"env": {
"ANTHROPIC_BASE_URL": "https://openrouter.ai/api",
"ANTHROPIC_AUTH_TOKEN": "YOUR_OPENROUTER_API_KEY",
"ANTHROPIC_API_KEY": "",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "z-ai/glm-5.2",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "z-ai/glm-5.2",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "z-ai/glm-5.2"
}
}
Validate:
python3 -m json.tool /Users/zarachtech/.claude/settings.json
On Windows:
python -m json.tool C:\Users\YOUR_WINDOWS_USERNAME\.claude\settings.json
Start Claude Code:
cd /path/to/your/project
claude
On Windows:
cd C:\Users\YOUR_WINDOWS_USERNAME\Documents\Codes\your-project
claude
Use GLM 5.2 With Codex CLI Through OpenRouter
Make sure your Codex OpenRouter provider is configured in:
/Users/zarachtech/.codex/config.toml
On Windows:
C:\Users\YOUR_WINDOWS_USERNAME\.codex\config.toml
Then run Codex with the model:
cd /path/to/your/project
export OPENROUTER_API_KEY="YOUR_OPENROUTER_API_KEY"
codex --model z-ai/glm-5.2
On Windows PowerShell:
cd C:\Users\YOUR_WINDOWS_USERNAME\Documents\Codes\your-project
$env:OPENROUTER_API_KEY = "YOUR_OPENROUTER_API_KEY"
codex --model z-ai/glm-5.2
If you want GLM 5.2 to be the default Codex model, edit:
/Users/zarachtech/.codex/config.toml
Set:
model = "z-ai/glm-5.2"
model_provider = "openrouter"
[model_providers.openrouter]
name = "OpenRouter"
base_url = "https://openrouter.ai/api/v1"
wire_api = "responses"
env_key = "OPENROUTER_API_KEY"
env_key_instructions = "Set OPENROUTER_API_KEY in your shell environment"
Then:
cd /path/to/your/project
export OPENROUTER_API_KEY="YOUR_OPENROUTER_API_KEY"
codex
Use Different OpenRouter Models Without Editing Config Every Time
For Claude Code, change the model IDs in:
~/.claude/settings.json
For Codex CLI, pass the model at launch:
codex --model anthropic/claude-sonnet-4.5
codex --model google/gemini-2.5-pro
codex --model z-ai/glm-5.2
codex --model z-ai/glm-4.5-air:free
On Windows PowerShell, the commands are the same:
codex --model anthropic/claude-sonnet-4.5
codex --model google/gemini-2.5-pro
codex --model z-ai/glm-5.2
codex --model z-ai/glm-4.5-air:free
For other OpenAI-compatible apps, update the app's model field to the exact OpenRouter model ID.
Recommended habit:
1. Find exact model ID on OpenRouter.
2. Test it with curl.
3. Use it in Claude Code, Codex CLI, or your selected app.
4. If tool/file editing is weak, switch to a stronger coding-capable model.
Using Free OpenRouter Models
Some OpenRouter model IDs include :free.
Examples:
z-ai/glm-4.5-air:free
minimax/minimax-m2.5:free
nvidia/nemotron-3-super-120b-a12b:free
Free models can change availability, rate limits, and quality. If Claude Code returns 402 Insufficient credits, the selected model or account still requires credits.
Common OpenRouter Errors
402 Insufficient credits
Your OpenRouter account needs credits, or the model is not free for your account.
Fix:
Add credits at https://openrouter.ai/settings/credits
or switch to a free model.
400 model is not a valid model ID
The model name in settings.json is not recognized by OpenRouter.
Fix:
Use the exact model ID shown on OpenRouter.
Do not use Ollama-only model names like qwen2.5-coder:7b unless OpenRouter supports that exact ID.
Invalid or malformed JSON
/Users/zarachtech/.claude/settings.json has a JSON syntax error.
Fix:
python3 -m json.tool /Users/zarachtech/.claude/settings.json
Then repair the line and column shown in the error.
Codex CLI With OpenRouter
Codex CLI can use custom providers from:
/Users/zarachtech/.codex/config.toml
Open the config:
nano /Users/zarachtech/.codex/config.toml
On Windows, edit:
C:\Users\YOUR_WINDOWS_USERNAME\.codex\config.toml
Add or update this OpenRouter provider:
model = "openai/gpt-4.1"
model_provider = "openrouter"
[model_providers.openrouter]
name = "OpenRouter"
base_url = "https://openrouter.ai/api/v1"
wire_api = "responses"
env_key = "OPENROUTER_API_KEY"
env_key_instructions = "Set OPENROUTER_API_KEY in your shell environment"
Then set your key:
export OPENROUTER_API_KEY="YOUR_OPENROUTER_API_KEY"
On Windows PowerShell:
$env:OPENROUTER_API_KEY = "YOUR_OPENROUTER_API_KEY"
Start Codex in a project folder:
cd /path/to/your/project
codex
On Windows PowerShell:
cd C:\Users\YOUR_WINDOWS_USERNAME\Documents\Codes\your-project
codex
Use a different OpenRouter model for one run:
cd /path/to/your/project
OPENROUTER_API_KEY="YOUR_OPENROUTER_API_KEY" codex --model google/gemini-2.5-pro
On Windows PowerShell:
cd C:\Users\YOUR_WINDOWS_USERNAME\Documents\Codes\your-project
$env:OPENROUTER_API_KEY = "YOUR_OPENROUTER_API_KEY"
codex --model google/gemini-2.5-pro
Or:
cd /path/to/your/project
OPENROUTER_API_KEY="YOUR_OPENROUTER_API_KEY" codex --model anthropic/claude-sonnet-4.5
Important: Codex agent workflows need strong tool/function-call behavior. If a model produces fake tool calls as text or fails to edit files, switch to a stronger model.
Codex App With OpenRouter
Codex App uses Codex configuration. Set the same OpenRouter provider in:
/Users/zarachtech/.codex/config.toml
Then launch:
export OPENROUTER_API_KEY="YOUR_OPENROUTER_API_KEY"
codex app
On Windows PowerShell:
$env:OPENROUTER_API_KEY = "YOUR_OPENROUTER_API_KEY"
codex app
You can also open the app normally after the config is saved, but the environment variable must be available to the app process. If the app cannot see OPENROUTER_API_KEY, launch it from the terminal with the command above.
OpenCode, OpenClaw, Hermes, And Other OpenAI-Compatible Apps
Most coding apps that support OpenAI-compatible APIs need these three values:
API key: YOUR_OPENROUTER_API_KEY
Base URL: https://openrouter.ai/api/v1
Model: exact OpenRouter model ID
Common environment variables:
export OPENROUTER_API_KEY="YOUR_OPENROUTER_API_KEY"
export OPENAI_API_KEY="$OPENROUTER_API_KEY"
export OPENAI_BASE_URL="https://openrouter.ai/api/v1"
On Windows PowerShell:
$env:OPENROUTER_API_KEY = "YOUR_OPENROUTER_API_KEY"
$env:OPENAI_API_KEY = $env:OPENROUTER_API_KEY
$env:OPENAI_BASE_URL = "https://openrouter.ai/api/v1"
Some apps use OPENAI_BASE_URL; others use OPENAI_API_BASE, OPENAI_API_URL, or a config file. If one variable does not work, check that app's settings and use:
https://openrouter.ai/api/v1
as the OpenAI-compatible base URL.
Example model IDs:
openai/gpt-4.1
google/gemini-2.5-pro
anthropic/claude-sonnet-4.5
z-ai/glm-4.5-air:free
minimax/minimax-m2.5:free
nvidia/nemotron-3-super-120b-a12b:free
Generic app setup:
Provider: OpenAI-compatible / Custom OpenAI / OpenAI API
Base URL: https://openrouter.ai/api/v1
API Key: YOUR_OPENROUTER_API_KEY
Model: exact model ID from https://openrouter.ai/models
Then open the app from the project folder if it is terminal-based:
cd /path/to/your/project
export OPENROUTER_API_KEY="YOUR_OPENROUTER_API_KEY"
export OPENAI_API_KEY="$OPENROUTER_API_KEY"
export OPENAI_BASE_URL="https://openrouter.ai/api/v1"
Run the app command after that. Examples, if installed:
opencode
openclaw
hermes
On Windows PowerShell, the commands are usually the same if the apps are installed and available in PATH:
opencode
openclaw
hermes
If an app asks for a model, use the exact OpenRouter ID, not an Ollama model tag. For OpenRouter, use:
anthropic/claude-sonnet-4.5
google/gemini-2.5-pro
openai/gpt-4.1
Do not use:
qwen2.5-coder:7b
qwen3-coder:30b
unless OpenRouter shows those exact model IDs in its model list.
Quick OpenRouter Test From Terminal
Use this to confirm your key and model work before configuring an app:
export OPENROUTER_API_KEY="YOUR_OPENROUTER_API_KEY"
curl https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4.1",
"messages": [
{ "role": "user", "content": "Reply with exactly: ready" }
]
}'
On Windows PowerShell:
$env:OPENROUTER_API_KEY = "YOUR_OPENROUTER_API_KEY"
curl.exe https://openrouter.ai/api/v1/chat/completions `
-H "Authorization: Bearer $env:OPENROUTER_API_KEY" `
-H "Content-Type: application/json" `
-d '{ "model": "openai/gpt-4.1", "messages": [ { "role": "user", "content": "Reply with exactly: ready" } ] }'
If this fails, fix OpenRouter credits, key, or model name before changing any coding app.
Switch Between OpenRouter Apps And Ollama VPS Apps
For OpenRouter apps:
unset OLLAMA_HOST
export OPENROUTER_API_KEY="YOUR_OPENROUTER_API_KEY"
export OPENAI_API_KEY="$OPENROUTER_API_KEY"
export OPENAI_BASE_URL="https://openrouter.ai/api/v1"
On Windows PowerShell:
Remove-Item Env:\OLLAMA_HOST -ErrorAction SilentlyContinue
$env:OPENROUTER_API_KEY = "YOUR_OPENROUTER_API_KEY"
$env:OPENAI_API_KEY = $env:OPENROUTER_API_KEY
$env:OPENAI_BASE_URL = "https://openrouter.ai/api/v1"
For Ollama VPS apps:
unset OPENAI_API_KEY
unset OPENAI_BASE_URL
export OLLAMA_HOST=http://153.75.90.251:11434
On Windows PowerShell:
Remove-Item Env:\OPENAI_API_KEY -ErrorAction SilentlyContinue
Remove-Item Env:\OPENAI_BASE_URL -ErrorAction SilentlyContinue
$env:OLLAMA_HOST = "http://153.75.90.251:11434"
Then launch Ollama-backed apps:
ollama launch codex --model qwen2.5-coder:7b
ollama launch claude --model qwen2.5-coder:7b
ollama launch opencode --model qwen2.5-coder:7b
Switch Between OpenRouter Claude And Ollama Claude
Claude Code can be configured globally through settings.json, while ollama launch claude tries to start Claude Code with Ollama-compatible settings.
If settings.json forces OpenRouter, Claude Code may ignore the Ollama launch model and still call OpenRouter.
To use Claude Code with OpenRouter:
cd /path/to/your/project
claude
To use Claude Code with Ollama cleanly, temporarily move the OpenRouter settings aside:
mv /Users/zarachtech/.claude/settings.json /Users/zarachtech/.claude/settings.json.openrouter
export OLLAMA_HOST=http://153.75.90.251:11434
ollama launch claude --model qwen2.5-coder:7b
Restore OpenRouter later:
mv /Users/zarachtech/.claude/settings.json.openrouter /Users/zarachtech/.claude/settings.json
If you already have a backup:
cp /Users/zarachtech/.claude/settings.json.openrouter-backup /Users/zarachtech/.claude/settings.json
Recommended Practical Workflow
Use OpenRouter for Claude Code when you want stronger cloud models:
cd /path/to/project
claude
Use Ollama VPS with Codex/OpenCode when you want your VPS-hosted models:
cd /path/to/project
export OLLAMA_HOST=http://153.75.90.251:11434
ollama launch codex --model qwen2.5-coder:7b
Use qwen2.5-coder:7b on your VPS for stable local-style coding. Use qwen3-coder:30b only when you can tolerate slow responses on the current VPS.
Python Launcher Script
The guide folder includes a cross-platform launcher:
/Users/zarachtech/Downloads/llmguides/llm_launcher.py
On macOS:
cd /Users/zarachtech/Downloads/llmguides
python3 llm_launcher.py
On Windows PowerShell:
cd C:\Users\YOUR_WINDOWS_USERNAME\Downloads\llmguides
python llm_launcher.py
The script saves only non-secret setup choices:
provider
model
app
project folder
Ollama host
It does not save OpenRouter API keys. If the current setup uses OpenRouter, it asks for the key at launch time or uses OPENROUTER_API_KEY if it already exists in the current terminal session.
Saved non-secret state is stored here:
~/.llm_launcher_state.json
Show the saved setup:
python3 llm_launcher.py --show
On Windows:
python llm_launcher.py --show
Run the current saved setup:
python3 llm_launcher.py
Change provider/model/app/project before launching:
python3 llm_launcher.py --change
Preview what will run without launching anything:
python3 llm_launcher.py --dry-run
If Claude Code settings contain saved ANTHROPIC_* environment overrides that interfere with the launcher, remove those overrides safely with:
python3 llm_launcher.py --sanitize-claude-settings
On Windows:
python llm_launcher.py --sanitize-claude-settings
This creates a backup of the Claude settings file before removing the conflicting environment overrides.