fix: use calendar.timegm for UTC timestamps and reuse AnthropicError

Address Greptile review feedback:
- Use calendar.timegm() instead of time.mktime() for correct UTC parsing
- Import AnthropicError from common_utils instead of redefining it
This commit is contained in:
Chesars
2026-03-11 13:03:49 -03:00
parent 9eff611b1a
commit b601b531e7
+3 -15
View File
@@ -12,6 +12,7 @@ Anthropic Files API endpoints:
- GET /v1/files/{file_id}/content - Download file content
"""
import calendar
import time
from typing import Any, Dict, List, Optional, Union
@@ -33,25 +34,12 @@ from litellm.types.llms.openai import (
)
from litellm.types.utils import LlmProviders
from ..common_utils import AnthropicModelInfo
from ..common_utils import AnthropicError, AnthropicModelInfo
ANTHROPIC_FILES_API_BASE = "https://api.anthropic.com"
ANTHROPIC_FILES_BETA_HEADER = "files-api-2025-04-14"
class AnthropicError(BaseLLMException):
def __init__(
self,
status_code: int,
message: str,
headers: Union[dict, httpx.Headers] = {},
):
self.status_code = status_code
self.message = message
self.headers = headers
super().__init__(status_code=status_code, message=message, headers=headers)
class AnthropicFilesConfig(BaseFilesConfig):
"""
Transformation config for Anthropic Files API.
@@ -291,7 +279,7 @@ class AnthropicFilesConfig(BaseFilesConfig):
if created_at_str:
try:
created_at = int(
time.mktime(
calendar.timegm(
time.strptime(
created_at_str.replace("Z", "+00:00")[:19],
"%Y-%m-%dT%H:%M:%S",