BerriAI/litellm · error · Exception
Missing prometheus_client. Run `pip install…
Error message
Missing prometheus_client. Run `pip install prometheus-client`
What it means
PrometheusServices.__init__ imports prometheus_client (Counter/Gauge/Histogram/REGISTRY plus gc_collector.Collector); on ImportError it converts to this Exception with the pip hint. litellm's core install does not hard-require prometheus-client — it ships in the [proxy] extra — so enabling prometheus callbacks on a bare install fails at callback construction with exactly this message.
Solutions
- pip install prometheus-client in the same environment that runs litellm
- Or install the bundle: pip install 'litellm[proxy]' which includes prometheus-client
- Rebuild the Docker image with the extra and confirm with python -c "import prometheus_client"
- If metrics are unwanted, remove the prometheus callback from config instead of shipping the dependency
Example fix
# before pip install litellm # proxy config: success_callback: ['prometheus'] -> Exception: Missing prometheus_client # after pip install 'litellm[proxy]' # or: pip install litellm prometheus-client
Defensive patterns
Strategy: validation
Validate before calling
import importlib.util
if importlib.util.find_spec('prometheus_client') is None:
raise RuntimeError('prometheus-client required for prometheus metrics: pip install prometheus-client') Try / catch
try:
from litellm.integrations.prometheus_services import PrometheusServices
services = PrometheusServices()
except Exception as e:
logger.warning('prometheus metrics disabled: %s', e)
services = None Prevention
- Install litellm[proxy] (or add prometheus-client) wherever metrics are enabled
- Add an import smoke test for prometheus_client to your image build
- Keep dependency extras in version control with the litellm pin
When it happens
Trigger: pip install litellm (no extras) then configuring success_callback: ['prometheus'] or any prometheus metrics feature; slim Docker images that pruned 'optional' dependencies; a venv where prometheus-client was uninstalled during a cleanup.
Common situations: CI or production images built from requirements.txt listing only litellm; local venvs reused after dependency pruning; upgrading litellm without reinstalling extras.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- Blocked user check was never set. This call has no effect.
- Configuration validation failed
- {error.message}
- Guardrail implements apply_guardrail, which needs the…
- {label_error.message}
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/db125f9c462cc759.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/integrations/prometheus_services.py:35
FAILED_REQUESTS_LABELS: Final = ["error_class", "function_name"]
class PrometheusServicesLogger:
# Class variables or attributes
litellm_service_latency = None # Class-level attribute to store the Histogram
def __init__(
self,
mock_testing: bool = False,
**kwargs,
):
try:
try:
from prometheus_client import REGISTRY, Counter, Gauge, Histogram
from prometheus_client.gc_collector import Collector
except ImportError:
raise Exception("Missing prometheus_client. Run `pip install prometheus-client`")
_custom_buckets: Final = litellm.prometheus_latency_buckets
self.latency_buckets = tuple(_custom_buckets) if _custom_buckets is not None else LATENCY_BUCKETS
self.Histogram = Histogram
self.Counter = Counter
self.Gauge = Gauge
self.REGISTRY = REGISTRY
verbose_logger.debug("in init prometheus services metrics")
self.payload_to_prometheus_map: dict[str, list[Histogram | Counter | Gauge | Collector]] = {}
for service in ServiceTypes:
service_metrics: list[Histogram | Counter | Gauge | Collector] = []
metrics_to_initialize = self._get_service_metrics_initialize(service)
View on GitHub (pinned to 77b7c6c40c)