BerriAI/litellm · error · ValueError
Could not parse timestamp '{timestamp_str}': {e}
Error message
Could not parse timestamp '{timestamp_str}': {e} What it means
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.
Source
Thrown at litellm/integrations/cloudzero/cz_stream_api.py:149
"+08:00",
"+09:00",
"+10:00",
"+11:00",
"+12:00",
)
):
dt = datetime.fromisoformat(timestamp_str)
else:
# Assume user timezone if no timezone info
dt = datetime.fromisoformat(timestamp_str)
if dt.tzinfo is None:
dt = dt.replace(tzinfo=self.user_timezone)
# Convert to UTC
return dt.astimezone(timezone.utc)
except ValueError as e:
raise ValueError(f"Could not parse timestamp '{timestamp_str}': {e}")
def _send_daily_batch(self, batch_date: str, batch_data: pl.DataFrame, operation: str) -> None:
"""Send a single daily batch to CloudZero API."""
if batch_data.is_empty():
return
headers: Final = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json",
}
# Use the correct API endpoint format from documentation
url: Final = f"{self.base_url}/v2/connections/billing/anycost/{self.connection_id}/billing_drops"
# Prepare the batch payload according to AnyCost API format
payload: Final = self._prepare_batch_payload(batch_date, batch_data, operation)
try:View on GitHub (pinned to 77b7c6c40c)
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
Example fix
# before
streamer.stream_usage_data(df.with_columns(pl.col("startTime").str.to_str())) # raw '2024/07/15 00:00:00'
# after
df = df.with_columns(
pl.col("startTime")
.str.strptime(pl.Datetime, "%Y/%m/%d %H:%M:%S", strict=True)
.dt.replace_time_zone("UTC")
.dt.to_string("%Y-%m-%dT%H:%M:%S%z")
) Defensive patterns
Strategy: validation
Validate before calling
from datetime import datetime
def is_parseable_timestamp(ts: str) -> bool:
if not isinstance(ts, str) or not ts.strip():
return False
try:
datetime.fromisoformat(ts.strip().replace("Z", "+00:00"))
return True
except ValueError:
return False Try / catch
try:
dt_utc = streamer._parse_and_convert_timestamp(ts)
except ValueError as e:
# convert non-ISO inputs yourself, e.g. epoch seconds:
from datetime import datetime, timezone
dt_utc = datetime.fromtimestamp(int(ts), tz=timezone.utc) Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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 ''.
Related errors
- CloudZero configuration missing. Please set CLOUDZERO_API_KE
- Generated CZRN is invalid: {czrn}
- Invalid CZRN format: {czrn}
- Database not connected. Connect a database to your proxy - h
- limit must be an integer
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/b8ad79bf7cca79df.
Report an issue: GitHub.