Agent skill · marketing growth · jeremylongshore

openrouter-cost-controls

Implement cost controls for OpenRouter API usage. Use when setting budgets,

Why this skill is useful

Provides specific API commands and middleware patterns for managing OpenRouter API costs that the AI wouldn't reliably generate on its own.

What it needs

Requires bc, curl, jq, node, python3 installed locally. Requires openrouter account access. About 4k tokens when loaded. Last updated 2026-08-07. 2,604 stars on the source repository.

What this skill does

OpenRouter Cost Controls Overview OpenRouter provides per-key credit limits, a credit balance API, and per-generation cost queries. Combined with client-side budget middleware, you can enforce hard spending caps at the key level and soft caps in your application. This skill covers key-level limits, per-request cost tracking, budget enforcement middleware, and alert systems. Prerequisites An OpenRouter API key (sk-or-v1-...) exported as OPENROUTERAPIKEY — see the openrouter-install-auth skill for setup Python 3.8+ with the OpenAI SDK and requests; Node.js 18+ for the TypeScript per-request cost logger in the references curl, jq, and bc for the balance check and the Budget Alert Script An OpenRouter management key exported as OPENROUTERMGMTKEY if you provision per-key credit limits via POST /api/v1/keys Instructions 1. Query GET /api/v1/auth/key per Check Credit Balance to see credits used, the key's limit, remaining balance, free-tier status, and rate limit. 2. Provision scoped keys per Per-Key Credit Limits — POST /api/v1/keys with a dollar limit (e.g. $50 for backend-prod) using the management key, then list keys to review usage against limits per service. 3. Deploy the BudgetEnforcer from Budget Enforcement Middleware: checkbudget() rejects any request whose pre-flight estimate exceeds the per-request or daily cap, and recordcost() books the exact spend from GET /api/v1/generation?id=. 4. Cut unit cost with Cost-Saving Model Variants: :floor picks the cheapest provider, :free costs nothing where available, and the task-based ROUTING table sends classification to gpt-4o-mini and simple Q&A to Llama 3.1 8B. 5. Schedule the Budget Alert Script (cron) so a balance drop below the threshold fires an alert to Slack or PagerDuty. 6. Set maxtokens on every request and enable auto-topup per Enterprise Considerations to cap completion cost without risking an outage. …

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills jeremylongshore/openrouter-cost-controls--8b11d5

View the source on GitHub

Browse the @skills marketplace