{"record":{"id":"1efd87f4188979a3","repo":"BerriAI/litellm","slug":"duration-needs-to-be-one-of-daily-weekly-m","errorCode":null,"errorMessage":"duration needs to be one of [\"daily\", \"weekly\", \"monthly\", \"yearly\"]","messagePattern":"duration needs to be one of \\[\"daily\", \"weekly\", \"monthly\", \"yearly\"\\]","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/budget_manager.py","lineNumber":92,"sourceCode":"        total_budget: float,\n        user: str,\n        duration: Literal[\"daily\", \"weekly\", \"monthly\", \"yearly\"] | None = None,\n        created_at: float = time.time(),\n    ):\n        self.user_dict[user] = {\"total_budget\": total_budget}\n        if duration is None:\n            return self.user_dict[user]\n\n        if duration == \"daily\":\n            duration_in_days = 1\n        elif duration == \"weekly\":\n            duration_in_days = DAYS_IN_A_WEEK\n        elif duration == \"monthly\":\n            duration_in_days = DAYS_IN_A_MONTH\n        elif duration == \"yearly\":\n            duration_in_days = DAYS_IN_A_YEAR\n        else:\n            raise ValueError(\"\"\"duration needs to be one of [\"daily\", \"weekly\", \"monthly\", \"yearly\"]\"\"\")\n        self.user_dict[user] = {\n            \"total_budget\": total_budget,\n            \"duration\": duration_in_days,\n            \"created_at\": created_at,\n            \"last_updated_at\": created_at,\n        }\n        self._save_data_thread()  # [Non-Blocking] Update persistent storage without blocking execution\n        return self.user_dict[user]\n\n    def projected_cost(self, model: str, messages: list, user: str):\n        text: Final = \"\".join(message[\"content\"] for message in messages)\n        prompt_tokens: Final = litellm.token_counter(model=model, text=text)\n        prompt_cost, _ = litellm.cost_per_token(model=model, prompt_tokens=prompt_tokens, completion_tokens=0)\n        current_cost: Final = self.user_dict[user].get(\"current_cost\", 0)\n        projected_cost: Final = prompt_cost + current_cost\n        return projected_cost\n\n    def get_total_budget(self, user: str):","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/budget_manager.py#L74-L110","documentation":"Raised by BudgetManager.create_budget when the duration argument is not one of the four supported budget-reset windows; the code maps each literal to a day count (1, 7, ~30, ~365) and hits this guard when no branch matches, e.g. a typo or an untyped caller passing an arbitrary string past the Literal annotation.","triggerScenarios":"Thrown at litellm/budget_manager.py:92 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass duration as one of the allowed values: \"daily\", \"weekly\", \"monthly\", or \"yearly\".","Check the value you pass to the BudgetManager duration parameter and map any custom interval names to the supported set."],"exampleFix":null,"handlingStrategy":"validation","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-23T08:17:48.524Z"}