mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-11 17:52:31 +03:00
feat(db): track API endpoint dimension on usage_history
Add an `endpoint` column to `usage_history` (migration 103) so the proxy records which API entry point a request came through — typically `/v1/chat/completions`, `/v1/messages`, or `/v1/responses`. Every `saveRequestUsage(...)` call site in `open-sse/handlers/chatCore.ts` (success, stream, failure) and the codex-responses-ws route now plumbs the endpoint through, and a new `getEndpointUsageRows(...)` analytics query in `src/lib/db/usageAnalytics.ts` aggregates per endpoint × provider × model with NULL → 'unknown' folding for backward compatibility with rows from before the migration. The aggregation reads directly from `usage_history` (matching the `getAutoRoutingVariantBreakdown` pattern) so the existing unified-source CTE — and the `daily_usage_summary` rollup it joins — stay untouched. TDD: tests/unit/usage-endpoint-dimension.test.ts covers persistence round-trip, NULL fallback, and the sinceIso filter (3/3 passing). Co-authored-by: toanalien <toanalien@gmail.com> Inspired-by: https://github.com/decolua/9router/pull/152
This commit is contained in:
@@ -199,7 +199,7 @@
|
||||
"src/lib/db/providers.ts": 1063,
|
||||
"src/lib/db/proxies.ts": 1057,
|
||||
"src/lib/db/settings.ts": 1149,
|
||||
"src/lib/db/usageAnalytics.ts": 873,
|
||||
"src/lib/db/usageAnalytics.ts": 925,
|
||||
"src/lib/evals/evalRunner.ts": 961,
|
||||
"src/lib/memory/retrieval.ts": 1171,
|
||||
"src/lib/modelsDevSync.ts": 934,
|
||||
|
||||
Reference in New Issue
Block a user