{"record":{"id":"b8ad79bf7cca79df","repo":"BerriAI/litellm","slug":"could-not-parse-timestamp-timestamp-str-e","errorCode":null,"errorMessage":"Could not parse timestamp '{timestamp_str}': {e}","messagePattern":"Could not parse timestamp '(.+?)': (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/integrations/cloudzero/cz_stream_api.py","lineNumber":149,"sourceCode":"                    \"+08:00\",\n                    \"+09:00\",\n                    \"+10:00\",\n                    \"+11:00\",\n                    \"+12:00\",\n                )\n            ):\n                dt = datetime.fromisoformat(timestamp_str)\n            else:\n                # Assume user timezone if no timezone info\n                dt = datetime.fromisoformat(timestamp_str)\n                if dt.tzinfo is None:\n                    dt = dt.replace(tzinfo=self.user_timezone)\n\n            # Convert to UTC\n            return dt.astimezone(timezone.utc)\n\n        except ValueError as e:\n            raise ValueError(f\"Could not parse timestamp '{timestamp_str}': {e}\")\n\n    def _send_daily_batch(self, batch_date: str, batch_data: pl.DataFrame, operation: str) -> None:\n        \"\"\"Send a single daily batch to CloudZero API.\"\"\"\n        if batch_data.is_empty():\n            return\n\n        headers: Final = {\n            \"Authorization\": f\"Bearer {self.api_key}\",\n            \"Content-Type\": \"application/json\",\n        }\n\n        # Use the correct API endpoint format from documentation\n        url: Final = f\"{self.base_url}/v2/connections/billing/anycost/{self.connection_id}/billing_drops\"\n\n        # Prepare the batch payload according to AnyCost API format\n        payload: Final = self._prepare_batch_payload(batch_date, batch_data, operation)\n\n        try:","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/cloudzero/cz_stream_api.py#L131-L167","documentation":"ValueError raised by CloudZeroStreamer._parse_and_convert_timestamp when datetime.fromisoformat rejects the input string after the Z-suffix and explicit-offset handling. The helper only understands ISO 8601; anything else — slash dates, epoch numbers, locale-formatted strings, empty strings, or precision variants your Python version can't parse (pre-3.11 fromisoformat is strict) — raises with the underlying parser message appended.","triggerScenarios":"Feeding the streamer usage rows whose timestamp column is '2024/07/15 00:00:00' (slashes), '1699999999' (epoch as string), '15-07-2024' (day-first), '' (empty), or a nanosecond-precision value on Python < 3.11. Note that naive strings are assumed to be in the configured user_timezone, so missing offsets alone do not raise.","commonSituations":"Usage data extracted from databases with non-ISO timestamp formatting (e.g. Snowflake/BigQuery variants rendered by drivers); spreadsheets/CSVs with locale dates; Python version differences between dev (3.11+) and prod (3.10) containers; columns accidentally containing NULLs coerced to ''.","solutions":["Normalize timestamps to ISO 8601 before export: dt.isoformat() or keep 'YYYY-MM-DDTHH:MM:SS(.ffffff)(Z|±HH:MM)'","If values are epoch seconds/millis, convert first: datetime.fromtimestamp(int(ts), tz=timezone.utc).isoformat()","Coerce empty/NULL to a sensible default (row creation time) instead of passing ''","Pin Python >= 3.11 in the image if inputs carry less-common ISO variants"],"exampleFix":"# before\nstreamer.stream_usage_data(df.with_columns(pl.col(\"startTime\").str.to_str()))  # raw '2024/07/15 00:00:00'\n\n# after\ndf = df.with_columns(\n    pl.col(\"startTime\")\n      .str.strptime(pl.Datetime, \"%Y/%m/%d %H:%M:%S\", strict=True)\n      .dt.replace_time_zone(\"UTC\")\n      .dt.to_string(\"%Y-%m-%dT%H:%M:%S%z\")\n)","handlingStrategy":"validation","validationCode":"from datetime import datetime\n\ndef is_parseable_timestamp(ts: str) -> bool:\n    if not isinstance(ts, str) or not ts.strip():\n        return False\n    try:\n        datetime.fromisoformat(ts.strip().replace(\"Z\", \"+00:00\"))\n        return True\n    except ValueError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    dt_utc = streamer._parse_and_convert_timestamp(ts)\nexcept ValueError as e:\n    # convert non-ISO inputs yourself, e.g. epoch seconds:\n    from datetime import datetime, timezone\n    dt_utc = datetime.fromtimestamp(int(ts), tz=timezone.utc)","preventionTips":["Emit timestamps exclusively as ISO 8601 (dt.isoformat()) from upstream systems","Convert epoch values to aware datetimes before handing rows to the streamer","Reject/replace empty-string timestamps at ingestion time","Run the export on Python >= 3.11 if source strings use less-common ISO variants"],"tags":["cloudzero","timestamp","iso8601","parsing","usage-export"],"backgroundTag":"timestamp-parse-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}