diff --git a/litellm_dashboard.py b/litellm_dashboard.py index 682657d..54776cd 100644 --- a/litellm_dashboard.py +++ b/litellm_dashboard.py @@ -247,11 +247,13 @@ class Tools: self, limit: int = 20, show_cost: bool = True, + show_failed: bool = True, ) -> str: """ Get recent LiteLLM proxy request history. :param limit: Number of recent requests to show (1-50, default 20) :param show_cost: Include per-request cost (default True) + :param show_failed: Include failed requests in output (default True). Set False to hide auth failures, routing errors, etc. Returns a formatted table of recent LLM requests with model, status, tokens, duration, and optional cost. """ if not self.valves.litellm_master_key: @@ -282,12 +284,24 @@ class Tools: # Sort by startTime descending and take the most recent `limit` entries sorted_logs = sorted(data, key=lambda e: e.get("startTime", ""), reverse=True) + + # Filter out failed requests if show_failed is False + if not show_failed: + sorted_logs = [ + e for e in sorted_logs + if not ( + (e.get("metadata", {}) or {}).get("exception", "") + or (e.get("metadata", {}) or {}).get("status", "") == "failure" + ) + ] + recent = sorted_logs[:limit] total_count = len(data) + filtered_note = " (failed requests hidden)" if not show_failed else "" lines = [] lines.append(f"LiteLLM Request History — {self._base_url()}") - lines.append(f"Showing {len(recent)} of {total_count} total requests (most recent first)") + lines.append(f"Showing {len(recent)} of {total_count} total requests{filtered_note} (most recent first)") lines.append("=" * 90) for i, entry in enumerate(recent, 1):