From 091d44ab875380b894b7b29bfd3f2c5d3015fc1b Mon Sep 17 00:00:00 2001 From: Kagamine Rin Date: Sat, 13 Jun 2026 16:48:13 -0400 Subject: [PATCH] =?UTF-8?q?refactor:=20invert=20hide=5Fzero=5Fspend=20?= =?UTF-8?q?=E2=86=92=20show=5Fzero=5Fspend,=20default=20False?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes the API from opt-in hiding (hide_zero_spend) to opt-in showing (show_zero_spend). Default behavior now hides sub-bash.001 models and shows the summary line — cleaner for the common case where free-tier models dominate the breakdown. - Renamed parameter: hide_zero_spend → show_zero_spend - Inverted logic: default False means hide by default - Updated docstrings, README, ARCHITECTURE.md --- ARCHITECTURE.md | 10 ++++++---- README.md | 2 +- litellm_dashboard.py | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index a967335..11bf123 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -93,7 +93,7 @@ Healthy: 8 | Unhealthy: 0 **LiteLLM Endpoint:** `GET {litellm_url}/user/daily/activity` **Auth:** `Authorization: Bearer {litellm_master_key}` -**Params:** `start_date` (YYYY-MM-DD or natural language shortcut), `end_date` (YYYY-MM-DD or natural language shortcut), `hide_zero_spend` (bool, default False) +**Params:** `start_date` (YYYY-MM-DD or natural language shortcut), `end_date` (YYYY-MM-DD or natural language shortcut), `show_zero_spend` (bool, default False) ### Natural Language Date Resolution @@ -109,9 +109,11 @@ The `_resolve_date()` helper converts natural language shortcuts to YYYY-MM-DD b Already-formatted YYYY-MM-DD strings pass through unchanged. Unrecognized strings are passed to the API, which will reject them with a clear error. -### hide_zero_spend Parameter +### show_zero_spend Parameter -When `hide_zero_spend=True`, models with sub-$0.001 spend are filtered from the per-model breakdown. This is useful when free-tier or subscription models (e.g., Ollama Cloud) dominate the report with high token counts but negligible cost. Hidden models are summarized as `... (N model(s) with sub-$0.001 spend hidden)`. +When `show_zero_spend=False` (the default), models with sub-$0.001 spend are hidden from the per-model breakdown and summarized as `... (N model(s) with sub-$0.001 spend hidden)`. This is the recommended default because free-tier or subscription models (e.g., Ollama Cloud) often dominate the report with high token counts but negligible cost, drowning out the models that actually cost money. + +Set `show_zero_spend=True` to see all models, including those with zero or near-zero spend. ### Response Processing @@ -256,7 +258,7 @@ These are documented but not in scope for v1. The two-function design is the rig ### v1.2.0 (2026-06-13) - **feat:** Natural language date shortcuts for `litellm_cost()` — `today`, `yesterday`, `monday`, `last week`, etc. -- **feat:** `hide_zero_spend` parameter for `litellm_cost()` — filters sub-$0.001 models from breakdown +- **feat:** `show_zero_spend` parameter for `litellm_cost()` — default False hides sub-$0.001 models with summary line - **fix:** Cost report header shows resolved YYYY-MM-DD dates instead of raw shortcuts ### v1.1.0 (2026-06-13) diff --git a/README.md b/README.md index 10548cd..9e7149d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Get LiteLLM cost breakdown for a date range. Returns per-model and per-day spend **Parameters:** - `start_date` (str, required): Start date — YYYY-MM-DD or natural language shortcut (e.g. "2026-06-01", "today", "yesterday", "monday", "last monday", "two days ago", "this week", "last month") - `end_date` (str, required): End date — YYYY-MM-DD or natural language shortcut -- `hide_zero_spend` (bool, default false): Hide models with sub-$0.001 spend. Useful when free-tier or subscription models (e.g. Ollama Cloud) dominate the breakdown with high token counts but negligible cost. +- `show_zero_spend` (bool, default false): Show models with sub-$0.001 spend. When false, these models are hidden and summarized as "... (N model(s) with sub-$0.001 spend hidden)". Useful when free-tier or subscription models (e.g. Ollama Cloud) dominate the breakdown with high token counts but negligible 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 7916e58..9205382 100644 --- a/litellm_dashboard.py +++ b/litellm_dashboard.py @@ -190,13 +190,13 @@ class Tools: self, start_date: str, end_date: str, - hide_zero_spend: bool = False, + show_zero_spend: bool = False, ) -> str: """ Get LiteLLM cost breakdown for a date range. :param start_date: Start date — YYYY-MM-DD or natural language shortcut (e.g. "2026-06-01", "today", "yesterday", "monday", "last monday", "two days ago", "this week", "last month") :param end_date: End date — YYYY-MM-DD or natural language shortcut - :param hide_zero_spend: Hide models with sub-$0.001 spend (default False). Useful when free-tier or subscription models (e.g. Ollama Cloud) dominate the breakdown with high token counts but negligible cost. + :param show_zero_spend: Show models with sub-$0.001 spend (default False). When False, these models are hidden and summarized as "... (N model(s) with sub-$0.001 spend hidden)". Useful when free-tier or subscription models (e.g. Ollama Cloud) dominate the breakdown with high token counts but negligible 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: @@ -284,7 +284,7 @@ class Tools: 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.001: + if not show_zero_spend and mt["spend"] < 0.001: hidden_count += 1 continue # Strip common provider prefixes for readability