{"record":{"id":"23ee56abb30d239d","repo":"BerriAI/litellm","slug":"invalid-date-format-date-str-expected-expect","errorCode":null,"errorMessage":"Invalid date format: {date_str}. Expected: {expected}","messagePattern":"Invalid date format: (.+?)\\. Expected: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"litellm/proxy/spend_tracking/spend_management_endpoints.py","lineNumber":2335,"sourceCode":"        else:\n            if start_date is None or end_date is None:\n                raise ProxyException(\n                    message=\"Start date and end date are required\",\n                    type=\"bad_request\",\n                    param=\"None\",\n                    code=status.HTTP_400_BAD_REQUEST,\n                )\n            formats: Final = [\"%Y-%m-%d %H:%M:%S\", \"%Y-%m-%d\"] if is_v2 else [\"%Y-%m-%d %H:%M:%S\"]\n\n            def parse_date(date_str: str) -> datetime:\n                date_str = date_str.strip()\n                for fmt in formats:\n                    try:\n                        return datetime.strptime(date_str, fmt).replace(tzinfo=timezone.utc)\n                    except ValueError:\n                        continue\n                expected: Final = \"'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'\" if is_v2 else \"'YYYY-MM-DD HH:MM:SS'\"\n                raise HTTPException(\n                    status_code=status.HTTP_400_BAD_REQUEST,\n                    detail=f\"Invalid date format: {date_str}. Expected: {expected}\",\n                )\n\n            start_date_obj = parse_date(start_date)\n            end_date_obj = parse_date(end_date)\n\n        # Build where conditions\n        where_conditions: Final[dict[str, Any]] = {}\n        if start_date_obj is not None and end_date_obj is not None:\n            where_conditions[\"startTime\"] = {\n                \"gte\": start_date_obj.isoformat(),  # Already in UTC, no need to add Z\n                \"lte\": end_date_obj.isoformat(),\n            }\n\n        if team_id is not None:\n            where_conditions[\"team_id\"] = team_id\n","sourceCodeStart":2317,"sourceCodeEnd":2353,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/spend_tracking/spend_management_endpoints.py#L2317-L2353","documentation":"Error \"Invalid date format: {date_str}. Expected: {expected}\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/proxy/spend_tracking/spend_management_endpoints.py:2335 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Format the date according to the expected format shown in the error (e.g. YYYY-MM-DD)."],"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"}