diff --git a/litellm/proxy/_lazy_openapi_snapshot.json b/litellm/proxy/_lazy_openapi_snapshot.json index 6575552c6fd..9a61a2d3f7a 100644 --- a/litellm/proxy/_lazy_openapi_snapshot.json +++ b/litellm/proxy/_lazy_openapi_snapshot.json @@ -3740,6 +3740,38 @@ "title": "AgentSkill", "type": "object" }, + "BoundedDailyActivityResponse": { + "properties": { + "metadata": { + "$ref": "#/components/schemas/DailySpendMetadata" + }, + "model_breakdown": { + "anyOf": [ + { + "$ref": "#/components/schemas/DailyActivityModelBreakdown" + }, + { + "type": "null" + } + ], + "description": "When requested, includes the highest-spend models across the full date range and an explicit aggregate of all remaining models. Daily totals always cover the complete activity scope. Other per-day dimension breakdowns are omitted." + }, + "results": { + "items": { + "$ref": "#/components/schemas/DailySpendData" + }, + "maxItems": 366, + "title": "Results", + "type": "array" + } + }, + "required": [ + "results", + "metadata" + ], + "title": "BoundedDailyActivityResponse", + "type": "object" + }, "BreakdownMetrics": { "description": "Breakdown of spend by different dimensions", "properties": { @@ -3851,6 +3883,82 @@ "title": "DailyActivityKeySearchResponse", "type": "object" }, + "DailyActivityModelBreakdown": { + "properties": { + "limit": { + "maximum": 100.0, + "minimum": 1.0, + "title": "Limit", + "type": "integer" + }, + "models": { + "items": { + "$ref": "#/components/schemas/DailyActivityModelContribution" + }, + "maxItems": 100, + "title": "Models", + "type": "array" + }, + "other": { + "anyOf": [ + { + "$ref": "#/components/schemas/DailyActivityOtherModels" + }, + { + "type": "null" + } + ] + }, + "total_models": { + "minimum": 0.0, + "title": "Total Models", + "type": "integer" + } + }, + "required": [ + "limit", + "total_models", + "models" + ], + "title": "DailyActivityModelBreakdown", + "type": "object" + }, + "DailyActivityModelContribution": { + "properties": { + "metrics": { + "$ref": "#/components/schemas/SpendMetrics" + }, + "model": { + "maxLength": 1024, + "title": "Model", + "type": "string" + } + }, + "required": [ + "model", + "metrics" + ], + "title": "DailyActivityModelContribution", + "type": "object" + }, + "DailyActivityOtherModels": { + "properties": { + "metrics": { + "$ref": "#/components/schemas/SpendMetrics" + }, + "model_count": { + "minimum": 1.0, + "title": "Model Count", + "type": "integer" + } + }, + "required": [ + "model_count", + "metrics" + ], + "title": "DailyActivityOtherModels", + "type": "object" + }, "DailySpendData": { "properties": { "breakdown": { @@ -5125,6 +5233,38 @@ "type": "integer" } }, + { + "in": "query", + "name": "bounded", + "required": false, + "schema": { + "default": false, + "title": "Bounded", + "type": "boolean" + } + }, + { + "in": "query", + "name": "include_model_breakdown", + "required": false, + "schema": { + "default": false, + "title": "Include Model Breakdown", + "type": "boolean" + } + }, + { + "in": "query", + "name": "model_limit", + "required": false, + "schema": { + "default": 20, + "maximum": 100, + "minimum": 1, + "title": "Model Limit", + "type": "integer" + } + }, { "in": "query", "name": "agent_ids", @@ -5243,7 +5383,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/SpendAnalyticsPaginatedResponse" + "anyOf": [ + { + "$ref": "#/components/schemas/SpendAnalyticsPaginatedResponse" + }, + { + "$ref": "#/components/schemas/BoundedDailyActivityResponse" + } + ], + "title": "Response Get Agent Daily Activity Aggregated Agent Daily Activity Aggregated Get" } } }, diff --git a/litellm/repositories/analytics_budget.py b/litellm/repositories/analytics_budget.py index a4d7cc42065..3e588a1ac6f 100644 --- a/litellm/repositories/analytics_budget.py +++ b/litellm/repositories/analytics_budget.py @@ -88,7 +88,11 @@ class BoundedAnalyticsDatabase: if _PostgresError.model_validate(error.meta or {}).code not in ("57014", "55P03"): raise raise AnalyticsCapacityError("Analytics exceeded its query budget. Try again shortly") from error - except (TransactionExpiredError, TransactionNotStartedError, asyncio.TimeoutError) as error: + except ( + TransactionExpiredError, + TransactionNotStartedError, + asyncio.TimeoutError, # pyright: ignore[reportDeprecated] # Python 3.10 uses a distinct asyncio timeout class + ) as error: raise AnalyticsCapacityError("Analytics exceeded its connection budget. Try again shortly") from error finally: self._admission.release() diff --git a/ui/litellm-dashboard/src/components/activity_metrics.tsx b/ui/litellm-dashboard/src/components/activity_metrics.tsx index 00f632f4097..928d393606b 100644 --- a/ui/litellm-dashboard/src/components/activity_metrics.tsx +++ b/ui/litellm-dashboard/src/components/activity_metrics.tsx @@ -155,7 +155,7 @@ const ModelTopKeys = ({ fetchTopApiKeys(modelName) .then((response) => { if (cancelled) return; - setSettled({ + const nextState = { modelName, fetchTopApiKeys, rows: response.api_keys.map((row) => ({ @@ -168,12 +168,14 @@ const ModelTopKeys = ({ tokens: row.metrics.total_tokens, })), failed: false, - }); + }; + setSettled(nextState); }) .catch((error) => { if (cancelled) return; console.error(`Failed to fetch top keys for ${modelName}:`, error); - setSettled({ modelName, fetchTopApiKeys, rows: [], failed: true }); + const failedState = { modelName, fetchTopApiKeys, rows: [], failed: true }; + setSettled(failedState); }); return () => { cancelled = true;