{"record":{"id":"b1060246b5cfd241","repo":"BerriAI/litellm","slug":"invalid-duration-format","errorCode":null,"errorMessage":"Invalid duration format","messagePattern":"Invalid duration format","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/duration_parser.py","lineNumber":33,"sourceCode":"from litellm._logging import verbose_logger\n\n_BUDGET_DURATION_WORD_ALIASES: Final[dict[str, str]] = {\n    \"hourly\": \"1h\",\n    \"daily\": \"24h\",\n    \"weekly\": \"7d\",\n    \"monthly\": \"30d\",\n}\n\n\ndef _normalize_duration(duration: str) -> str:\n    return _BUDGET_DURATION_WORD_ALIASES.get(duration.strip().lower(), duration)\n\n\ndef _extract_from_regex(duration: str) -> tuple[int, str]:\n    match: Final = re.match(r\"(\\d+)(mo|[smhdw]?)\", duration)\n\n    if not match:\n        raise ValueError(\"Invalid duration format\")\n\n    value, unit = match.groups()\n    value = int(value)\n\n    return value, unit\n\n\ndef get_last_day_of_month(year, month):\n    # Handle December case\n    if month == 12:\n        return 31\n    # Next month is January, so subtract a day from March 1st\n    next_month: Final = datetime(year=year, month=month + 1, day=1)\n    last_day_of_month: Final = (next_month - timedelta(days=1)).day\n    return last_day_of_month\n\n\ndef duration_in_seconds(duration: str) -> int:","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/duration_parser.py#L15-L51","documentation":"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'.","triggerScenarios":"Thrown at litellm/litellm_core_utils/duration_parser.py:33 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a valid duration format such as '30s', '10m', '2h', '7d', or '1mo'.","Check the duration string for typos or missing units."],"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"}