From 6adcd79c1aeebab2d0db1b09054e2fc1f769d1d7 Mon Sep 17 00:00:00 2001 From: Kagamine Rin Date: Sat, 13 Jun 2026 16:21:49 -0400 Subject: [PATCH] feat: add hide_zero_spend parameter to litellm_cost() Adds optional hide_zero_spend parameter (default False) to filter out models with bash.00 spend from the per-model breakdown. Useful when free-tier or subscription models (e.g. Ollama Cloud) dominate the breakdown with high token counts but zero cost. - Updated litellm_cost() signature with hide_zero_spend parameter - Added filtering logic in model line builder - Added hidden model count summary line - Updated README with parameter documentation - Bumped version to 1.2.0 --- README.md | 5 +++++ litellm_dashboard.py | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b631265..4e65030 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,11 @@ Check LiteLLM proxy health and authentication status. Returns which models are h ### `litellm_cost` Get LiteLLM cost breakdown for a date range. Returns per-model and per-day spend, token counts, cache hit rate, and request stats. +**Parameters:** +- `start_date` (str, required): Start date in YYYY-MM-DD format +- `end_date` (str, required): End date in YYYY-MM-DD format +- `hide_zero_spend` (bool, default false): Hide models with $0.00 spend. Useful when free-tier or subscription models (e.g. Ollama Cloud) dominate the breakdown with high token counts but zero cost. + ### `litellm_history` Get recent LiteLLM request history. Returns the most recent N requests with model, call type, status, duration, token counts, cache hit %, and per-request cost. Useful for understanding which models are being called and how much individual requests cost. diff --git a/litellm_dashboard.py b/litellm_dashboard.py index 54776cd..49e5eff 100644 --- a/litellm_dashboard.py +++ b/litellm_dashboard.py @@ -5,7 +5,7 @@ author_url: https://rin.captcouch.xyz description: Check LiteLLM proxy health + auth status and get cost breakdowns with configurable timerange. Two functions, that's it. required_open_webui_version: 0.4.0 requirements: requests -version: 1.1.0 +version: 1.2.0 licence: MIT """ @@ -119,11 +119,13 @@ class Tools: self, start_date: str, end_date: str, + hide_zero_spend: bool = False, ) -> str: """ Get LiteLLM cost breakdown for a date range. :param start_date: Start date in YYYY-MM-DD format (e.g. "2026-06-01") :param end_date: End date in YYYY-MM-DD format (e.g. "2026-06-04") + :param hide_zero_spend: Hide models with $0.00 spend (default False). Useful when free-tier or subscription models (e.g. Ollama Cloud) dominate the breakdown with high token counts but zero cost. Returns formatted cost report with per-model and per-day breakdowns, token counts, cache hit rate, and request stats. """ if not self.valves.litellm_master_key: @@ -205,8 +207,12 @@ class Tools: # Build model lines sorted by spend model_lines = [] + hidden_count = 0 for model_name in sorted(model_totals, key=lambda k: model_totals[k]["spend"], reverse=True): mt = model_totals[model_name] + if hide_zero_spend and mt["spend"] == 0: + hidden_count += 1 + continue # Strip common provider prefixes for readability display = model_name for prefix in ("gemini/", "openai/", "anthropic/", "mistral/", "cohere/"): @@ -237,6 +243,8 @@ class Tools: lines.append("By Model:") lines.append(f' {"Model":25s} {"Spend":>7s} | {"Requests":>14s} | {"Tokens":>10s}') lines.extend(model_lines) + if hidden_count > 0: + lines.append(f" ... ({hidden_count} model(s) with $0.00 spend hidden)") lines.append("") lines.append("By Date:") lines.extend(date_lines) @@ -406,4 +414,4 @@ class Tools: f"{recent_prompt:,} prompt + {recent_completion:,} completion tokens | " f"{recent_failed} failed") - return "\n".join(lines) \ No newline at end of file + return "\n".join(lines)