Skip to content
Back to skills

Openrouter Cost Controls

ASecurity

Implement cost control mechanisms for OpenRouter usage. Use when managing budgets or preventing overspend. Trigger with phrases like 'openrouter budget', 'openrouter spending limit', 'cost control', 'openrouter limit spend'.

  • 4 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 10, 2026
documentationapidocumentation

Works with

  • api

Security analysis

A100/100

Pro scans all 8 files and shows the line behind each finding

Scanned September 10, 2026

npx -y skills add micsapp/micstec-skills --skill openrouter-cost-controls --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Openrouter Cost Controls?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Openrouter Cost Controls
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/micsapp-openrouter-cost-controls/badge)](https://www.skillsdirectory.com/skills/micsapp-openrouter-cost-controls)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: openrouter-cost-controls
description: |
  Implement cost control mechanisms for OpenRouter usage. Use when managing budgets or preventing overspend. Trigger with phrases like 'openrouter budget', 'openrouter spending limit', 'cost control', 'openrouter limit spend'.
allowed-tools: Read, Write, Edit, Grep
version: 1.0.0
license: MIT
author: Jeremy Longshore <jeremy@intentsolutions.io>
compatible-with: claude-code, codex, openclaw
---
# Openrouter Cost Controls

## Overview

This skill demonstrates setting up spending limits, per-request budgets, and automated cost monitoring to prevent unexpected charges.

## Prerequisites

- OpenRouter account with credit management access
- Understanding of model pricing tiers

## Instructions

1. **Set account-level limits**: Configure spending limits in the OpenRouter dashboard under Settings > Limits to cap total monthly spend
2. **Use per-request max_tokens**: Always set `max_tokens` in every request to cap completion length and prevent runaway costs
3. **Track costs per request**: Read the `usage` field in each response and multiply by model pricing to track cumulative spend in your application
4. **Implement budget middleware**: Create a middleware that checks cumulative spend before each request and rejects requests that would exceed the budget
5. **Set up alerts**: Query `/api/v1/auth/key` periodically to check remaining credits and alert when balance drops below a threshold

## Output

- Per-request cost tracking integrated into your application
- Budget enforcement middleware that blocks requests over the limit
- Automated alerts when spending approaches configured thresholds

## Error Handling

| Error | Cause | Fix |
|-------|-------|-----|
| 402 Payment Required | Account credits exhausted | Top up credits or switch to free models |
| Budget exceeded locally | Middleware blocked the request | Increase budget limit or optimize prompts to reduce token usage |
| Inaccurate cost tracking | Using stale pricing data | Refresh model pricing from `/models` endpoint daily |

See `${CLAUDE_SKILL_DIR}/references/errors.md` for full error reference.

## Examples

See `${CLAUDE_SKILL_DIR}/references/examples.md` for runnable code samples.

## Resources

- [OpenRouter Documentation](https://openrouter.ai/docs)
- [OpenRouter Models](https://openrouter.ai/models)
- [OpenRouter API Reference](https://openrouter.ai/docs/api-reference)
- [OpenRouter Status](https://status.openrouter.ai)

Files in this skill

  • SKILL.md2.4 KB
  • references/automatic-cost-controls.md2.9 KB
  • references/budget-alerts.md2.8 KB
  • references/budget-tracking.md2.7 KB
  • references/cost-dashboard.md1.2 KB
  • references/errors.md323 B
  • references/examples.md4.1 KB
  • references/request-level-controls.md2.2 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.