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]

Handle openai gpt file data + add openai 'supports_pdf_input' to all vision models + Support bedrock tool cache pointing (#10897)

Krish Dholakiacc626ad3ec5c
diff --git a/litellm/litellm_core_utils/prompt_templates/factory.py b/litellm/litellm_core_utils/prompt_templates/factory.py
index 4e699be3d71..2386e82d4a5 100644
--- a/litellm/litellm_core_utils/prompt_templates/factory.py
+++ b/litellm/litellm_core_utils/prompt_templates/factory.py
@@ -1046,10 +1046,10 @@ def convert_to_gemini_tool_call_invoke(
if tool_calls is not None:
for tool in tool_calls:
if "function" in tool:
- gemini_function_call: Optional[VertexFunctionCall] = (
- _gemini_tool_call_invoke_helper(
- function_call_params=tool["function"]
- )
+ gemini_function_call: Optional[
+ VertexFunctionCall
+ ] = _gemini_tool_call_invoke_helper(
+ function_call_params=tool["function"]
)
if gemini_function_call is not None:
_parts_list.append(
@@ -1465,9 +1465,9 @@ def anthropic_messages_pt( # noqa: PLR0915
)
if "cache_control" in _content_element:
- _anthropic_content_element["cache_control"] = (
- _content_element["cache_control"]
- )
+ _anthropic_content_element[
+ "cache_control"
+ ] = _content_element["cache_control"]
user_content.append(_anthropic_content_element)
elif m.get("type", "") == "text":
m = cast(ChatCompletionTextObject, m)
@@ -1518,9 +1518,9 @@ def anthropic_messages_pt( # noqa: PLR0915
)
if "cache_control" in _content_element:
- _anthropic_content_text_element["cache_control"] = (
- _content_element["cache_control"]
- )
+ _anthropic_content_text_element[
+ "cache_control"
+ ] = _content_element["cache_control"]
user_content.append(_anthropic_content_text_element)
@@ -3468,6 +3468,15 @@ def make_valid_bedrock_tool_name(input_tool_name: str) -> str:
return valid_string
+def add_cache_point_tool_block(tool: dict) -> Optional[BedrockToolBlock]:
+ cache_control = tool.get("cache_control", None)
+ if cache_control is not None:
+ cache_point = cache_control.get("type", "ephemeral")
+ if cache_point == "ephemeral":
+ return {"cachePoint": {"type": "default"}}
+ return None
+
+
def _bedrock_tools_pt(tools: List) -> List[BedrockToolBlock]:
"""
OpenAI tools looks like:
@@ -3552,6 +3561,11 @@ def _bedrock_tools_pt(tools: List) -> List[BedrockToolBlock]:
tool_block = BedrockToolBlock(toolSpec=tool_spec)
tool_block_list.append(tool_block)
+ ## ADD CACHE POINT TOOL BLOCK ##
+ cache_point_tool_block = add_cache_point_tool_block(tool)
+ if cache_point_tool_block is not None:
+ tool_block_list.append(cache_point_tool_block)
+
return tool_block_list
diff --git a/litellm/llms/openai/chat/gpt_transformation.py b/litellm/llms/openai/chat/gpt_transformation.py
index bda7689a4c3..907da5002f0 100644
--- a/litellm/llms/openai/chat/gpt_transformation.py
+++ b/litellm/llms/openai/chat/gpt_transformation.py
@@ -205,41 +205,28 @@ class OpenAIGPTConfig(BaseLLMModelInfo, BaseConfig):
drop_params=drop_params,
)
- @overload
- def _handle_pdf_url(
- self, content_item: ChatCompletionFileObjectFile, is_async: Literal[True]
- ) -> Coroutine[Any, Any, ChatCompletionFileObjectFile]:
- ...
+ def contains_pdf_url(self, content_item: ChatCompletionFileObjectFile) -> bool:
+ potential_pdf_url_starts = ["https://", "http://", "www."]
+ file_id = content_item.get("file_id")
+ if file_id and any(
+ file_id.startswith(start) for start in potential_pdf_url_starts
+ ):
+ return True
+ return False
- @overload
def _handle_pdf_url(
- self,
- content_item: ChatCompletionFileObjectFile,
- is_async: Literal[False] = False,
+ self, content_item: ChatCompletionFileObjectFile
) -> ChatCompletionFileObjectFile:
- ...
-
- def _handle_pdf_url(
- self, content_item: ChatCompletionFileObjectFile, is_async: bool = False
- ) -> Union[
- ChatCompletionFileObjectFile, Coroutine[Any, Any, ChatCompletionFileObjectFile]
- ]:
- potential_pdf_url_starts = ["https://", "http://", "www."]
content_copy = content_item.copy()
file_id = content_copy.get("file_id")
- if file_id and any(
- file_id.startswith(start) for start in potential_pdf_url_starts
- ):
- if is_async:
- return self._async_handle_pdf_url_helper(content_item)
- else:
- base64_data = convert_url_to_base64(file_id)
- content_copy["file_data"] = base64_data
- content_copy["filename"] = "my_file.pdf"
- content_copy.pop("file_id")
+ if file_id is not None:
+ base64_data = convert_url_to_base64(file_id)
+ content_copy["file_data"] = base64_data
+ content_copy["filename"] = "my_file.pdf"
+ content_copy.pop("file_id")
return content_copy
- async def _async_handle_pdf_url_helper(
+ async def _async_handle_pdf_url(
self, content_item: ChatCompletionFileObjectFile
) -> ChatCompletionFileObjectFile:
file_id = content_item.get("file_id")
@@ -250,6 +237,82 @@ class OpenAIGPTConfig(BaseLLMModelInfo, BaseConfig):
content_item.pop("file_id")
return content_item
+ def _common_file_data_check(
+ self, content_item: ChatCompletionFileObjectFile
+ ) -> ChatCompletionFileObjectFile:
+ file_data = content_item.get("file_data")
+ filename = content_item.get("filename")
+ if file_data is not None and filename is None:
+ content_item["filename"] = "my_file.pdf"
+ return content_item
+
+ def _apply_common_transform_content_item(
+ self,
+ content_item: OpenAIMessageContentListBlock,
+ ) -> OpenAIMessageContentListBlock:
+ litellm_specific_params = {"format"}
+ if content_item.get("type") == "image_url":
+ content_item = cast(ChatCompletionImageObject, content_item)
+ if isinstance(content_item["image_url"], str):
+ content_item["image_url"] = {
+ "url": content_item["image_url"],
+ }
+ elif isinstance(content_item["image_url"], dict):
+ new_image_url_obj = ChatCompletionImageUrlObject(
+ **{ # type: ignore
+ k: v
+ for k, v in content_item["image_url"].items()
+ if k not in litellm_specific_params
+ }
+ )
+ content_item["image_url"] = new_image_url_obj
+ elif content_item.get("type") == "file":
+ content_item = cast(ChatCompletionFileObject, content_item)
+ file_obj = content_item["file"]
+ new_file_obj = ChatCompletionFileObjectFile(
+ **{ # type: ignore
+ k: v
+ for k, v in file_obj.items()
+ if k not in litellm_specific_params
+ }
+ )
+ content_item["file"] = new_file_obj
+
+ return content_item
+
+ def _transform_content_item(
+ self,
+ content_item: OpenAIMessageContentListBlock,
+ ) -> OpenAIMessageContentListBlock:
+ content_item = self._apply_common_transform_content_item(content_item)
+ content_item_type = content_item.get("type")
+ potential_file_obj = content_item.get("file")
+ if content_item_type == "file" and potential_file_obj:
+ file_obj = cast(ChatCompletionFileObjectFile, potential_file_obj)
+ content_item_typed = cast(ChatCompletionFileObject, content_item)
+ if self.contains_pdf_url(file_obj):
+ file_obj = self._handle_pdf_url(file_obj)
+ file_obj = self._common_file_data_check(file_obj)
+ content_item_typed["file"] = file_obj
+ content_item = content_item_typed
+ return content_item
+
+ async def _async_transform_content_item(
+ self, content_item: OpenAIMessageContentListBlock, is_async: bool = False
+ ) -> OpenAIMessageContentListBlock:
+ content_item = self._apply_common_transform_content_item(content_item)
+ content_item_type = content_item.get("type")
+ potential_file_obj = content_item.get("file")
+ if content_item_type == "file" and potential_file_obj:
+ file_obj = cast(ChatCompletionFileObjectFile, potential_file_obj)
+ content_item_typed = cast(ChatCompletionFileObject, content_item)
+ if self.contains_pdf_url(file_obj):
+ file_obj = await self._async_handle_pdf_url(file_obj)
+ file_obj = self._common_file_data_check(file_obj)
+ content_item_typed["file"] = file_obj
+ content_item = content_item_typed
+ return content_item
+
@overload
def _transform_messages(
self, messages: List[AllMessageValues], model: str, is_async: Literal[True]
@@ -270,67 +333,6 @@ class OpenAIGPTConfig(BaseLLMModelInfo, BaseConfig):
) -> Union[List[AllMessageValues], Coroutine[Any, Any, List[AllMessageValues]]]:
"""OpenAI no longer supports image_url as a string, so we need to convert it to a dict"""
- def _apply_common_transform_content_item(
- content_item: OpenAIMessageContentListBlock,
- ) -> OpenAIMessageContentListBlock:
- litellm_specific_params = {"format"}
- if content_item.get("type") == "image_url":
- content_item = cast(ChatCompletionImageObject, content_item)
- if isinstance(content_item["image_url"], str):
- content_item["image_url"] = {
- "url": content_item["image_url"],
- }
- elif isinstance(content_item["image_url"], dict):
- new_image_url_obj = ChatCompletionImageUrlObject(
- **{ # type: ignore
- k: v
- for k, v in content_item["image_url"].items()
- if k not in litellm_specific_params
- }
- )
- content_item["image_url"] = new_image_url_obj
- elif content_item.get("type") == "file":
- content_item = cast(ChatCompletionFileObject, content_item)
- file_obj = content_item["file"]
- new_file_obj = ChatCompletionFileObjectFile(
- **{ # type: ignore
- k: v
- for k, v in file_obj.items()
- if k not in litellm_specific_params
- }
- )
- content_item["file"] = new_file_obj
-
- return content_item
-
- def _transform_content_item(
- content_item: OpenAIMessageContentListBlock,
- ) -> OpenAIMessageContentListBlock:
- content_item = _apply_common_transform_content_item(content_item)
- content_item_type = content_item.get("type")
- potential_file_obj = content_item.get("file")
- if content_item_type == "file" and potential_file_obj:
- file_obj = cast(ChatCompletionFileObjectFile, potential_file_obj)
- content_item_typed = cast(ChatCompletionFileObject, content_item)
- content_item_typed["file"] = self._handle_pdf_url(file_obj)
- content_item = content_item_typed
- return content_item
-
- async def _async_transform_content_item(
- content_item: OpenAIMessageContentListBlock, is_async: bool = False
- ) -> OpenAIMessageContentListBlock:
- content_item = _apply_common_transform_content_item(content_item)
- content_item_type = content_item.get("type")
- potential_file_obj = content_item.get("file")
- if content_item_type == "file" and potential_file_obj:
- file_obj = cast(ChatCompletionFileObjectFile, potential_file_obj)
- content_item_typed = cast(ChatCompletionFileObject, content_item)
- content_item_typed["file"] = await self._handle_pdf_url(
- file_obj, is_async=True
- )
- content_item = content_item_typed
- return content_item
-
async def _async_transform():
for message in messages:
message_content = message.get("content")
@@ -344,7 +346,9 @@ class OpenAIGPTConfig(BaseLLMModelInfo, BaseConfig):
List[OpenAIMessageContentListBlock], message_content
)
for i, content_item in enumerate(message_content_types):
- message_content_types[i] = await _async_transform_content_item(
+ message_content_types[
+ i
+ ] = await self._async_transform_content_item(
cast(OpenAIMessageContentListBlock, content_item),
)
return messages
@@ -364,7 +368,7 @@ class OpenAIGPTConfig(BaseLLMModelInfo, BaseConfig):
List[OpenAIMessageContentListBlock], message_content
)
for i, content_item in enumerate(message_content):
- message_content_types[i] = _transform_content_item(
+ message_content_types[i] = self._transform_content_item(
cast(OpenAIMessageContentListBlock, content_item)
)
return messages
diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json
index 79a6aaab2e4..e7f63d18e13 100644
--- a/litellm/model_prices_and_context_window_backup.json
+++ b/litellm/model_prices_and_context_window_backup.json
@@ -79,6 +79,7 @@
"supported_endpoints": ["/v1/chat/completions", "/v1/batch", "/v1/responses"],
"supported_modalities": ["text", "image"],
"supported_output_modalities": ["text"],
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -108,6 +109,7 @@
"supported_endpoints": ["/v1/chat/completions", "/v1/batch", "/v1/responses"],
"supported_modalities": ["text", "image"],
"supported_output_modalities": ["text"],
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -137,6 +139,7 @@
"supported_endpoints": ["/v1/chat/completions", "/v1/batch", "/v1/responses"],
"supported_modalities": ["text", "image"],
"supported_output_modalities": ["text"],
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -166,6 +169,7 @@
"supported_endpoints": ["/v1/chat/completions", "/v1/batch", "/v1/responses"],
"supported_modalities": ["text", "image"],
"supported_output_modalities": ["text"],
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -195,6 +199,7 @@
"supported_endpoints": ["/v1/chat/completions", "/v1/batch", "/v1/responses"],
"supported_modalities": ["text", "image"],
"supported_output_modalities": ["text"],
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -218,6 +223,7 @@
"supported_endpoints": ["/v1/chat/completions", "/v1/batch", "/v1/responses"],
"supported_modalities": ["text", "image"],
"supported_output_modalities": ["text"],
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -238,6 +244,7 @@
"cache_read_input_token_cost": 0.00000125,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -281,6 +288,7 @@
"cache_read_input_token_cost": 0.00000125,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -306,6 +314,7 @@
"cache_read_input_token_cost": 0.00000125,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -331,6 +340,7 @@
"cache_read_input_token_cost": 0.0000375,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -350,6 +360,7 @@
"cache_read_input_token_cost": 0.0000375,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -438,6 +449,7 @@
"cache_read_input_token_cost": 0.000000075,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -463,6 +475,7 @@
"cache_read_input_token_cost": 0.000000075,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -488,6 +501,7 @@
"cache_read_input_token_cost": 0.000000075,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -513,6 +527,7 @@
"cache_read_input_token_cost": 0.000000075,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -536,6 +551,7 @@
"output_cost_per_token_batches": 0.0003,
"litellm_provider": "openai",
"mode": "responses",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_vision": true,
@@ -559,6 +575,7 @@
"output_cost_per_token_batches": 0.0003,
"litellm_provider": "openai",
"mode": "responses",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_vision": true,
@@ -584,6 +601,7 @@
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_vision": true,
+ "supports_pdf_input": true,
"supports_prompt_caching": true,
"supports_system_messages": true,
"supports_response_schema": true,
@@ -600,6 +618,7 @@
"litellm_provider": "openai",
"mode": "chat",
"supports_vision": true,
+ "supports_pdf_input": true,
"supports_prompt_caching": true
},
"computer-use-preview": {
@@ -634,6 +653,7 @@
"supports_function_calling": true,
"supports_parallel_function_calling": false,
"supports_vision": true,
+ "supports_pdf_input": true,
"supports_prompt_caching": true,
"supports_response_schema": true,
"supports_reasoning": true,
@@ -651,6 +671,7 @@
"supports_function_calling": true,
"supports_parallel_function_calling": false,
"supports_vision": true,
+ "supports_pdf_input": true,
"supports_prompt_caching": true,
"supports_response_schema": true,
"supports_reasoning": true,
@@ -699,6 +720,7 @@
"cache_read_input_token_cost": 2.75e-7,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": false,
"supports_vision": true,
@@ -716,6 +738,7 @@
"cache_read_input_token_cost": 2.75e-7,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": false,
"supports_vision": true,
@@ -733,6 +756,7 @@
"cache_read_input_token_cost": 0.0000015,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_vision": true,
"supports_reasoning": true,
"supports_prompt_caching": true
@@ -746,6 +770,7 @@
"cache_read_input_token_cost": 0.0000075,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_vision": true,
"supports_reasoning": true,
"supports_prompt_caching": true
@@ -759,6 +784,7 @@
"cache_read_input_token_cost": 0.0000075,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_vision": true,
"supports_reasoning": true,
"supports_prompt_caching": true
@@ -772,6 +798,7 @@
"cache_read_input_token_cost": 0.0000075,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_vision": true,
@@ -789,6 +816,7 @@
"output_cost_per_token": 0.000015,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_vision": true,
@@ -806,6 +834,7 @@
"output_cost_per_token_batches": 0.0000075,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_vision": true,
@@ -824,6 +853,7 @@
"cache_read_input_token_cost": 0.00000125,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -849,6 +879,7 @@
"cache_read_input_token_cost": 0.00000125,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -958,6 +989,7 @@
"output_cost_per_token": 0.00003,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_prompt_caching": true,
@@ -1034,6 +1066,7 @@
"output_cost_per_token": 0.00003,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_vision": true,
@@ -1049,6 +1082,7 @@
"output_cost_per_token": 0.00003,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_vision": true,
@@ -1093,6 +1127,7 @@
"litellm_provider": "openai",
"mode": "chat",
"supports_vision": true,
+ "supports_pdf_input": true,
"supports_prompt_caching": true,
"supports_system_messages": true,
"deprecation_date": "2024-12-06",
@@ -1107,6 +1142,7 @@
"litellm_provider": "openai",
"mode": "chat",
"supports_vision": true,
+ "supports_pdf_input": true,
"supports_prompt_caching": true,
"supports_system_messages": true,
"deprecation_date": "2024-12-06",
@@ -1271,6 +1307,7 @@
"output_cost_per_token_batches": 0.000007500,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -1287,6 +1324,7 @@
"output_cost_per_token": 0.000015,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -1310,6 +1348,7 @@
"supports_parallel_function_calling": true,
"supports_response_schema": true,
"supports_vision": true,
+ "supports_pdf_input": true,
"supports_prompt_caching": true,
"supports_system_messages": true,
"supports_tool_choice": true
@@ -2295,6 +2334,7 @@
"cache_read_input_token_cost": 0.0000075,
"litellm_provider": "azure",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_vision": false,
diff --git a/litellm/types/llms/bedrock.py b/litellm/types/llms/bedrock.py
index 834be071da1..8c95349e4a4 100644
--- a/litellm/types/llms/bedrock.py
+++ b/litellm/types/llms/bedrock.py
@@ -141,8 +141,9 @@ class ToolSpecBlock(TypedDict, total=False):
description: str
-class ToolBlock(TypedDict):
+class ToolBlock(TypedDict, total=False):
toolSpec: Optional[ToolSpecBlock]
+ cachePoint: Optional[CachePointBlock]
class SpecificToolChoiceBlock(TypedDict):
diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json
index 79a6aaab2e4..e7f63d18e13 100644
--- a/model_prices_and_context_window.json
+++ b/model_prices_and_context_window.json
@@ -79,6 +79,7 @@
"supported_endpoints": ["/v1/chat/completions", "/v1/batch", "/v1/responses"],
"supported_modalities": ["text", "image"],
"supported_output_modalities": ["text"],
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -108,6 +109,7 @@
"supported_endpoints": ["/v1/chat/completions", "/v1/batch", "/v1/responses"],
"supported_modalities": ["text", "image"],
"supported_output_modalities": ["text"],
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -137,6 +139,7 @@
"supported_endpoints": ["/v1/chat/completions", "/v1/batch", "/v1/responses"],
"supported_modalities": ["text", "image"],
"supported_output_modalities": ["text"],
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -166,6 +169,7 @@
"supported_endpoints": ["/v1/chat/completions", "/v1/batch", "/v1/responses"],
"supported_modalities": ["text", "image"],
"supported_output_modalities": ["text"],
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -195,6 +199,7 @@
"supported_endpoints": ["/v1/chat/completions", "/v1/batch", "/v1/responses"],
"supported_modalities": ["text", "image"],
"supported_output_modalities": ["text"],
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -218,6 +223,7 @@
"supported_endpoints": ["/v1/chat/completions", "/v1/batch", "/v1/responses"],
"supported_modalities": ["text", "image"],
"supported_output_modalities": ["text"],
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -238,6 +244,7 @@
"cache_read_input_token_cost": 0.00000125,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -281,6 +288,7 @@
"cache_read_input_token_cost": 0.00000125,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -306,6 +314,7 @@
"cache_read_input_token_cost": 0.00000125,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -331,6 +340,7 @@
"cache_read_input_token_cost": 0.0000375,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -350,6 +360,7 @@
"cache_read_input_token_cost": 0.0000375,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -438,6 +449,7 @@
"cache_read_input_token_cost": 0.000000075,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -463,6 +475,7 @@
"cache_read_input_token_cost": 0.000000075,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -488,6 +501,7 @@
"cache_read_input_token_cost": 0.000000075,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -513,6 +527,7 @@
"cache_read_input_token_cost": 0.000000075,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -536,6 +551,7 @@
"output_cost_per_token_batches": 0.0003,
"litellm_provider": "openai",
"mode": "responses",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_vision": true,
@@ -559,6 +575,7 @@
"output_cost_per_token_batches": 0.0003,
"litellm_provider": "openai",
"mode": "responses",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_vision": true,
@@ -584,6 +601,7 @@
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_vision": true,
+ "supports_pdf_input": true,
"supports_prompt_caching": true,
"supports_system_messages": true,
"supports_response_schema": true,
@@ -600,6 +618,7 @@
"litellm_provider": "openai",
"mode": "chat",
"supports_vision": true,
+ "supports_pdf_input": true,
"supports_prompt_caching": true
},
"computer-use-preview": {
@@ -634,6 +653,7 @@
"supports_function_calling": true,
"supports_parallel_function_calling": false,
"supports_vision": true,
+ "supports_pdf_input": true,
"supports_prompt_caching": true,
"supports_response_schema": true,
"supports_reasoning": true,
@@ -651,6 +671,7 @@
"supports_function_calling": true,
"supports_parallel_function_calling": false,
"supports_vision": true,
+ "supports_pdf_input": true,
"supports_prompt_caching": true,
"supports_response_schema": true,
"supports_reasoning": true,
@@ -699,6 +720,7 @@
"cache_read_input_token_cost": 2.75e-7,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": false,
"supports_vision": true,
@@ -716,6 +738,7 @@
"cache_read_input_token_cost": 2.75e-7,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": false,
"supports_vision": true,
@@ -733,6 +756,7 @@
"cache_read_input_token_cost": 0.0000015,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_vision": true,
"supports_reasoning": true,
"supports_prompt_caching": true
@@ -746,6 +770,7 @@
"cache_read_input_token_cost": 0.0000075,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_vision": true,
"supports_reasoning": true,
"supports_prompt_caching": true
@@ -759,6 +784,7 @@
"cache_read_input_token_cost": 0.0000075,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_vision": true,
"supports_reasoning": true,
"supports_prompt_caching": true
@@ -772,6 +798,7 @@
"cache_read_input_token_cost": 0.0000075,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_vision": true,
@@ -789,6 +816,7 @@
"output_cost_per_token": 0.000015,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_vision": true,
@@ -806,6 +834,7 @@
"output_cost_per_token_batches": 0.0000075,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_vision": true,
@@ -824,6 +853,7 @@
"cache_read_input_token_cost": 0.00000125,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -849,6 +879,7 @@
"cache_read_input_token_cost": 0.00000125,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -958,6 +989,7 @@
"output_cost_per_token": 0.00003,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_prompt_caching": true,
@@ -1034,6 +1066,7 @@
"output_cost_per_token": 0.00003,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_vision": true,
@@ -1049,6 +1082,7 @@
"output_cost_per_token": 0.00003,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_vision": true,
@@ -1093,6 +1127,7 @@
"litellm_provider": "openai",
"mode": "chat",
"supports_vision": true,
+ "supports_pdf_input": true,
"supports_prompt_caching": true,
"supports_system_messages": true,
"deprecation_date": "2024-12-06",
@@ -1107,6 +1142,7 @@
"litellm_provider": "openai",
"mode": "chat",
"supports_vision": true,
+ "supports_pdf_input": true,
"supports_prompt_caching": true,
"supports_system_messages": true,
"deprecation_date": "2024-12-06",
@@ -1271,6 +1307,7 @@
"output_cost_per_token_batches": 0.000007500,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -1287,6 +1324,7 @@
"output_cost_per_token": 0.000015,
"litellm_provider": "openai",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_response_schema": true,
@@ -1310,6 +1348,7 @@
"supports_parallel_function_calling": true,
"supports_response_schema": true,
"supports_vision": true,
+ "supports_pdf_input": true,
"supports_prompt_caching": true,
"supports_system_messages": true,
"supports_tool_choice": true
@@ -2295,6 +2334,7 @@
"cache_read_input_token_cost": 0.0000075,
"litellm_provider": "azure",
"mode": "chat",
+ "supports_pdf_input": true,
"supports_function_calling": true,
"supports_parallel_function_calling": true,
"supports_vision": false,
diff --git a/tests/litellm/llms/bedrock/chat/test_converse_transformation.py b/tests/litellm/llms/bedrock/chat/test_converse_transformation.py
index ef0b296fe02..34dcb325d71 100644
--- a/tests/litellm/llms/bedrock/chat/test_converse_transformation.py
+++ b/tests/litellm/llms/bedrock/chat/test_converse_transformation.py
@@ -176,3 +176,61 @@ def test_apply_tool_call_transformation_if_needed():
assert transformed_message.tool_calls[0].function.arguments == json.dumps(
tool_response["parameters"]
)
+
+
+def test_transform_tool_call_with_cache_control():
+ from litellm.llms.bedrock.chat.converse_transformation import AmazonConverseConfig
+
+ config = AmazonConverseConfig()
+
+ messages = [{"role": "user", "content": "Am I lost?"}]
+
+ tools = [
+ {
+ "type": "function",
+ "function": {
+ "name": "get_location",
+ "description": "Get the user's location",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "location": {
+ "type": "string",
+ "description": "The city and state, e.g. San Francisco, CA",
+ },
+ "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
+ },
+ "required": ["location"],
+ },
+ },
+ "cache_control": {"type": "ephemeral"},
+ },
+ ]
+
+ result = config.transform_request(
+ model="bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0",
+ messages=messages,
+ optional_params={"tools": tools},
+ litellm_params={},
+ headers={},
+ )
+
+ assert "toolConfig" in result
+ assert "tools" in result["toolConfig"]
+
+ assert len(result["toolConfig"]["tools"]) == 2
+
+ function_out_msg = result["toolConfig"]["tools"][0]
+ print(function_out_msg)
+ assert function_out_msg["toolSpec"]["name"] == "get_location"
+ assert function_out_msg["toolSpec"]["description"] == "Get the user's location"
+ assert (
+ function_out_msg["toolSpec"]["inputSchema"]["json"]["properties"]["location"][
+ "type"
+ ]
+ == "string"
+ )
+
+ transformed_cache_msg = result["toolConfig"]["tools"][1]
+ assert "cachePoint" in transformed_cache_msg
+ assert transformed_cache_msg["cachePoint"]["type"] == "default"
diff --git a/tests/litellm/test_utils.py b/tests/litellm/test_utils.py
index 36da4162a8e..12fd42bfb90 100644
--- a/tests/litellm/test_utils.py
+++ b/tests/litellm/test_utils.py
@@ -4,6 +4,7 @@ import sys
from unittest.mock import patch
import pytest
+from jsonschema import validate
sys.path.insert(
0, os.path.abspath("../..")
@@ -319,3 +320,201 @@ def test_cohere_embedding_optional_params():
dimensions=512,
)
assert optional_params is not None
+
+
+def test_aaamodel_prices_and_context_window_json_is_valid():
+ """
+ Validates the `model_prices_and_context_window.json` file.
+
+ If this test fails after you update the json, you need to update the schema or correct the change you made.
+ """
+
+ INTENDED_SCHEMA = {
+ "type": "object",
+ "additionalProperties": {
+ "type": "object",
+ "properties": {
+ "cache_creation_input_audio_token_cost": {"type": "number"},
+ "cache_creation_input_token_cost": {"type": "number"},
+ "cache_read_input_token_cost": {"type": "number"},
+ "cache_read_input_audio_token_cost": {"type": "number"},
+ "deprecation_date": {"type": "string"},
+ "input_cost_per_audio_per_second": {"type": "number"},
+ "input_cost_per_audio_per_second_above_128k_tokens": {"type": "number"},
+ "input_cost_per_audio_token": {"type": "number"},
+ "input_cost_per_character": {"type": "number"},
+ "input_cost_per_character_above_128k_tokens": {"type": "number"},
+ "input_cost_per_image": {"type": "number"},
+ "input_cost_per_image_above_128k_tokens": {"type": "number"},
+ "input_cost_per_token_above_200k_tokens": {"type": "number"},
+ "input_cost_per_pixel": {"type": "number"},
+ "input_cost_per_query": {"type": "number"},
+ "input_cost_per_request": {"type": "number"},
+ "input_cost_per_second": {"type": "number"},
+ "input_cost_per_token": {"type": "number"},
+ "input_cost_per_token_above_128k_tokens": {"type": "number"},
+ "input_cost_per_token_batch_requests": {"type": "number"},
+ "input_cost_per_token_batches": {"type": "number"},
+ "input_cost_per_token_cache_hit": {"type": "number"},
+ "input_cost_per_video_per_second": {"type": "number"},
+ "input_cost_per_video_per_second_above_8s_interval": {"type": "number"},
+ "input_cost_per_video_per_second_above_15s_interval": {
+ "type": "number"
+ },
+ "input_cost_per_video_per_second_above_128k_tokens": {"type": "number"},
+ "input_dbu_cost_per_token": {"type": "number"},
+ "litellm_provider": {"type": "string"},
+ "max_audio_length_hours": {"type": "number"},
+ "max_audio_per_prompt": {"type": "number"},
+ "max_document_chunks_per_query": {"type": "number"},
+ "max_images_per_prompt": {"type": "number"},
+ "max_input_tokens": {"type": "number"},
+ "max_output_tokens": {"type": "number"},
+ "max_pdf_size_mb": {"type": "number"},
+ "max_query_tokens": {"type": "number"},
+ "max_tokens": {"type": "number"},
+ "max_tokens_per_document_chunk": {"type": "number"},
+ "max_video_length": {"type": "number"},
+ "max_videos_per_prompt": {"type": "number"},
+ "metadata": {"type": "object"},
+ "mode": {
+ "type": "string",
+ "enum": [
+ "audio_speech",
+ "audio_transcription",
+ "chat",
+ "completion",
+ "embedding",
+ "image_generation",
+ "moderation",
+ "rerank",
+ "responses",
+ ],
+ },
+ "output_cost_per_audio_token": {"type": "number"},
+ "output_cost_per_character": {"type": "number"},
+ "output_cost_per_character_above_128k_tokens": {"type": "number"},
+ "output_cost_per_image": {"type": "number"},
+ "output_cost_per_pixel": {"type": "number"},
+ "output_cost_per_second": {"type": "number"},
+ "output_cost_per_token": {"type": "number"},
+ "output_cost_per_token_above_128k_tokens": {"type": "number"},
+ "output_cost_per_token_above_200k_tokens": {"type": "number"},
+ "output_cost_per_token_batches": {"type": "number"},
+ "output_cost_per_reasoning_token": {"type": "number"},
+ "output_db_cost_per_token": {"type": "number"},
+ "output_dbu_cost_per_token": {"type": "number"},
+ "output_vector_size": {"type": "number"},
+ "rpd": {"type": "number"},
+ "rpm": {"type": "number"},
+ "source": {"type": "string"},
+ "supports_assistant_prefill": {"type": "boolean"},
+ "supports_audio_input": {"type": "boolean"},
+ "supports_audio_output": {"type": "boolean"},
+ "supports_embedding_image_input": {"type": "boolean"},
+ "supports_function_calling": {"type": "boolean"},
+ "supports_image_input": {"type": "boolean"},
+ "supports_parallel_function_calling": {"type": "boolean"},
+ "supports_pdf_input": {"type": "boolean"},
+ "supports_prompt_caching": {"type": "boolean"},
+ "supports_response_schema": {"type": "boolean"},
+ "supports_system_messages": {"type": "boolean"},
+ "supports_tool_choice": {"type": "boolean"},
+ "supports_video_input": {"type": "boolean"},
+ "supports_vision": {"type": "boolean"},
+ "supports_web_search": {"type": "boolean"},
+ "supports_reasoning": {"type": "boolean"},
+ "tool_use_system_prompt_tokens": {"type": "number"},
+ "tpm": {"type": "number"},
+ "supported_endpoints": {
+ "type": "array",
+ "items": {
+ "type": "string",
+ "enum": [
+ "/v1/responses",
+ "/v1/embeddings",
+ "/v1/chat/completions",
+ "/v1/completions",
+ "/v1/images/generations",
+ "/v1/images/variations",
+ "/v1/images/edits",
+ "/v1/batch",
+ "/v1/audio/transcriptions",
+ "/v1/audio/speech",
+ ],
+ },
+ },
+ "search_context_cost_per_query": {
+ "type": "object",
+ "properties": {
+ "search_context_size_low": {"type": "number"},
+ "search_context_size_medium": {"type": "number"},
+ "search_context_size_high": {"type": "number"},
+ },
+ "additionalProperties": False,
+ },
+ "supported_modalities": {
+ "type": "array",
+ "items": {
+ "type": "string",
+ "enum": ["text", "audio", "image", "video"],
+ },
+ },
+ "supported_output_modalities": {
+ "type": "array",
+ "items": {
+ "type": "string",
+ "enum": ["text", "image", "audio", "code"],
+ },
+ },
+ "supports_native_streaming": {"type": "boolean"},
+ },
+ "additionalProperties": False,
+ },
+ }
+
+ prod_json = "./model_prices_and_context_window.json"
+ with open(prod_json, "r") as model_prices_file:
+ actual_json = json.load(model_prices_file)
+ assert isinstance(actual_json, dict)
+ actual_json.pop(
+ "sample_spec", None
+ ) # remove the sample, whose schema is inconsistent with the real data
+
+ validate(actual_json, INTENDED_SCHEMA)
+
+
+def test_get_model_info_gemini():
+ """
+ Tests if ALL gemini models have 'tpm' and 'rpm' in the model info
+ """
+ os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
+ litellm.model_cost = litellm.get_model_cost_map(url="")
+
+ model_map = litellm.model_cost
+ for model, info in model_map.items():
+ if (
+ model.startswith("gemini/")
+ and not "gemma" in model
+ and not "learnlm" in model
+ ):
+ assert info.get("tpm") is not None, f"{model} does not have tpm"
+ assert info.get("rpm") is not None, f"{model} does not have rpm"
+
+
+def test_openai_models_in_model_info():
+ os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
+ litellm.model_cost = litellm.get_model_cost_map(url="")
+
+ model_map = litellm.model_cost
+ violated_models = []
+ for model, info in model_map.items():
+ if (
+ info.get("litellm_provider") == "openai"
+ and info.get("supports_vision") is True
+ ):
+ if info.get("supports_pdf_input") is not True:
+ violated_models.append(model)
+ assert (
+ len(violated_models) == 0
+ ), f"The following models should support pdf input: {violated_models}"
diff --git a/tests/llm_translation/base_llm_unit_tests.py b/tests/llm_translation/base_llm_unit_tests.py
index 270895b17f1..624ed13071c 100644
--- a/tests/llm_translation/base_llm_unit_tests.py
+++ b/tests/llm_translation/base_llm_unit_tests.py
@@ -174,20 +174,23 @@ class BaseLLMChatTest(ABC):
self.completion_function(**base_completion_call_args, messages=messages)
- @pytest.mark.parametrize("image_url", ["str", "dict"])
- def test_pdf_handling(self, pdf_messages, image_url):
+ @pytest.mark.parametrize("sync_mode", [True, False])
+ @pytest.mark.asyncio
+ async def test_pdf_handling(self, pdf_messages, sync_mode):
from litellm.utils import supports_pdf_input
+ os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
+ litellm.model_cost = litellm.get_model_cost_map(url="")
+
+ litellm._turn_on_debug()
- if image_url == "str":
- image_url = pdf_messages
- elif image_url == "dict":
- image_url = {"url": pdf_messages}
image_content = [
{"type": "text", "text": "What's this file about?"},
{
- "type": "image_url",
- "image_url": image_url,
+ "type": "file",
+ "file": {
+ "file_data": pdf_messages,
+ },
},
]
@@ -198,10 +201,17 @@ class BaseLLMChatTest(ABC):
if not supports_pdf_input(base_completion_call_args["model"], None):
pytest.skip("Model does not support image input")
- response = self.completion_function(
- **base_completion_call_args,
- messages=image_messages,
- )
+ if sync_mode:
+ response = self.completion_function(
+ **base_completion_call_args,
+ messages=image_messages,
+ )
+ else:
+ response = await self.async_completion_function(
+ **base_completion_call_args,
+ messages=image_messages,
+ )
+
assert response is not None
def test_file_data_unit_test(self, pdf_messages):
diff --git a/tests/local_testing/test_get_model_info.py b/tests/local_testing/test_get_model_info.py
index 73e6269dccd..cff7be4cc02 100644
--- a/tests/local_testing/test_get_model_info.py
+++ b/tests/local_testing/test_get_model_info.py
@@ -5,7 +5,7 @@ import sys
import traceback
import json
-from jsonschema import validate
+
from typing import List, Dict, Any
@@ -115,22 +115,6 @@ def test_get_model_info_ollama_chat():
assert mock_client.call_args.kwargs["json"]["name"] == "unknown-model"
-def test_get_model_info_gemini():
- """
- Tests if ALL gemini models have 'tpm' and 'rpm' in the model info
- """
- os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
- litellm.model_cost = litellm.get_model_cost_map(url="")
-
- model_map = litellm.model_cost
- for model, info in model_map.items():
- if (
- model.startswith("gemini/")
- and not "gemma" in model
- and not "learnlm" in model
- ):
- assert info.get("tpm") is not None, f"{model} does not have tpm"
- assert info.get("rpm") is not None, f"{model} does not have rpm"
def test_get_model_info_bedrock_region():
@@ -409,164 +393,3 @@ def test_get_model_info_cost_calculator_bedrock_region_cris_stripped(model, prov
assert info["key"] == "us.anthropic.claude-3-haiku-20240307-v1:0"
assert info["litellm_provider"] == "bedrock"
-
-def test_aaamodel_prices_and_context_window_json_is_valid():
- """
- Validates the `model_prices_and_context_window.json` file.
-
- If this test fails after you update the json, you need to update the schema or correct the change you made.
- """
-
- INTENDED_SCHEMA = {
- "type": "object",
- "additionalProperties": {
- "type": "object",
- "properties": {
- "cache_creation_input_audio_token_cost": {"type": "number"},
- "cache_creation_input_token_cost": {"type": "number"},
- "cache_read_input_token_cost": {"type": "number"},
- "cache_read_input_audio_token_cost": {"type": "number"},
- "deprecation_date": {"type": "string"},
- "input_cost_per_audio_per_second": {"type": "number"},
- "input_cost_per_audio_per_second_above_128k_tokens": {"type": "number"},
- "input_cost_per_audio_token": {"type": "number"},
- "input_cost_per_character": {"type": "number"},
- "input_cost_per_character_above_128k_tokens": {"type": "number"},
- "input_cost_per_image": {"type": "number"},
- "input_cost_per_image_above_128k_tokens": {"type": "number"},
- "input_cost_per_token_above_200k_tokens": {"type": "number"},
- "input_cost_per_pixel": {"type": "number"},
- "input_cost_per_query": {"type": "number"},
- "input_cost_per_request": {"type": "number"},
- "input_cost_per_second": {"type": "number"},
- "input_cost_per_token": {"type": "number"},
- "input_cost_per_token_above_128k_tokens": {"type": "number"},
- "input_cost_per_token_batch_requests": {"type": "number"},
- "input_cost_per_token_batches": {"type": "number"},
- "input_cost_per_token_cache_hit": {"type": "number"},
- "input_cost_per_video_per_second": {"type": "number"},
- "input_cost_per_video_per_second_above_8s_interval": {"type": "number"},
- "input_cost_per_video_per_second_above_15s_interval": {
- "type": "number"
- },
- "input_cost_per_video_per_second_above_128k_tokens": {"type": "number"},
- "input_dbu_cost_per_token": {"type": "number"},
- "litellm_provider": {"type": "string"},
- "max_audio_length_hours": {"type": "number"},
- "max_audio_per_prompt": {"type": "number"},
- "max_document_chunks_per_query": {"type": "number"},
- "max_images_per_prompt": {"type": "number"},
- "max_input_tokens": {"type": "number"},
- "max_output_tokens": {"type": "number"},
- "max_pdf_size_mb": {"type": "number"},
- "max_query_tokens": {"type": "number"},
- "max_tokens": {"type": "number"},
- "max_tokens_per_document_chunk": {"type": "number"},
- "max_video_length": {"type": "number"},
- "max_videos_per_prompt": {"type": "number"},
- "metadata": {"type": "object"},
- "mode": {
- "type": "string",
- "enum": [
- "audio_speech",
- "audio_transcription",
- "chat",
- "completion",
- "embedding",
- "image_generation",
- "moderation",
- "rerank",
- "responses",
- ],
- },
- "output_cost_per_audio_token": {"type": "number"},
- "output_cost_per_character": {"type": "number"},
- "output_cost_per_character_above_128k_tokens": {"type": "number"},
- "output_cost_per_image": {"type": "number"},
- "output_cost_per_pixel": {"type": "number"},
- "output_cost_per_second": {"type": "number"},
- "output_cost_per_token": {"type": "number"},
- "output_cost_per_token_above_128k_tokens": {"type": "number"},
- "output_cost_per_token_above_200k_tokens": {"type": "number"},
- "output_cost_per_token_batches": {"type": "number"},
- "output_cost_per_reasoning_token": {"type": "number"},
- "output_db_cost_per_token": {"type": "number"},
- "output_dbu_cost_per_token": {"type": "number"},
- "output_vector_size": {"type": "number"},
- "rpd": {"type": "number"},
- "rpm": {"type": "number"},
- "source": {"type": "string"},
- "supports_assistant_prefill": {"type": "boolean"},
- "supports_audio_input": {"type": "boolean"},
- "supports_audio_output": {"type": "boolean"},
- "supports_embedding_image_input": {"type": "boolean"},
- "supports_function_calling": {"type": "boolean"},
- "supports_image_input": {"type": "boolean"},
- "supports_parallel_function_calling": {"type": "boolean"},
- "supports_pdf_input": {"type": "boolean"},
- "supports_prompt_caching": {"type": "boolean"},
- "supports_response_schema": {"type": "boolean"},
- "supports_system_messages": {"type": "boolean"},
- "supports_tool_choice": {"type": "boolean"},
- "supports_video_input": {"type": "boolean"},
- "supports_vision": {"type": "boolean"},
- "supports_web_search": {"type": "boolean"},
- "supports_reasoning": {"type": "boolean"},
- "tool_use_system_prompt_tokens": {"type": "number"},
- "tpm": {"type": "number"},
- "supported_endpoints": {
- "type": "array",
- "items": {
- "type": "string",
- "enum": [
- "/v1/responses",
- "/v1/embeddings",
- "/v1/chat/completions",
- "/v1/completions",
- "/v1/images/generations",
- "/v1/images/variations",
- "/v1/images/edits",
- "/v1/batch",
- "/v1/audio/transcriptions",
- "/v1/audio/speech",
- ],
- },
- },
- "search_context_cost_per_query": {
- "type": "object",
- "properties": {
- "search_context_size_low": {"type": "number"},
- "search_context_size_medium": {"type": "number"},
- "search_context_size_high": {"type": "number"},
- },
- "additionalProperties": False,
- },
- "supported_modalities": {
- "type": "array",
- "items": {
- "type": "string",
- "enum": ["text", "audio", "image", "video"],
- },
- },
- "supported_output_modalities": {
- "type": "array",
- "items": {
- "type": "string",
- "enum": ["text", "image", "audio", "code"],
- },
- },
- "supports_native_streaming": {"type": "boolean"},
- },
- "additionalProperties": False,
- },
- }
-
- prod_json = "./model_prices_and_context_window.json"
- with open(prod_json, "r") as model_prices_file:
- actual_json = json.load(model_prices_file)
- assert isinstance(actual_json, dict)
- actual_json.pop(
- "sample_spec", None
- ) # remove the sample, whose schema is inconsistent with the real data
-
- validate(actual_json, INTENDED_SCHEMA)