openrouter-audit-logging

Featured

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'.

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 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. ## Core: Generation Metadata Retrieval ```python import os, json, time, hashlib, logging from datetime import datetime, timezone from dataclasses import dataclass, asdict from typing import Optional import requests from openai import OpenAI log = logging.getLogger("openrouter.audit") @dataclass class AuditEntry: timestamp: str generation_id: str model_requested: str model_used: str # Actual model served (may differ with fallbacks) prompt_tokens: int completion_tokens: int total_cost: float latency_ms: float status: str # "success" | "error" | "timeout" user_id: str prompt_hash: str # SHA-256 of prompt (not raw content) error_code: Optional[str] = None 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 audited_completion( messages: list[dict], model: str = "anthropic/claude-3.5-sonnet", user_id: str = "...

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

AI & Automation Featured

openrouter-usage-analytics

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'.

2,266 Updated today
jeremylongshore
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-compliance-review

Review OpenRouter integration for regulatory compliance (SOC2, GDPR, HIPAA). Use when preparing for audits, evaluating data handling, or documenting compliance posture. Triggers: 'openrouter compliance', 'openrouter gdpr', 'openrouter soc2', 'openrouter data residency'.

2,266 Updated today
jeremylongshore
AI & Automation Featured

openrouter-debug-bundle

Create debug bundles for troubleshooting OpenRouter API issues. Use when diagnosing failures, unexpected responses, or latency problems. Triggers: 'openrouter debug', 'openrouter troubleshoot', 'debug openrouter request', 'openrouter issue'.

2,266 Updated today
jeremylongshore
AI & Automation Featured

openrouter-reference-architecture

Design production architectures using OpenRouter as the LLM gateway. Use when planning system design, reviewing architecture, or scaling AI applications. Triggers: 'openrouter architecture', 'openrouter system design', 'openrouter at scale', 'llm gateway architecture'.

2,266 Updated today
jeremylongshore