{"record":{"id":"b1044d5ab916a5c9","repo":"BerriAI/litellm","slug":"start-time-utc-is-required-for-getting-a-payload-f","errorCode":null,"errorMessage":"start_time_utc is required for getting a payload from GCS Bucket","messagePattern":"start_time_utc is required for getting a payload from GCS Bucket","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/integrations/gcs_bucket/gcs_bucket.py","lineNumber":316,"sourceCode":"        if \"gcs_log_id\" in _metadata:\n            safe_log_id: Final = sanitize_cloud_object_component(_metadata.get(\"gcs_log_id\"), fallback=\"\")\n            if safe_log_id:\n                object_name = f\"{current_date}/custom-{uuid.uuid4().hex}-{safe_log_id}\"\n\n        return object_name\n\n    async def get_request_response_payload(\n        self,\n        request_id: str,\n        start_time_utc: datetime | None,\n        end_time_utc: datetime | None,\n    ) -> dict | None:\n        \"\"\"\n        Get the request and response payload for a given `request_id`\n        Tries current day, next day, and previous day until it finds the payload\n        \"\"\"\n        if start_time_utc is None:\n            raise ValueError(\"start_time_utc is required for getting a payload from GCS Bucket\")\n\n        dates_to_try: Final = [\n            start_time_utc,\n            start_time_utc + timedelta(days=1),\n            start_time_utc - timedelta(days=1),\n        ]\n        date_str = None\n        for date in dates_to_try:\n            try:\n                date_str = self._get_object_date_from_datetime(datetime_obj=date)\n                object_name = self._generate_success_object_name(\n                    request_date_str=date_str,\n                    response_id=request_id,\n                )\n                response = await self.download_gcs_object(object_name)\n\n                if response is not None:\n                    loaded_response = json.loads(response)","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/gcs_bucket/gcs_bucket.py#L298-L334","documentation":"GCSBucketLogger.get_request_response_payload raises ValueError when start_time_utc is None. The method searches GCS objects for the request's payload by deriving object names from dates (start day, +1 day, -1 day), so it cannot compute any candidate object keys without at least the request's start time. end_time_utc is accepted as None, but start_time_utc is mandatory.","triggerScenarios":"Calling get_request_response_payload(request_id, None, None); an API handler that looks up a request by ID only and forwards a null start_time_utc; DB rows where the start_time column is missing so callers pass None.","commonSituations":"Building admin/debug endpoints that fetch the raw payload for a logged request; integrations that join against a spend-logs table where start_time can be NULL; forgetting that the GCS layout is date-partitioned.","solutions":["Always pass the request's start_time_utc — fetch it from your spend/logs DB row for that request_id first.","If the start time is unknown, query your logging DB (e.g. LiteLLMSpendLogs) for start_time by request_id before calling.","Return a 4xx from your handler when start_time is unavailable rather than calling with None.","Remember the method tolerates end_time_utc=None; only start is required."],"exampleFix":"# before\npayload = await logger.get_request_response_payload(req_id, None, None)\n\n# after\nrow = await get_spend_log(request_id=req_id)  # has start_time\npayload = await logger.get_request_response_payload(req_id, row.start_time, row.end_time)","handlingStrategy":"validation","validationCode":"if start_time_utc is None:\n    row = await fetch_spend_log(request_id=request_id)\n    if row is None or row.start_time is None:\n        return JSONResponse({'error': 'start_time required to fetch GCS payload'}, 400)\n    start_time_utc = row.start_time","typeGuard":"def has_start_time(start: datetime | None) -> bool:\n    return start is not None","tryCatchPattern":"try:\n    payload = await logger.get_request_response_payload(request_id, start_time_utc, end_time_utc)\nexcept ValueError as e:\n    if 'start_time_utc is required' in str(e):\n        return JSONResponse({'error': 'start_time_utc missing for request'}, 400)\n    raise","preventionTips":["Always join the request's start_time from your spend-logs DB before calling.","Treat a NULL start_time in the DB as 'payload not retrievable', not as None to pass through."],"tags":["gcs","payload-retrieval","parameter-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}