BerriAI/litellm · error · Exception

Missing prometheus_client. Run `pip install prometheus-clien

Error message

Missing prometheus_client. Run `pip install prometheus-client`

What it means

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.

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 6c2dcb801b)

Solutions

  1. pip install prometheus-client in the same environment that runs the proxy/callback
  2. Or install the proxy extras bundle: pip install 'litellm[extra_proxy]'
  3. Verify with python -c "import prometheus_client; print(prometheus_client.__version__)" before restarting

Example fix

# before
litellm.callbacks = ["prometheus"]  # Exception: Missing prometheus_client

# after
# pip install prometheus-client
import prometheus_client  # sanity check
litellm.callbacks = ["prometheus"]
Defensive patterns

Strategy: validation

Validate before calling

try:
    import prometheus_client  # noqa: F401
except ImportError:
    raise SystemExit("prometheus-client is required: pip install prometheus-client")

litellm.callbacks = ["prometheus"]

Try / catch

try:
    from litellm.integrations.prometheus_services import PrometheusServicesLogger
    logger = PrometheusServicesLogger()
except Exception as e:
    if "Missing prometheus_client" in str(e):
        logger = None  # degrade without service metrics
    else:
        raise

Prevention

When it happens

Trigger: 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].

Common situations: 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.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/db125f9c462cc759. Report an issue: GitHub.