glm-openrouter-specialist
Caution
OpenRouter adds a routing layer between Claude Code and the GLM backends. Model IDs, auth headers, and provider fallback chains differ from the direct Z.ai API. Sending a direct-API payload to OpenRouter — or vice versa — returns a 400 or silent truncation. This agent handles the translation.
Tip
Auto-delegated by /brewui:glm-design-to-code when OpenRouter is selected as provider. You can also invoke it directly for standalone API requests, cost audits, or model selection decisions.
Quick reference
| Field | Value |
|---|---|
| Name | glm-openrouter-specialist |
| Model | sonnet |
| Tools | Read, Bash, Glob, Grep, Write, Edit |
| Triggers | ”openrouter”, “open router”, “route glm”, “openrouter api”, “glm via openrouter”, “glm provider”, “openrouter pricing” |
| Env required | OPENROUTER_API_KEY, BU_PLUGIN_ROOT (injected by hook) |
When to use
- Design-to-code via OpenRouter — send a screenshot or image to GLM through the OpenRouter gateway
- Model selection — pick the right GLM variant (quality vs. cost vs. free tier) for the task
- Cost audit — estimate or review token spend before a batch run
- Provider routing — lock to a specific backend (e.g., SiliconFlow) or configure fallback chains
- Debugging 4xx/5xx — diagnose auth errors, rate limits, and provider downtime
Examples
"use openrouter to send this screenshot to glm"
"route glm via openrouter with cost optimization"
"which openrouter GLM model should I use for batch design-to-code?"
"openrouter pricing for glm vision tasks"
"glm provider — openrouter api key check"
Flow
- Validate env
Checks
OPENROUTER_API_KEYis set and valid via/api/v1/auth/key. ReadsBU_PLUGIN_ROOTfrom prompt context (injected bypre-task.mjs). If either is missing — stops with an explicit error before touching any files. - Select model
Matches the task to the optimal GLM variant: vision tasks get
z-ai/glm-5v-turbo(quality) orz-ai/glm-4.6v(budget); text-only tasks usez-ai/glm-4.5-air:freeat zero cost. Model IDs must carry thez-ai/prefix — bare names are rejected by OpenRouter. - Build payload
Calls
glm-build-request.shfrom$BU_PLUGIN_ROOT/skills/glm-design-to-code/scripts/to construct the JSON payload with image (base64-encoded), prompt, model ID, andmax_tokens. Optionally addsprovider.orderandprovider.allow_fallbacksfor backend routing control. - Send request
Runs
glm-request.sh payload.json response.json openrouter. The script posts tohttps://openrouter.ai/api/v1/chat/completionswith the requiredAuthorizationandContent-Typeheaders, plus optionalHTTP-RefererandX-Titlefor OpenRouter dashboard identification. - Parse response
Checks HTTP status code and
finish_reason. Extracts content viajq -r ‘.choices[0].message.content’. For multi-file design-to-code output, delegates extraction toglm-extract.shwhich splits on===FILE:===/===END_FILE===markers. - Report cost
Reads
.usagefrom the response — OpenRouter returnsprompt_tokens,completion_tokens, andtotal_cost. Prints a summary table: model, finish reason, token counts, estimated USD cost. Surfaces any 402/429/5xx errors with a concrete remediation step.
Model matrix & pricing
| Model ID | Vision | Input $/1M | Output $/1M | Context | Best for |
|---|---|---|---|---|---|
z-ai/glm-5v-turbo | image + video | $1.20 | $4.00 | 202K | Quality design-to-code |
z-ai/glm-4.6v | image + video | $0.30 | $0.90 | 131K | Cost-effective vision (default) |
z-ai/glm-4.5-air:free | text only | FREE | FREE | 131K | Text generation, no vision |
Provider routing snippet:
{
"provider": {
"order": ["SiliconFlow"],
"allow_fallbacks": true,
"require_parameters": true,
"data_collection": "deny"
}
}Error reference:
| HTTP | Meaning | Fix |
|---|---|---|
| 400 | Bad request | Check payload format, verify z-ai/ model prefix |
| 401 | Auth failed | Verify OPENROUTER_API_KEY |
| 402 | Insufficient credits | Top up OpenRouter account |
| 429 | Rate limited | Wait and retry with exponential backoff |
| 502/503 | Provider down | Retry or add provider.order fallback |
GLM Z.ai Specialist
Direct Z.ai API alternative — no routing layer, lower latency.
GLM Design to Code
The skill that auto-delegates to this agent when OpenRouter is selected.
Brewui overview
All brewui skills and agents in one place.
GitHub source
Agent definition, scripts, and request helpers.
Updating plugins
/brewtools:plugin-update to check and update the brewcode plugin suite in one command.
See the FAQ for details.