BerriAI/litellm · error · ValueError
Invalid duration format
Error message
Invalid duration format
What it means
Raised by _extract_from_regex when the duration string does not match the pattern (\d+)(mo|[smhdw]?) — i.e. it lacks a leading integer count or carries an unrecognized unit. Fires on malformed duration inputs like 'abc', '1x', or 'hour'.
Solutions
- Use a valid duration format such as '30s', '10m', '2h', '7d', or '1mo'.
- Check the duration string for typos or missing units.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/litellm_core_utils/duration_parser.py:33 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/b1060246b5cfd241.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/litellm_core_utils/duration_parser.py:33
from litellm._logging import verbose_logger
_BUDGET_DURATION_WORD_ALIASES: Final[dict[str, str]] = {
"hourly": "1h",
"daily": "24h",
"weekly": "7d",
"monthly": "30d",
}
def _normalize_duration(duration: str) -> str:
return _BUDGET_DURATION_WORD_ALIASES.get(duration.strip().lower(), duration)
def _extract_from_regex(duration: str) -> tuple[int, str]:
match: Final = re.match(r"(\d+)(mo|[smhdw]?)", duration)
if not match:
raise ValueError("Invalid duration format")
value, unit = match.groups()
value = int(value)
return value, unit
def get_last_day_of_month(year, month):
# Handle December case
if month == 12:
return 31
# Next month is January, so subtract a day from March 1st
next_month: Final = datetime(year=year, month=month + 1, day=1)
last_day_of_month: Final = (next_month - timedelta(days=1)).day
return last_day_of_month
def duration_in_seconds(duration: str) -> int:View on GitHub (pinned to 77b7c6c40c)