{"record":{"id":"e56a315277ff1202","repo":"BerriAI/litellm","slug":"invalid-or-missing-x-drain-token","errorCode":null,"errorMessage":"Invalid or missing X-Drain-Token","messagePattern":"Invalid or missing X-Drain-Token","errorType":"http","errorClass":"HTTPException","httpStatus":401,"severity":"error","filePath":"litellm/proxy/health_endpoints/_health_endpoints.py","lineNumber":1598,"sourceCode":"    if env_token:\n        return env_token\n    return None\n\n\ndef _authorize_drain_request(request: Request) -> None:\n    \"\"\"\n    Reject /health/drain calls that don't carry the configured X-Drain-Token.\n\n    When no token is configured the endpoint is treated as already opted-in\n    (the ``enable_drain_endpoint`` flag is the only gate). Comparison uses\n    ``secrets.compare_digest`` to avoid timing leaks.\n    \"\"\"\n    expected: Final = _drain_endpoint_token()\n    if expected is None:\n        return\n    supplied: Final = request.headers.get(\"x-drain-token\") or \"\"\n    if not secrets.compare_digest(supplied, expected):\n        raise HTTPException(\n            status_code=status.HTTP_401_UNAUTHORIZED,\n            detail=\"Invalid or missing X-Drain-Token\",\n        )\n\n\nasync def _resolve_public_readiness_db(response: Response) -> str:\n    \"\"\"\n    Return the db status string for the public probe and flip the response to\n    503 when a configured DB is unreachable. Mirrors the legacy values:\n    \"Not connected\" (no DB configured), \"connected\", \"disconnected\".\n    \"\"\"\n    from litellm.proxy.proxy_server import prisma_client\n\n    if prisma_client is None:\n        return \"Not connected\"\n\n    db_health_status: Final = await _db_health_readiness_check()\n    if db_health_status[\"status\"] != \"connected\":","sourceCodeStart":1580,"sourceCodeEnd":1616,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/health_endpoints/_health_endpoints.py#L1580-L1616","documentation":"Error \"Invalid or missing X-Drain-Token\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/proxy/health_endpoints/_health_endpoints.py:1598 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Send the correct drain token in the X-Drain-Token header.","Verify the drain token configured on the proxy matches the one used by the client."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}