Skip to Content

OpenRouter guardrails

OpenRouter guardrails cap spend and restrict model access at the org and workspace level — before runaway agent loops hit your credit balance.

Hub: Tokenminning with OpenRouter.

This page answers openrouter spending limit, openrouter budget, and openrouter guardrails.

Workspace budgets

Workspaces  isolate projects, teams, and agents. Each workspace can have a spending budget with automatic enforcement when the cap is reached.

WorkspacePurposeBudget pattern
devCline / Aider localLow monthly cap
ciEval scripts, botsHard cap, haiku-only
prodApp trafficSeparate from coding

Pass workspace_id when querying the Analytics API  to attribute spend per workspace.

Org guardrails

Guardrails  control spending and model access for your organization:

Guardrail typeWhat it blocks or limits
Model allowlistFrontier slugs on CI keys
Spending limitsPer-key and org-level caps
Sensitive infoAPI keys in prompts before they reach providers
Prompt injectionRegex patterns on inbound requests

Configure guardrails in the OpenRouter dashboard under your org settings. Pair with per-key limits — guardrails are the org-wide backstop.

Per-key spending limits

At key creation, set a spending limit. When the key hits the cap, requests fail fast instead of draining the shared credit pool.

Dev key → $20/mo cap, haiku + sonnet allowlist CI key → $5/mo cap, haiku-only Prod key → separate pool, no coding-agent traffic

Rotate keys when a tool leaks into the wrong environment. Never commit keys — use env vars and secret scanners.

Notifications

Notifications  alert before credits deplete or when a workspace approaches its budget. Route alerts to Slack or email so spikes surface during business hours, not Monday morning.

BYOK tradeoff

Bring your own key (BYOK)  routes through your provider credentials. You pay provider rates directly; OpenRouter charges a smaller platform fee. Useful when you already have enterprise Anthropic or OpenAI contracts — but you lose unified credit pooling across providers.

Batch workloads

The Batch API  runs inference asynchronously. Submit large eval or offline workloads as batches instead of synchronous agent loops — lower effective cost and no interactive latency pressure.

curl https://openrouter.ai/api/v1/batches \ -H "Authorization: Bearer $OPENROUTER_API_KEY" \ -H "Content-Type: application/json" \ -d '{"input_file_id": "file-abc123", "endpoint": "/v1/chat/completions"}'

Reserve synchronous /chat/completions for interactive coding agents.

Agent SDK loops

The Agent SDK  (callModel) runs multi-turn tool loops in one invocation. Each tool call re-bills. Cap maxSteps in your agent config and default to haiku-tier models for tool-selection turns.

Spending guardrails checklist

  • Separate API keys per tool and environment
  • Spending limit on every key
  • Workspace budgets for prod vs dev
  • Model allowlist on CI keys
  • Notifications before credit depletion
  • Batch API for offline eval, not agent loops

Troubleshooting

Key blocked mid-sprint — cap too low for legitimate traffic. Raise cap on dev key; keep CI key tight.

Guardrail rejected a valid request — check model allowlist and sensitive-info patterns. Allowlist safe internal domains if web-fetch tools are enabled.

BYOK bill higher than expected — BYOK removes OpenRouter credit pooling but not upstream provider rates. Activity still shows per-request cost.

Last updated on