{"record":{"id":"db125f9c462cc759","repo":"BerriAI/litellm","slug":"missing-prometheus-client-run-pip-install-promet","errorCode":null,"errorMessage":"Missing prometheus_client. Run `pip install prometheus-client`","messagePattern":"Missing prometheus_client\\. Run `pip install prometheus-client`","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/integrations/prometheus_services.py","lineNumber":35,"sourceCode":"\nFAILED_REQUESTS_LABELS: Final = [\"error_class\", \"function_name\"]\n\n\nclass PrometheusServicesLogger:\n    # Class variables or attributes\n    litellm_service_latency = None  # Class-level attribute to store the Histogram\n\n    def __init__(\n        self,\n        mock_testing: bool = False,\n        **kwargs,\n    ):\n        try:\n            try:\n                from prometheus_client import REGISTRY, Counter, Gauge, Histogram\n                from prometheus_client.gc_collector import Collector\n            except ImportError:\n                raise Exception(\"Missing prometheus_client. Run `pip install prometheus-client`\")\n\n            _custom_buckets: Final = litellm.prometheus_latency_buckets\n            self.latency_buckets = tuple(_custom_buckets) if _custom_buckets is not None else LATENCY_BUCKETS\n\n            self.Histogram = Histogram\n            self.Counter = Counter\n            self.Gauge = Gauge\n            self.REGISTRY = REGISTRY\n\n            verbose_logger.debug(\"in init prometheus services metrics\")\n\n            self.payload_to_prometheus_map: dict[str, list[Histogram | Counter | Gauge | Collector]] = {}\n\n            for service in ServiceTypes:\n                service_metrics: list[Histogram | Counter | Gauge | Collector] = []\n\n                metrics_to_initialize = self._get_service_metrics_initialize(service)\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/integrations/prometheus_services.py#L17-L53","documentation":"PrometheusServicesLogger.__init__ imports prometheus_client (Counter/Gauge/Histogram, gc_collector) and, on ImportError, raises a generic Exception telling you to install prometheus-client. The logger cannot register any service-level metrics without the package, so construction aborts.","triggerScenarios":"Instantiating PrometheusServicesLogger (or enabling the 'prometheus' callback that does so) in an environment where prometheus_client is not installed — plain 'pip install litellm' does not pull it in; it ships with litellm[extra_proxy].","commonSituations":"Using litellm as a library in a slim venv and then adding prometheus monitoring; CI images that only install the base package; upgrading pip dependencies with a lock file that predates the metrics feature.","solutions":["pip install prometheus-client in the same environment that runs the proxy/callback","Or install the proxy extras bundle: pip install 'litellm[extra_proxy]'","Verify with python -c \"import prometheus_client; print(prometheus_client.__version__)\" before restarting"],"exampleFix":"# before\nlitellm.callbacks = [\"prometheus\"]  # Exception: Missing prometheus_client\n\n# after\n# pip install prometheus-client\nimport prometheus_client  # sanity check\nlitellm.callbacks = [\"prometheus\"]","handlingStrategy":"validation","validationCode":"try:\n    import prometheus_client  # noqa: F401\nexcept ImportError:\n    raise SystemExit(\"prometheus-client is required: pip install prometheus-client\")\n\nlitellm.callbacks = [\"prometheus\"]","typeGuard":null,"tryCatchPattern":"try:\n    from litellm.integrations.prometheus_services import PrometheusServicesLogger\n    logger = PrometheusServicesLogger()\nexcept Exception as e:\n    if \"Missing prometheus_client\" in str(e):\n        logger = None  # degrade without service metrics\n    else:\n        raise","preventionTips":["Add prometheus-client to your deployment requirements file, not just ad-hoc installs","Prefer litellm[extra_proxy] for proxy-style deployments","Fail a startup probe on the import so the missing dep is caught at deploy, not at first request"],"tags":["prometheus","dependency","installation","callbacks"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}