BerriAI/litellm · error · ValueError
start_time_utc and end_time_utc must be provided together
Error message
start_time_utc and end_time_utc must be provided together
What it means
FocusLogger.export_usage_data raises this ValueError when exactly one of start_time_utc / end_time_utc is provided (checked with a boolean XOR). This method is the manual export hook (e.g. the /vantage/export endpoint); time bounds must be a complete pair or entirely absent. When both are absent the hook exports all available data instead of a scheduled window.
Solutions
- Pass both bounds together: export_usage_data(start_time_utc=start, end_time_utc=end).
- Or pass neither to export all available data: export_usage_data(limit=1000).
- In HTTP handlers, require start and end as a pair (422 on partial input) instead of forwarding them blindly.
- If only a start is known, compute end = start + timedelta(hours=1) (or another window) before calling.
Example fix
# before await logger.export_usage_data(start_time_utc=start_dt) # XOR -> ValueError # after await logger.export_usage_data(start_time_utc=start_dt, end_time_utc=start_dt + timedelta(hours=1))
Defensive patterns
Strategy: validation
Validate before calling
if bool(start_time_utc) ^ bool(end_time_utc):
raise HTTPException(422, 'start_time_utc and end_time_utc must be provided together')
await logger.export_usage_data(limit=limit, start_time_utc=start_time_utc, end_time_utc=end_time_utc) Type guard
def is_complete_time_range(start: datetime | None, end: datetime | None) -> bool:
return (start is None) == (end is None) Try / catch
try:
await logger.export_usage_data(start_time_utc=s, end_time_utc=e)
except ValueError as e:
if 'together' in str(e):
return JSONResponse({'error': 'Provide both start and end, or neither'}, 422)
raise Prevention
- Enforce start/end as a pair at the API boundary (both required or both forbidden).
- Derive one bound from the other when only a window start is known.
- Remember omitting both exports ALL data — bound the call explicitly when you only want a window.
When it happens
Trigger: Calling export_usage_data(start_time_utc=ts) without end_time_utc, or vice versa; an HTTP handler that only forwards the 'start' query parameter; passing datetime(0)-like falsy values — note bool(datetime) is True for any real datetime, so this is purely the one-sided case.
Common situations: Building a custom export endpoint where only the start timestamp is wired up; clients sending ?start=... without ?end=...; UI date-range pickers where the user clears one of the two fields.
Related errors
- api_key must be provided for Vantage destination (set…
- bucket_name must be provided for GCS destination
- bucket_name must be provided for S3 destination
- Export format ' ' not supported. Use 'parquet' or 'csv'.
- GCS upload failed: status=
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/0475238207ccb2c5.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/integrations/focus/focus_logger.py:92
)
return self._engine
async def export_usage_data(
self,
*,
limit: int | None = None,
start_time_utc: datetime | None = None,
end_time_utc: datetime | None = None,
) -> None:
"""Public hook to trigger export immediately.
When called without time bounds (manual /vantage/export with no
start/end), exports **all** available data instead of the last
scheduled window. The hourly/daily window only applies to
automatic scheduler runs.
"""
if bool(start_time_utc) ^ bool(end_time_utc):
raise ValueError("start_time_utc and end_time_utc must be provided together")
if start_time_utc and end_time_utc:
window: Final = FocusTimeWindow(
start_time=start_time_utc,
end_time=end_time_utc,
frequency=self.frequency,
)
await self._export_window(window=window, limit=limit)
else:
# No time bounds → export all available data
await self._export_all(limit=limit)
async def dry_run_export_usage_data(self, limit: int | None = DEFAULT_DRY_RUN_LIMIT) -> dict[str, Any]:
"""Return transformed data without uploading."""
engine: Final = self._ensure_engine()
return await engine.dry_run_export_usage_data(limit=limit)
async def initialize_focus_export_job(self) -> None:View on GitHub (pinned to 77b7c6c40c)