Agent skill · data analytics · jeremylongshore
openrouter-usage-analytics
Track and analyze OpenRouter API usage patterns, costs, and performance.
Why this skill is useful
Provides specific commands and analytics patterns for tracking OpenRouter API usage and costs that the AI wouldn't reliably generate on its own.
What it needs
Requires curl, jq, python3 installed locally. Requires openrouter account access. About 5k tokens when loaded. Last updated 2026-08-07. 2,604 stars on the source repository.
What this skill does
OpenRouter Usage Analytics Overview OpenRouter provides usage data through three endpoints: GET /api/v1/auth/key (credit balance and rate limits), GET /api/v1/generation?id= (per-request cost and metadata), and response usage fields (token counts). This skill covers collecting metrics from these sources, building analytics pipelines, cost reporting, and performance dashboards. 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 plus requests (used to fetch exact per-request cost from the generation endpoint); sqlite3 (stdlib) backs the analytics database curl and jq for the Credit Balance Monitoring one-liner HTTP-Referer / X-Title headers set on the client if you also want OpenRouter dashboard attribution Instructions 1. Route completions through trackedcompletion (Collect Per-Request Metrics) — it times each call, then fetches the exact totalcost from GET /api/v1/generation?id= and emits a JSON metric with tokens, latency, and modelrequested vs modelused. 2. Initialize openrouteranalytics.db with initanalyticsdb (Analytics Database) and persist every metric via storemetric — the generationid unique constraint plus INSERT OR IGNORE deduplicates retries. 3. Query the store with the Analytics Queries: daily cost summary, cost by model, top users by spend, hourly request pattern, and 30-day cost trend. 4. Watch remaining credits with the Credit Balance Monitoring snippet — curl + jq against /api/v1/auth/key reports creditsused, creditlimit, and remaining. 5. Generate the Weekly Report Generator output for stakeholders (totals plus top 5 models by cost). 6. Apply the retention and alerting policies from Enterprise Considerations (aggregate raw rows after 30 days, alert when daily cost exceeds 2x the historical average). …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills jeremylongshore/openrouter-usage-analytics--694e6b