{"record":{"id":"d69b1171b71ecdac","repo":"BerriAI/litellm","slug":"budget-enforcement-unavailable-the-budget-reserva","errorCode":null,"errorMessage":"Budget enforcement unavailable: the budget reservation could not be written to the spend counter backend, and fail_closed_budget_enforcement is enabled, so the request was rejected to avoid exceeding the configured budget. Retry shortly.","messagePattern":"Budget enforcement unavailable: the budget reservation could not be written to the spend counter backend, and fail_closed_budget_enforcement is enabled, so the request was rejected to avoid exceeding the configured budget\\. Retry shortly\\.","errorType":"http","errorClass":"HTTPException","httpStatus":503,"severity":"error","filePath":"litellm/proxy/spend_tracking/budget_reservation.py","lineNumber":71,"sourceCode":"\n\nclass _CounterReservationUnavailable(Exception):\n    def __init__(\n        self,\n        touched_counter: bool = False,\n        counter_invalidated: bool = False,\n    ) -> None:\n        self.touched_counter = touched_counter\n        self.counter_invalidated = counter_invalidated\n        super().__init__(\"Counter reservation unavailable\")\n\n\ndef _raise_reservation_unavailable(counter_key: str) -> NoReturn:\n    verbose_proxy_logger.warning(\n        \"fail_closed_budget_enforcement: rejecting request — budget reservation for %s could not be written\",\n        counter_key,\n    )\n    raise HTTPException(\n        status_code=status.HTTP_503_SERVICE_UNAVAILABLE,\n        detail=(\n            \"Budget enforcement unavailable: the budget reservation could not \"\n            \"be written to the spend counter backend, and \"\n            \"fail_closed_budget_enforcement is enabled, so the request was \"\n            \"rejected to avoid exceeding the configured budget. Retry shortly.\"\n        ),\n    )\n\n\ndef get_reserved_counter_keys(budget_reservation: dict | None) -> set:\n    if not budget_reservation:\n        return set()\n    entries: Final = budget_reservation.get(\"entries\") or []\n    return {\n        entry[\"counter_key\"] for entry in entries if isinstance(entry, dict) and entry.get(\"counter_key\") is not None\n    }\n","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/spend_tracking/budget_reservation.py#L53-L89","documentation":"Error \"Budget enforcement unavailable: the budget reservation could not be written to the spend counter backend, and fail_closed_budget_enforcement is enabled, so the request was rejected to avoid exceeding the configured budget. Retry shortly.\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/proxy/spend_tracking/budget_reservation.py:71 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the spend counter backend (Redis/DB) connectivity; retry shortly once reservations can be written.","If fail-closed behavior is not desired, disable fail_closed_budget_enforcement in config."],"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"}