Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(types/utils.py): support openai 'file' message type

Krrish Dholakia8ef9129556ab
diff --git a/litellm/types/llms/openai.py b/litellm/types/llms/openai.py
index df746036da3..4b0be9d5fe6 100644
--- a/litellm/types/llms/openai.py
+++ b/litellm/types/llms/openai.py
@@ -436,12 +436,24 @@ class ChatCompletionDocumentObject(TypedDict):
citations: Optional[CitationsObject]
+class ChatCompletionFileObjectFile(TypedDict):
+ file_data: Optional[str]
+ file_id: Optional[str]
+ filename: Optional[str]
+
+
+class ChatCompletionFileObject(TypedDict):
+ type: Literal["file"]
+ file: ChatCompletionFileObjectFile
+
+
OpenAIMessageContentListBlock = Union[
ChatCompletionTextObject,
ChatCompletionImageObject,
ChatCompletionAudioObject,
ChatCompletionDocumentObject,
ChatCompletionVideoObject,
+ ChatCompletionFileObject,
]
OpenAIMessageContent = Union[
@@ -523,6 +535,7 @@ ValidUserMessageContentTypes = [
"input_audio",
"document",
"video_url",
+ "file",
] # used for validating user messages. Prevent users from accidentally sending anthropic messages.
AllMessageValues = Union[
diff --git a/tests/litellm_utils_tests/test_utils.py b/tests/litellm_utils_tests/test_utils.py
index 2b1e78a681a..42df7c495c2 100644
--- a/tests/litellm_utils_tests/test_utils.py
+++ b/tests/litellm_utils_tests/test_utils.py
@@ -1094,6 +1094,26 @@ def test_is_base64_encoded_2():
[
([{"role": "user", "content": "hi"}], True),
([{"role": "user", "content": [{"type": "text", "text": "hi"}]}], True),
+ (
+ [
+ {
+ "role": "user",
+ "content": [
+ {
+ "type": "file",
+ "file": {
+ "file_id": "123",
+ "file_name": "test.txt",
+ "file_size": 100,
+ "file_type": "text/plain",
+ "file_url": "https://example.com/test.txt",
+ },
+ }
+ ],
+ }
+ ],
+ True,
+ ),
(
[
{