openrouter-cost-controls
Installation
SKILL.md
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 asOPENROUTER_API_KEY— see theopenrouter-install-authskill 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, andbcfor the balance check and the Budget Alert Script- An OpenRouter management key exported as
OPENROUTER_MGMT_KEYif you provision per-key credit limits viaPOST /api/v1/keys