BerriAI/litellm · error · ValueError
duration needs to be one of ["daily", "weekly", "monthly"…
Error message
duration needs to be one of ["daily", "weekly", "monthly", "yearly"]
What it means
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.
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.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/budget_manager.py:92 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/1efd87f4188979a3.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/budget_manager.py:92
total_budget: float,
user: str,
duration: Literal["daily", "weekly", "monthly", "yearly"] | None = None,
created_at: float = time.time(),
):
self.user_dict[user] = {"total_budget": total_budget}
if duration is None:
return self.user_dict[user]
if duration == "daily":
duration_in_days = 1
elif duration == "weekly":
duration_in_days = DAYS_IN_A_WEEK
elif duration == "monthly":
duration_in_days = DAYS_IN_A_MONTH
elif duration == "yearly":
duration_in_days = DAYS_IN_A_YEAR
else:
raise ValueError("""duration needs to be one of ["daily", "weekly", "monthly", "yearly"]""")
self.user_dict[user] = {
"total_budget": total_budget,
"duration": duration_in_days,
"created_at": created_at,
"last_updated_at": created_at,
}
self._save_data_thread() # [Non-Blocking] Update persistent storage without blocking execution
return self.user_dict[user]
def projected_cost(self, model: str, messages: list, user: str):
text: Final = "".join(message["content"] for message in messages)
prompt_tokens: Final = litellm.token_counter(model=model, text=text)
prompt_cost, _ = litellm.cost_per_token(model=model, prompt_tokens=prompt_tokens, completion_tokens=0)
current_cost: Final = self.user_dict[user].get("current_cost", 0)
projected_cost: Final = prompt_cost + current_cost
return projected_cost
def get_total_budget(self, user: str):View on GitHub (pinned to 77b7c6c40c)