{"record":{"id":"7d014fd507e4c89f","repo":"BerriAI/litellm","slug":"start-time-is-required-got-start-time-of-type","errorCode":null,"errorMessage":"start_time is required, got={start_time} of type {type(start_time)}","messagePattern":"start_time is required, got=(.+?) of type (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/litellm_logging.py","lineNumber":4726,"sourceCode":"    ) -> tuple[float, float, float]:\n        \"\"\"\n        Convert datetime objects to floats\n\n        Args:\n            start_time: Union[dt_object, float]\n            end_time: Union[dt_object, float]\n            completion_start_time: Union[dt_object, float]\n\n        Returns:\n            Tuple[float, float, float]: A tuple containing the start time, end time, and completion start time as floats.\n        \"\"\"\n\n        if isinstance(start_time, datetime.datetime):\n            start_time_float = start_time.timestamp()\n        elif isinstance(start_time, float):\n            start_time_float = start_time\n        else:\n            raise ValueError(f\"start_time is required, got={start_time} of type {type(start_time)}\")\n\n        if isinstance(end_time, datetime.datetime):\n            end_time_float = end_time.timestamp()\n        elif isinstance(end_time, float):\n            end_time_float = end_time\n        else:\n            raise ValueError(f\"end_time is required, got={end_time} of type {type(end_time)}\")\n\n        if isinstance(completion_start_time, datetime.datetime):\n            completion_start_time_float = completion_start_time.timestamp()\n        elif isinstance(completion_start_time, float):\n            completion_start_time_float = completion_start_time\n        else:\n            completion_start_time_float = end_time_float\n\n        return start_time_float, end_time_float, completion_start_time_float\n\n    @staticmethod","sourceCodeStart":4708,"sourceCodeEnd":4744,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/litellm_logging.py#L4708-L4744","documentation":"StandardLoggingPayloadSetup.cleanup_timestamps() normalizes a request's start/end/completion timestamps into epoch-second floats for the standard logging payload. It accepts only datetime.datetime instances or Python floats; every other type - None, str, int (time.time_ns(), int(time.time())), pandas.Timestamp, Decimal - raises this ValueError echoing the offending value and type. Note that Python ints fail even though they look numeric.","triggerScenarios":"Passing start_time=time.time_ns() or int(time.time()) to litellm.completion/embedding, or a custom logger invoking StandardLoggingPayloadSetup.cleanup_timestamps with an ISO string, None, or other non-datetime/non-float value.","commonSituations":"Latency-test harnesses seeding nanosecond ints; timestamps loaded from JSON/DB as ISO-8601 strings and passed through; None leaking from conditionally computed timer values; pandas Timestamps from dataframe pipelines.","solutions":["Pass epoch seconds as float: float(time.time()) instead of int or time.time_ns()","Or pass datetime.datetime objects and let litellm call .timestamp() itself","Or omit start_time entirely - litellm stamps it internally per request","Coerce at the boundary: start_time = start_time.timestamp() if isinstance(start_time, datetime.datetime) else float(start_time)"],"exampleFix":"# before\nimport time\nlitellm.completion(model=\"gpt-4o\", messages=m, start_time=time.time_ns())  # int -> ValueError\n\n# after\nimport time\nlitellm.completion(model=\"gpt-4o\", messages=m, start_time=float(time.time()))\n# or: from datetime import datetime, timezone; start_time=datetime.now(timezone.utc)","handlingStrategy":"type-guard","validationCode":"from datetime import datetime\n\ndef to_epoch_seconds(v):\n    if isinstance(v, datetime):\n        return v.timestamp()\n    if isinstance(v, float):\n        return v\n    if isinstance(v, int) and not isinstance(v, bool):\n        return float(v)\n    raise TypeError(f\"unsupported timestamp: {v!r}\")\n\nlitellm.completion(model=\"gpt-4o\", messages=m, start_time=to_epoch_seconds(start))","typeGuard":"from datetime import datetime\n\ndef is_valid_timestamp(v: object) -> bool:\n    return (isinstance(v, datetime) or isinstance(v, float)) and not isinstance(v, bool)","tryCatchPattern":"try:\n    litellm.completion(..., start_time=start)\nexcept ValueError as e:\n    if \"start_time is required\" in str(e):\n        start = float(start)  # or datetime.now(timezone.utc)\n        litellm.completion(..., start_time=start)","preventionTips":["Always pass datetime objects or float(time.time()); never ints or time.time_ns()","Centralize timestamp creation in one helper so all call sites share the coercion","Omit start_time when you have no explicit timing need - litellm stamps it itself"],"tags":["litellm","logging","type-validation","timestamps"],"backgroundTag":"invalid-argument-value","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}