From 3bd18ef77312a69629bda244b85e45896013a75b Mon Sep 17 00:00:00 2001 From: Bungic <71993947+Bungic@users.noreply.github.com> Date: Thu, 28 May 2026 18:40:11 +0300 Subject: [PATCH] fix(prometheus): rate-limit gauges drop the emit when value is 0 The remaining_requests and remaining_tokens gauges are guarded by a truthy check: if remaining_requests: ...emit metric When the value is 0 (the upstream has actually exhausted the user's quota), Python evaluates 0 as falsy and the metric is never emitted. This is exactly the moment the metric is most useful for alerting. The rest of this file already uses the correct `is not None` pattern for similar nullable values (lines 1688, 1710, 1856, 1868, 1901, etc.), and even for these exact variables in the *non*-init path at lines 2419 and 2431. The two checks at 2519 and 2537 are the holdouts. Changed truthy to `is not None`. No behavior change when the upstream header is genuinely absent (still skipped); only difference is that 0 now flows through to the gauge. --- litellm/integrations/prometheus.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/litellm/integrations/prometheus.py b/litellm/integrations/prometheus.py index 64d4dd578b2..ad1f52c2259 100644 --- a/litellm/integrations/prometheus.py +++ b/litellm/integrations/prometheus.py @@ -2691,7 +2691,7 @@ class PrometheusLogger(CustomLogger): label_context=label_context, ) - if remaining_requests: + if remaining_requests is not None: """ "model_group", "api_provider", @@ -2705,7 +2705,7 @@ class PrometheusLogger(CustomLogger): ) self.litellm_remaining_requests_metric.labels(**_labels).set(remaining_requests) - if remaining_tokens: + if remaining_tokens is not None: _labels = prometheus_label_factory( supported_enum_labels=self.get_labels_for_metric(metric_name="litellm_remaining_tokens_metric"), enum_values=enum_values,