{"record":{"id":"273b45481d0eb213","repo":"BerriAI/litellm","slug":"prometheus-url-not-set-please-set-prometheus-url","errorCode":null,"errorMessage":"PROMETHEUS_URL not set please set 'PROMETHEUS_URL=<>' in .env","messagePattern":"PROMETHEUS_URL not set please set 'PROMETHEUS_URL=<>' in \\.env","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/integrations/prometheus_helpers/prometheus_api.py","lineNumber":27,"sourceCode":"\nfrom litellm import get_secret\nfrom litellm._logging import verbose_logger\nfrom litellm.llms.custom_httpx.http_handler import (\n    get_async_httpx_client,\n    httpxSpecialProvider,\n)\n\nPROMETHEUS_URL: Final[str | None] = get_secret(\"PROMETHEUS_URL\")\nPROMETHEUS_SELECTED_INSTANCE: Final[str | None] = get_secret(\"PROMETHEUS_SELECTED_INSTANCE\")\nasync_http_handler: Final = get_async_httpx_client(llm_provider=httpxSpecialProvider.LoggingCallback)\n\n\nasync def get_metric_from_prometheus(\n    metric_name: str,\n):\n    # Get the start of the current day in Unix timestamp\n    if PROMETHEUS_URL is None:\n        raise ValueError(\"PROMETHEUS_URL not set please set 'PROMETHEUS_URL=<>' in .env\")\n\n    query: Final = f\"{metric_name}[24h]\"\n    now: Final = int(time.time())\n    response: Final = await async_http_handler.get(\n        f\"{PROMETHEUS_URL}/api/v1/query\", params={\"query\": query, \"time\": now}\n    )  # End of the day\n    _json_response: Final = response.json()\n    verbose_logger.debug(\"json response from prometheus /query api %s\", _json_response)\n    results: Final = response.json()[\"data\"][\"result\"]\n    return results\n\n\nasync def get_fallback_metric_from_prometheus():\n    \"\"\"\n    Gets fallback metrics from prometheus for the last 24 hours\n    \"\"\"\n    response_message = \"\"\n    relevant_metrics: Final = [","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/integrations/prometheus_helpers/prometheus_api.py#L9-L45","documentation":"get_metric_from_prometheus queries the Prometheus HTTP API for the last 24h of a metric, but refuses to run unless the PROMETHEUS_URL secret/env var is set at import time (litellm.integrations.prometheus_helpers.prometheus_api reads it via get_secret at module load). The ValueError is raised at call time when that module-level value is None.","triggerScenarios":"Calling proxy admin endpoints that surface prometheus metrics (e.g. /global/spend/report or model-metric dashboards) without PROMETHEUS_URL defined; running the proxy with prometheus callback enabled but the URL configured only in a different environment (.env not loaded, wrong container).","commonSituations":"Deploying the proxy with metrics scraping but forgetting the URL env var; .env present locally but not copied into Docker image; setting PROMETHEUS_URL after process start (it is read once at import, so a hot set of os.environ will not help).","solutions":["Set PROMETHEUS_URL (e.g. http://prometheus:9090) in the proxy's environment/.env and restart the process","If running in Docker, verify the variable is passed (docker run -e PROMETHEUS_URL=... or listed in env_file)","If self-hosting Prometheus, point it at the scrape target exposed by the prometheus callback port first, then set the URL"],"exampleFix":"# .env\nPROMETHEUS_URL=http://prometheus:9090\n\n# docker-compose.yaml\nservices:\n  litellm:\n    environment:\n      - PROMETHEUS_URL=http://prometheus:9090","handlingStrategy":"validation","validationCode":"import os\n\nPROM_URL = os.getenv(\"PROMETHEUS_URL\")\nif not PROM_URL:\n    raise RuntimeError(\"Set PROMETHEUS_URL (e.g. http://prometheus:9090) before using prometheus queries\")\n\nresults = await get_metric_from_prometheus(\"litellm_request_total_latency_bucket\")","typeGuard":null,"tryCatchPattern":"try:\n    results = await get_metric_from_prometheus(metric)\nexcept ValueError as e:\n    if \"PROMETHEUS_URL not set\" in str(e):\n        results = []  # metrics feature disabled\n    else:\n        raise","preventionTips":["Declare PROMETHEUS_URL in the same env file as the other proxy settings and fail startup fast on missing config","Remember the value is read once at import — restart the process after changing it","Add a container healthcheck that curls $PROMETHEUS_URL/api/v1/query?query=up"],"tags":["prometheus","configuration","environment","metrics"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}