Agent skill · security · jeremylongshore

openrouter-audit-logging

Implement audit logging for OpenRouter API calls. Use when building

Why this skill is useful

Provides domain-specific knowledge on implementing audit logging for OpenRouter API calls, including structured logging and compliance trails.

What it needs

Requires python3, sqlite3 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 Audit Logging Overview Every OpenRouter API call returns a generation ID and metadata that enables comprehensive audit logging. The generation endpoint (GET /api/v1/generation?id=) provides exact cost, token counts, provider used, and latency -- data that the initial response doesn't always include. This skill covers structured logging, cost tracking, PII redaction, and compliance-ready audit trails. 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 and requests (pip install openai requests) — the audit wrapper fetches exact cost from the generation endpoint with requests SQLite: the Python stdlib sqlite3 module writes the audit table; the sqlite3 CLI runs the Audit Queries against openrouteraudit.db Optional: a SIEM destination (Splunk, Datadog, ELK) if you ship the structured JSON log lines downstream Instructions 1. Export your key and wire auditedcompletion() from Core: Generation Metadata Retrieval — it hashes the prompt (SHA-256), times the call, and fetches exact cost via GET /api/v1/generation?id= after each request. 2. Create the append-only store with initauditdb() per Structured Log Storage, then persist every AuditEntry with writeaudit() — INSERT OR IGNORE keeps retries from double-writing a generationid. 3. Run redactpii() from PII Redaction Before Logging over any prompt preview before it touches a log: emails, phones, SSNs, card numbers, and sk-or-v1- keys are scrubbed, and raw prompts are never stored (hashes only). 4. Answer operational questions with the Audit Queries SQL: daily cost by model, error rate per model over the last 24 hours, and top spenders by userid. 5. If the generation fetch 404s or totalcost comes back missing, apply the fixes in Error Handling (fetch within 30 minutes; retry after 1-2 seconds). 6. …

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills jeremylongshore/openrouter-audit-logging

View the source on GitHub

Browse the @skills marketplace