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

FieldValue
Nameglm-openrouter-specialist
Modelsonnet
ToolsRead, Bash, Glob, Grep, Write, Edit
Triggers”openrouter”, “open router”, “route glm”, “openrouter api”, “glm via openrouter”, “glm provider”, “openrouter pricing”
Env requiredOPENROUTER_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

  1. Validate env

    Checks OPENROUTER_API_KEY is set and valid via /api/v1/auth/key. Reads BU_PLUGIN_ROOT from prompt context (injected by pre-task.mjs). If either is missing — stops with an explicit error before touching any files.

  2. Select model

    Matches the task to the optimal GLM variant: vision tasks get z-ai/glm-5v-turbo (quality) or z-ai/glm-4.6v (budget); text-only tasks use z-ai/glm-4.5-air:free at zero cost. Model IDs must carry the z-ai/ prefix — bare names are rejected by OpenRouter.

  3. Build payload

    Calls glm-build-request.sh from $BU_PLUGIN_ROOT/skills/glm-design-to-code/scripts/ to construct the JSON payload with image (base64-encoded), prompt, model ID, and max_tokens. Optionally adds provider.order and provider.allow_fallbacks for backend routing control.

  4. Send request

    Runs glm-request.sh payload.json response.json openrouter. The script posts to https://openrouter.ai/api/v1/chat/completions with the required Authorization and Content-Type headers, plus optional HTTP-Referer and X-Title for OpenRouter dashboard identification.

  5. Parse response

    Checks HTTP status code and finish_reason. Extracts content via jq -r ‘.choices[0].message.content’. For multi-file design-to-code output, delegates extraction to glm-extract.sh which splits on ===FILE:=== / ===END_FILE=== markers.

  6. Report cost

    Reads .usage from the response — OpenRouter returns prompt_tokens, completion_tokens, and total_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 IDVisionInput $/1MOutput $/1MContextBest for
z-ai/glm-5v-turboimage + video$1.20$4.00202KQuality design-to-code
z-ai/glm-4.6vimage + video$0.30$0.90131KCost-effective vision (default)
z-ai/glm-4.5-air:freetext onlyFREEFREE131KText generation, no vision

Provider routing snippet:

{
  "provider": {
    "order": ["SiliconFlow"],
    "allow_fallbacks": true,
    "require_parameters": true,
    "data_collection": "deny"
  }
}

Error reference:

HTTPMeaningFix
400Bad requestCheck payload format, verify z-ai/ model prefix
401Auth failedVerify OPENROUTER_API_KEY
402Insufficient creditsTop up OpenRouter account
429Rate limitedWait and retry with exponential backoff
502/503Provider downRetry 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

Use /brewtools:plugin-update to check and update the brewcode plugin suite in one command. See the FAQ for details.