openrouter-usage-analytics

Featured

Track and analyze OpenRouter API usage patterns, costs, and performance. Use when building dashboards, optimizing spend, or reporting on AI usage. Triggers: 'openrouter analytics', 'openrouter usage', 'openrouter metrics', 'track openrouter spend'.

AI & Automation 2,266 stars 315 forks Updated today MIT

Install

View on GitHub

Quality Score: 99/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# 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. ## Collect Per-Request Metrics ```python import os, time, json, logging from datetime import datetime, timezone from openai import OpenAI import requests as http_requests log = logging.getLogger("openrouter.analytics") client = OpenAI( base_url="https://openrouter.ai/api/v1", api_key=os.environ["OPENROUTER_API_KEY"], default_headers={"HTTP-Referer": "https://my-app.com", "X-Title": "my-app"}, ) def tracked_completion(messages, model="openai/gpt-4o-mini", user_id="system", **kwargs): """Make a completion and capture full analytics.""" start = time.monotonic() response = client.chat.completions.create( model=model, messages=messages, **kwargs ) latency = (time.monotonic() - start) * 1000 # Fetch exact cost from generation endpoint cost = 0.0 try: gen = http_requests.get( f"https://openrouter.ai/api/v1/generation?id={response.id}", headers={"Authorization": f"Bearer {os.environ['OPENROUTER_API_KEY']}"}, timeout=5, ).json() cost = float(gen.get("data", {}).get("total_cost", 0)) ...

Details

Author
jeremylongshore
Repository
jeremylongshore/claude-code-plugins-plus-skills
Created
7 months ago
Last Updated
today
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category

API & Backend Listed

openrouter-usage

Query OpenRouter API costs, credits, and usage breakdown by model, provider, and date. This skill should be used when checking API spending, auditing costs, or generating usage reports for the last 30 days.

33 Updated yesterday
tdimino
AI & Automation Featured

openrouter-audit-logging

Implement audit logging for OpenRouter API calls. Use when building compliance trails, debugging production issues, or tracking model usage. Triggers: 'openrouter audit', 'openrouter logging', 'audit trail openrouter', 'log openrouter requests'.

2,266 Updated today
jeremylongshore
AI & Automation Featured

openrouter-pricing-basics

Understand OpenRouter pricing, calculate costs, and optimize spend. Use when budgeting, comparing model costs, or tracking spend. Triggers: 'openrouter pricing', 'openrouter cost', 'model pricing', 'openrouter budget', 'how much does openrouter cost'.

2,266 Updated today
jeremylongshore
AI & Automation Featured

openrouter-hello-world

Send your first OpenRouter API request and understand the response. Use when learning OpenRouter, testing setup, or verifying connectivity. Triggers: 'openrouter hello world', 'openrouter first request', 'test openrouter', 'openrouter quickstart'.

2,266 Updated today
jeremylongshore
AI & Automation Featured

openrouter-cost-controls

Implement cost controls for OpenRouter API usage. Use when setting budgets, preventing overspend, or managing per-key limits. Triggers: 'openrouter budget', 'openrouter cost limit', 'openrouter spending', 'control openrouter cost'.

2,266 Updated today
jeremylongshore