feat: add show_failed parameter to litellm_history (default true)
When show_failed=False, filters out requests with metadata.exception or metadata.status='failure' before applying the limit. Useful for hiding auth probe noise and routing failures. Header shows '(failed requests hidden)' when active.
This commit is contained in:
1 parent
abc3b7b191
commit
8a8be608a0
1 file changed
+15
-1
+15
-1
@@ -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):
|
||||
|
||||
Reference in new issue
Block a user