Files
openrouter-watcher/src/openrouter_monitor/main.py
Luca Sacchi Ricciardi 16f740f023 feat(stats): T32-T33 implement dashboard and usage endpoints
Add statistics router with two endpoints:
- GET /api/stats/dashboard: Aggregated dashboard statistics
  - Query param: days (1-365, default 30)
  - Auth required
  - Returns DashboardResponse

- GET /api/usage: Detailed usage statistics with filtering
  - Required params: start_date, end_date
  - Optional filters: api_key_id, model
  - Pagination: skip, limit (max 1000)
  - Auth required
  - Returns List[UsageStatsResponse]

Also add get_usage_stats() service function for querying
individual usage records with filtering and pagination.
2026-04-07 15:22:31 +02:00

48 lines
1.2 KiB
Python

"""FastAPI main application.
Main application entry point for OpenRouter API Key Monitor.
"""
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from openrouter_monitor.config import get_settings
from openrouter_monitor.routers import api_keys
from openrouter_monitor.routers import auth
from openrouter_monitor.routers import stats
settings = get_settings()
# Create FastAPI app
app = FastAPI(
title="OpenRouter API Key Monitor",
description="Monitor and manage OpenRouter API keys",
version="1.0.0",
debug=settings.debug,
)
# CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Configure appropriately for production
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include routers
app.include_router(auth.router, prefix="/api/auth", tags=["authentication"])
app.include_router(api_keys.router, prefix="/api/keys", tags=["api-keys"])
app.include_router(stats.router)
@app.get("/")
async def root():
"""Root endpoint."""
return {"message": "OpenRouter API Key Monitor API", "version": "1.0.0"}
@app.get("/health")
async def health_check():
"""Health check endpoint."""
return {"status": "healthy"}