AI Cost Estimator

Estimate your AI coding costs

← Back to Blog

How to Track and Reduce AI Token Spending With OpenRouter Analytics

June 10, 2026 · 7 min read

Analytics dashboard with charts and graphs showing spending data

Why You Need Token Spending Visibility

Most developers using AI coding tools have no idea where their money goes. They see a monthly bill — $80, $150, $300 — but cannot answer basic questions: Which model costs the most? Which tasks consume the most tokens? Am I overpaying for simple operations? OpenRouter solves this by routing all your AI API calls through a single dashboard with per-model, per-app, and per-request analytics.

OpenRouter is an API aggregator that provides access to every major model — Claude Opus 4.8, Sonnet 4.6, GPT-4o, DeepSeek V4 Flash, Gemini 2.5 Pro — through a single API key. Beyond convenience, its killer feature for cost management is the analytics dashboard that shows exactly where every token goes.

Setting Up OpenRouter for Cost Tracking

Getting started takes under 5 minutes. Create an account at openrouter.ai, generate an API key, and replace your direct provider API keys in your tools:

  • Aider: Set OPENROUTER_API_KEY as your environment variable and prefix model names with openrouter/
  • Custom scripts: Point your base URL to https://openrouter.ai/api/v1 — it is OpenAI-compatible
  • LangChain/LlamaIndex: Use the OpenAI-compatible client with OpenRouter's base URL

Pro tip: use separate API keys for different projects or tools. This automatically segments your spending in the dashboard without any additional configuration.

The Analytics Dashboard: Key Features

Once your traffic flows through OpenRouter, the dashboard shows:

  • Per-model cost breakdown: See exactly how much each model costs you daily, weekly, and monthly. Instantly identify if you are over-using expensive models.
  • Per-app tracking: If you set the HTTP-Referer or X-Title header, each tool/app gets its own spending chart. Compare Aider vs your custom agent vs ad-hoc scripts.
  • Request-level detail: Token counts (input/output), cost, latency, and model used for every single request. Find the outliers.
  • Daily spending graph: Visual trend of your spending over time. Spot anomalies immediately — a spike usually means a runaway retry loop or an unexpectedly large context.
  • Credit balance and alerts: Set up low-balance notifications so you never get cut off mid-task.

Step 1: Identify Your Most Expensive Prompts

After running for one week, sort your requests by cost (descending). You will likely find a Pareto pattern: 20% of your requests account for 80% of your spending. Common culprits:

PatternTypical Input TokensCost Per Request (Sonnet)Fix
Full repo context loads100-200K$0.30-0.60Use targeted file selection
Retry loops (3-5 attempts)200-400K cumulative$0.60-1.20Set token budgets, circuit breakers
Long code generation30-50K in, 20-40K out$0.40-0.70Break into smaller tasks
Repeated system prompts10-20K per request$0.03-0.06 (adds up)Use prompt caching

Step 2: Switch Models for Specific Tasks

The dashboard reveals which tasks you are running on expensive models that could be handled by cheaper ones. Common switches that maintain quality:

TaskCurrent ModelSwitch ToSavings
Test generationClaude Sonnet 4.6 ($3/$15)DeepSeek V4 Flash ($0.14/$0.28)95%
Code review summariesClaude Opus 4.8 ($5/$25)Claude Sonnet 4.6 ($3/$15)40%
Commit messagesClaude Sonnet 4.6 ($3/$15)Haiku 4.5 ($1/$5)67%
DocumentationClaude Sonnet 4.6 ($3/$15)Gemini 2.5 Pro ($1.25/$10)50%
Boilerplate/CRUDClaude Sonnet 4.6 ($3/$15)DeepSeek V4 Flash ($0.14/$0.28)95%

A developer who routes 60% of requests to cheaper models while keeping Sonnet/Opus for complex work typically sees 50-65% total cost reduction with minimal quality impact.

Step 3: Set Daily Spending Limits

OpenRouter allows you to set credit limits per API key. Use this to prevent budget overruns:

  • Daily limit: Set to your monthly budget / 22 working days. If your budget is $100/month, set $4.50/day.
  • Per-key limits: Give each tool its own key with its own budget. Aider gets $2/day, your custom agent gets $2/day, experiments get $0.50/day.
  • Alert thresholds: Set notifications at 50% and 80% of daily budget so you can adjust behavior before hitting the cap.

Recommended thresholds for solo developers:

Budget LevelMonthlyDaily LimitAlert atSuitable For
Budget$30$1.50$0.75 / $1.20Side projects, learning
Standard$100$4.50$2.25 / $3.60Active solo dev
Professional$250$11.50$5.75 / $9.20Full-time AI-assisted dev

Step 4: Optimize Your Highest-Volume Requests

The dashboard's request log reveals optimization opportunities that are invisible without data. Look for:

Repeated identical prefixes: If 80% of your requests start with the same 5K-token system prompt, enable prompt caching. Anthropic's prompt caching reduces the cost of cached tokens by 90%. On 50 requests/day with a 5K shared prefix, that saves $0.67/day or $20/month.

Unnecessarily large contexts: If your average input is 80K tokens but your tasks only need 30K of relevant context, you are paying 2.5x too much for input. Trim file contexts to only include relevant sections rather than full files.

Output tokens you discard: If your agent generates verbose explanations but you only use the code blocks, configure the model to skip explanations. A system prompt instruction like "output only code, no explanations" can cut output tokens by 40-60%.

Step 5: Weekly Review Ritual (10 Minutes)

Set a weekly calendar reminder to review your OpenRouter dashboard. Check:

  • Total spend vs budget — are you on track?
  • Top 5 most expensive requests — any surprises or anomalies?
  • Model distribution — is expensive model usage justified or lazy?
  • Daily trend — any spikes that indicate runaway processes?
  • New models available — any cheaper alternatives launched this week?

This 10-minute review typically finds $10-30 in monthly savings each time for the first few months as you identify and fix spending patterns.

Advanced: Automated Cost Alerts via API

OpenRouter exposes usage data via API, enabling automated monitoring. Useful automations:

  • Slack alert on daily spend threshold: Query the API hourly, alert if pace exceeds 120% of daily budget.
  • Auto-switch to cheaper model: When budget hits 80%, automatically route remaining requests to DeepSeek V4 Flash instead of Sonnet.
  • Weekly digest email: Summarize spending by model, app, and day — useful for teams managing shared budgets.

Real Results: Before and After OpenRouter Analytics

A typical optimization journey for a solo developer:

MetricBefore (Month 1)After (Month 3)
Monthly spend$180$72
Tasks completed~400~420
Avg cost per task$0.45$0.17
% on expensive models95%30%
Waste from retries~$50 (unknown)~$8 (measured)

The biggest win was not any single optimization — it was visibility. Once you can see where tokens go, the obvious optimizations become actionable. You cannot reduce what you cannot measure.

Getting Started Today

The minimum viable cost tracking setup takes 5 minutes: create an OpenRouter account, generate an API key, and route one of your tools through it. Run for one week without changing anything — just observe. The dashboard will immediately show you patterns you did not know existed. Then start with the highest-impact change: switch your most frequent task to a cheaper model and verify quality is acceptable.

Most developers find that 40-60% of their AI coding spend is optimizable without sacrificing quality on the tasks that matter. The data makes the decisions obvious. You just need to look.

Want to calculate exact costs for your project?