Openrouter Usage Analytics
Overview
This skill demonstrates building usage analytics for OpenRouter to track costs, token usage, model popularity, and performance metrics over time.
Prerequisites
- OpenRouter integration with logging
- Data storage for metrics (database, time-series DB, or analytics service)
Instructions
- Instrument API calls: Add middleware that captures timestamp, model, prompt/completion token counts, cost, latency, and status for every request
- Store metrics efficiently: Write metrics to a time-series database (InfluxDB, TimescaleDB) or append-only table with proper indexing on timestamp and model
- Build aggregation queries: Create queries for daily/weekly cost by model, average latency trends, token usage distribution, and error rates
- Create a dashboard: Visualize key metrics — total spend over time, cost per model, average latency, requests per hour, and error rate trends
- Set up automated reports: Schedule daily or weekly summary emails/alerts with top-line metrics and any anomalies detected
Output
- Analytics pipeline capturing cost, latency, and usage per request
- Dashboard with charts for spend, token usage, model distribution, and errors
- Automated weekly report summarizing key usage trends and anomalies
Error Handling
| Error |
Cause |
Fix |
| Missing metrics for some requests |
Instrumentation middleware not covering all paths |
Centralize all API calls through a single instrumented client |
| Metric storage growing too fast |
High request volume with verbose logging |
Aggregate metrics hourly/daily; keep raw data only for recent period |
| Dashboard showing stale data |
Query or aggregation pipeline lagging |
Check pipeline health; add alerting on data freshness |
See ${CLAUDE_SKILL_DIR}/references/errors.md for full error reference.
Examples
See ${CLAUDE_SKILL_DIR}/references/examples.md for runnable code samples.
Resources
1---2name: openrouter-usage-analytics3description: |4 Track and analyze OpenRouter API usage patterns. Use when optimizing costs or understanding usage trends. Trigger with phrases like 'openrouter analytics', 'openrouter usage', 'openrouter metrics', 'track openrouter'.5allowed-tools: Read, Write, Edit, Grep6version: 1.0.07license: MIT8author: Jeremy Longshore <jeremy@intentsolutions.io>9compatible-with: claude-code, codex, openclaw10---1112# Openrouter Usage Analytics1314## Overview1516This skill demonstrates building usage analytics for OpenRouter to track costs, token usage, model popularity, and performance metrics over time.1718## Prerequisites1920- OpenRouter integration with logging21- Data storage for metrics (database, time-series DB, or analytics service)2223## Instructions24251. **Instrument API calls**: Add middleware that captures timestamp, model, prompt/completion token counts, cost, latency, and status for every request262. **Store metrics efficiently**: Write metrics to a time-series database (InfluxDB, TimescaleDB) or append-only table with proper indexing on timestamp and model273. **Build aggregation queries**: Create queries for daily/weekly cost by model, average latency trends, token usage distribution, and error rates284. **Create a dashboard**: Visualize key metrics — total spend over time, cost per model, average latency, requests per hour, and error rate trends295. **Set up automated reports**: Schedule daily or weekly summary emails/alerts with top-line metrics and any anomalies detected3031## Output3233- Analytics pipeline capturing cost, latency, and usage per request34- Dashboard with charts for spend, token usage, model distribution, and errors35- Automated weekly report summarizing key usage trends and anomalies3637## Error Handling3839| Error | Cause | Fix |40|-------|-------|-----|41| Missing metrics for some requests | Instrumentation middleware not covering all paths | Centralize all API calls through a single instrumented client |42| Metric storage growing too fast | High request volume with verbose logging | Aggregate metrics hourly/daily; keep raw data only for recent period |43| Dashboard showing stale data | Query or aggregation pipeline lagging | Check pipeline health; add alerting on data freshness |4445See `${CLAUDE_SKILL_DIR}/references/errors.md` for full error reference.4647## Examples4849See `${CLAUDE_SKILL_DIR}/references/examples.md` for runnable code samples.5051## Resources5253- [OpenRouter Documentation](https://openrouter.ai/docs)54- [OpenRouter Models](https://openrouter.ai/models)55- [OpenRouter API Reference](https://openrouter.ai/docs/api-reference)56- [OpenRouter Status](https://status.openrouter.ai)