litellm - ✅(Solved) Fix [Bug]: Unable to use a gemini file id on responses [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#24907Fetched 2026-04-08 02:23:50
View on GitHub
Comments
0
Participants
1
Timeline
7
Reactions
0
Author
Participants
Timeline (top)
referenced ×3cross-referenced ×2labeled ×1marked_as_duplicate ×1

Error Message

Error: 500 litellm.APIConnectionError: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format Traceback (most recent call last): File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 401, in _gemini_convert_messages_with_history _part = _process_gemini_media( image_url=passed_file, ...<3 lines>... video_metadata=video_metadata, ) File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 230, in _process_gemini_media raise e File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 222, in _process_gemini_media image = convert_to_anthropic_image_obj(image_url, format=format) File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/factory.py", line 892, in convert_to_anthropic_image_obj openai_image_url = convert_url_to_base64(url=openai_image_url) File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 113, in convert_url_to_base64 return _process_image_response(response, url) File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 21, in _process_image_response raise litellm.ImageFetchError( f"Error: Unable to fetch image from URL. Status code: {response.status_code}, url={url}" ) litellm.exceptions.ImageFetchError: litellm.BadRequestError: Error: Unable to fetch image from URL. Status code: 403, url=https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3.13/site-packages/litellm/main.py", line 620, in acompletion response = await init_response ^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 2738, in async_completion request_body = await async_transform_request_body( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<4 lines>... ) # type: ignore ^ File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 875, in async_transform_request_body return _transform_request_body( messages=messages, ...<4 lines>... optional_params=optional_params, ) File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 778, in _transform_request_body raise e File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 702, in _transform_request_body content = litellm.GoogleAIStudioGeminiConfig()._transform_messages( messages=messages, model=model ) File "/usr/lib/python3.13/site-packages/litellm/llms/gemini/chat/transformation.py", line 153, in _transform_messages return _gemini_convert_messages_with_history(messages=messages, model=model) File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 635, in _gemini_convert_messages_with_history raise e File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 410, in _gemini_convert_messages_with_history raise Exception( ...<3 lines>... ) Exception: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3.13/site-packages/litellm/router.py", line 5586, in async_function_with_retries response = await self.make_call(original_function, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.13/site-packages/litellm/router.py", line 5754, in make_call response = await response ^^^^^^^^^^^^^^ File "/usr/lib/python3.13/site-packages/litellm/router.py", line 3891, in _ageneric_api_call_with_fallbacks_helper raise e File "/usr/lib/python3.13/site-packages/litellm/router.py", line 3877, in _ageneric_api_call_with_fallbacks_helper response = await response # type: ignore ^^^^^^^^^^^^^^ File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 2094, in wrapper_async raise e File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 1893, in wrapper_async result = await original_function(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.13/site-packages/litellm/responses/main.py", line 580, in aresponses raise litellm.exception_type( ...<5 lines>... ) File "/usr/lib/python3.13/site-packages/litellm/responses/main.py", line 558, in aresponses response = await init_response ^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.13/site-packages/litellm/responses/litellm_completion_transformation/handler.py", line 114, in async_response_api_handler ] = await litellm.acompletion( ^^^^^^^^^^^^^^^^^^^^^^^^^^ **acompletion_args, ^^^^^^^^^^^^^^^^^^^ ) ^ File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 2094, in wrapper_async raise e File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 1893, in wrapper_async result = await original_function(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.13/site-packages/litellm/main.py", line 639, in acompletion raise exception_type( ~~~~~~~~~~~~~~^ model=model, ^^^^^^^^^^^^ ...<3 lines>... extra_kwargs=kwargs, ^^^^^^^^^^^^^^^^^^^^ ) ^ File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2456, in exception_type raise e File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2432, in exception_type raise APIConnectionError( ...<8 lines>... ) litellm.exceptions.APIConnectionError: litellm.APIConnectionError: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format Traceback (most recent call last): File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 401, in _gemini_convert_messages_with_history _part = _process_gemini_media( image_url=passed_file, ...<3 lines>... video_metadata=video_metadata, ) File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 230, in _process_gemini_media raise e File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 222, in _process_gemini_media image = convert_to_anthropic_image_obj(image_url, format=format) File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/factory.py", line 892, in convert_to_anthropic_image_obj openai_image_url = convert_url_to_base64(url=openai_image_url) File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 113, in convert_url_to_base64 return _process_image_response(response, url) File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 21, in _process_image_response raise litellm.ImageFetchError( f"Error: Unable to fetch image from URL. Status code: {response.status_code}, url={url}" ) litellm.exceptions.ImageFetchError: litellm.BadRequestError: Error: Unable to fetch image from URL. Status code: 403, url=https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3.13/site-packages/litellm/main.py", line 620, in acompletion response = await init_response ^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 2738, in async_completion request_body = await async_transform_request_body( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<4 lines>... ) # type: ignore ^ File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 875, in async_transform_request_body return _transform_request_body( messages=messages, ...<4 lines>... optional_params=optional_params, ) File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 778, in _transform_request_body raise e File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 702, in _transform_request_body content = litellm.GoogleAIStudioGeminiConfig()._transform_messages( messages=messages, model=model ) File "/usr/lib/python3.13/site-packages/litellm/llms/gemini/chat/transformation.py", line 153, in _transform_messages return _gemini_convert_messages_with_history(messages=messages, model=model) File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 635, in _gemini_convert_messages_with_history raise e File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 410, in _gemini_convert_messages_with_history raise Exception( ...<3 lines>... ) Exception: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 401, in _gemini_convert_messages_with_history _part = _process_gemini_media( image_url=passed_file, ...<3 lines>... video_metadata=video_metadata, ) File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 230, in _process_gemini_media raise e File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 222, in _process_gemini_media image = convert_to_anthropic_image_obj(image_url, format=format) File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/factory.py", line 892, in convert_to_anthropic_image_obj openai_image_url = convert_url_to_base64(url=openai_image_url) File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 113, in convert_url_to_base64 return _process_image_response(response, url) File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 21, in _process_image_response raise litellm.ImageFetchError( f"Error: Unable to fetch image from URL. Status code: {response.status_code}, url={url}" ) litellm.exceptions.ImageFetchError: litellm.BadRequestError: Error: Unable to fetch image from URL. Status code: 403, url=https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3.13/site-packages/litellm/main.py", line 620, in acompletion response = await init_response ^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 2738, in async_completion request_body = await async_transform_request_body( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<4 lines>... ) # type: ignore ^ File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 875, in async_transform_request_body return _transform_request_body( messages=messages, ...<4 lines>... optional_params=optional_params, ) File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 778, in _transform_request_body raise e File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 702, in _transform_request_body content = litellm.GoogleAIStudioGeminiConfig()._transform_messages( messages=messages, model=model ) File "/usr/lib/python3.13/site-packages/litellm/llms/gemini/chat/transformation.py", line 153, in _transform_messages return _gemini_convert_messages_with_history(messages=messages, model=model) File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 635, in _gemini_convert_messages_with_history raise e File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 410, in _gemini_convert_messages_with_history raise Exception( ...<3 lines>... ) Exception: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format . Received Model Group=gemini/gemini-2.5-flash-Promia Available Model Group Fallbacks=None Serialized Error: { status: 500, headers: { constructor: 'Function<Headers>', append: 'Function<append>', delete: 'Function<delete>', get: 'Function<get>', has: 'Function<has>', set: 'Function<set>', getSetCookie: 'Function<getSetCookie>', keys: 'Function<keys>', values: 'Function<values>', entries: 'Function<entries>', forEach: 'Function<forEach>' }, requestID: null, error: { message: 'litellm.APIConnectionError: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format\n' + 'Traceback (most recent call last):\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 401, in _gemini_convert_messages_with_history\n' + ' _part = _process_gemini_media(\n' + ' image_url=passed_file,\n' + ' ...<3 lines>...\n' + ' video_metadata=video_metadata,\n' + ' )\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 230, in _process_gemini_media\n' + ' raise e\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 222, in _process_gemini_media\n' + ' image = convert_to_anthropic_image_obj(image_url, format=format)\n' + ' File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/factory.py", line 892, in convert_to_anthropic_image_obj\n' + ' openai_image_url = convert_url_to_base64(url=openai_image_url)\n' + ' File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 113, in convert_url_to_base64\n' + ' return _process_image_response(response, url)\n' + ' File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 21, in _process_image_response\n' + ' raise litellm.ImageFetchError(\n' + ' f"Error: Unable to fetch image from URL. Status code: {response.status_code}, url={url}"\n' + ' )\n' + 'litellm.exceptions.ImageFetchError: litellm.BadRequestError: Error: Unable to fetch image from URL. Status code: 403, url=https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw\n' + '\n' + 'During handling of the above exception, another exception occurred:\n' + '\n' + 'Traceback (most recent call last):\n' + ' File "/usr/lib/python3.13/site-packages/litellm/main.py", line 620, in acompletion\n' + ' response = await init_response\n' + ' ^^^^^^^^^^^^^^^^^^^\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 2738, in async_completion\n' + ' request_body = await async_transform_request_body(\n' + ' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n' + ' ...<4 lines>...\n' + ' ) # type: ignore\n' + ' ^\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 875, in async_transform_request_body\n' + ' return _transform_request_body(\n' + ' messages=messages,\n' + ' ...<4 lines>...\n' + ' optional_params=optional_params,\n' + ' )\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 778, in _transform_request_body\n' + ' raise e\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 702, in _transform_request_body\n' + ' content = litellm.GoogleAIStudioGeminiConfig()._transform_messages(\n' + ' messages=messages, model=model\n' + ' )\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/gemini/chat/transformation.py", line 153, in _transform_messages\n' + ' return _gemini_convert_messages_with_history(messages=messages, model=model)\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 635, in _gemini_convert_messages_with_history\n' + ' raise e\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 410, in _gemini_convert_messages_with_history\n' + ' raise Exception(\n' + ' ...<3 lines>...\n' + ' )\n' + 'Exception: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format\n' + '\n' + 'During handling of the above exception, another exception occurred:\n' + '\n' + 'Traceback (most recent call last):\n' + ' File "/usr/lib/python3.13/site-packages/litellm/router.py", line 5586, in async_function_with_retries\n' + ' response = await self.make_call(original_function, *args, **kwargs)\n' + ' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n' + ' File "/usr/lib/python3.13/site-packages/litellm/router.py", line 5754, in make_call\n' + ' response = await response\n' + ' ^^^^^^^^^^^^^^\n' + ' File "/usr/lib/python3.13/site-packages/litellm/router.py", line 3891, in _ageneric_api_call_with_fallbacks_helper\n' + ' raise e\n' + ' File "/usr/lib/python3.13/site-packages/litellm/router.py", line 3877, in _ageneric_api_call_with_fallbacks_helper\n' + ' response = await response # type: ignore\n' + ' ^^^^^^^^^^^^^^\n' + ' File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 2094, in wrapper_async\n' + ' raise e\n' + ' File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 1893, in wrapper_async\n' + ' result = await original_function(*args, **kwargs)\n' + ' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n' + ' File "/usr/lib/python3.13/site-packages/litellm/responses/main.py", line 580, in aresponses\n' + ' raise litellm.exception_type(\n' + ' ...<5 lines>...\n' + ' )\n' + ' File "/usr/lib/python3.13/site-packages/litellm/responses/main.py", line 558, in aresponses\n' + ' response = await init_response\n' + ' ^^^^^^^^^^^^^^^^^^^\n' + ' File "/usr/lib/python3.13/site-packages/litellm/responses/litellm_completion_transformation/handler.py", line 114, in async_response_api_handler\n' + ' ] = await litellm.acompletion(\n' + ' ^^^^^^^^^^^^^^^^^^^^^^^^^^\n' + ' **acompletion_args,\n' + ' ^^^^^^^^^^^^^^^^^^^\n' + ' )\n' + ' ^\n' + ' File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 2094, in wrapper_async\n' + ' raise e\n' + ' File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 1893, in wrapper_async\n' + ' result = await original_function(*args, **kwargs)\n' + ' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n' + ' File "/usr/lib/python3.13/site-packages/litellm/main.py", line 639, in acompletion\n' + ' raise exception_type(\n' + ' ~~~~~~~~~~~~~~^\n' + ' model=model,\n' + ' ^^^^^^^^^^^^\n' + ' ...<3 lines>...\n' + ' extra_kwargs=kwargs,\n' + ' ^^^^^^^^^^^^^^^^^^^^\n' + ' )\n' + ' ^\n' + ' File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2456, in exception_type\n' + ' raise e\n' + ' File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2432, in exception_type\n' + ' raise APIConnectionError(\n' + ' ...<8 lines>...\n' + ' )\n' + 'litellm.exceptions.APIConnectionError: litellm.APIConnectionError: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format\n' + 'Traceback (most recent call last):\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 401, in _gemini_convert_messages_with_history\n' + ' _part = _process_gemini_media(\n' + ' image_url=passed_file,\n' + ' ...<3 lines>...\n' + ' video_metadata=video_metadata,\n' + ' )\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 230, in _process_gemini_media\n' + ' raise e\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 222, in _process_gemini_media\n' + ' image = convert_to_anthropic_image_obj(image_url, format=format)\n' + ' File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/factory.py", line 892, in convert_to_anthropic_image_obj\n' + ' openai_image_url = convert_url_to_base64(url=openai_image_url)\n' + ' File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 113, in convert_url_to_base64\n' + ' return _process_image_response(response, url)\n' + ' File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 21, in _process_image_response\n' + ' raise litellm.ImageFetchError(\n' + ' f"Error: Unable to fetch image from URL. Status code: {response.status_code}, url={url}"\n' + ' )\n' + 'litellm.exceptions.ImageFetchError: litellm.BadRequestError: Error: Unable to fetch image from URL. Status code: 403, url=https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw\n' + '\n' + 'During handling of the above exception, another exception occurred:\n' + '\n' + 'Traceback (most recent call last):\n' + ' File "/usr/lib/python3.13/site-packages/litellm/main.py", line 620, in acompletion\n' + ' response = await init_response\n' + ' ^^^^^^^^^^^^^^^^^^^\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 2738, in async_completion\n' + ' request_body = await async_transform_request_body(\n' + ' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n' + ' ...<4 lines>...\n' + ' ) # type: ignore\n' + ' ^\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 875, in async_transform_request_body\n' + ' return _transform_request_body(\n' + ' messages=messages,\n' + ' ...<4 lines>...\n' + ' optional_params=optional_params,\n' + ' )\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 778, in _transform_request_body\n' + ' raise e\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 702, in _transform_request_body\n' + ' content = litellm.GoogleAIStudioGeminiConfig()._transform_messages(\n' + ' messages=messages, model=model\n' + ' )\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/gemini/chat/transformation.py", line 153, in _transform_messages\n' + ' return _gemini_convert_messages_with_history(messages=messages, model=model)\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 635, in _gemini_convert_messages_with_history\n' + ' raise e\n' + ' File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 410, in _gemini_convert_messages_with_history\n' + ' raise Exception(\n' + ' ...<3 lines>...\n' + ' )\n' + 'Exception: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format\n' + '\n' + '\n' + 'During handling of the above excepti'... 3579 more characters, type: null, param: null, code: '500' }, code: '500', param: null }

Root Cause

Fix Action

Fixed

PR fix notes

PR #24922: fix(gemini): handle Gemini Files API URIs without fetching

Description (problem / solution / changelog)

Summary

Fixes #24907

When a file is uploaded via the Gemini Files API, the returned URI (https://generativelanguage.googleapis.com/v1beta/files/...) starts with https:// and matches the generic HTTPS handler in _process_gemini_media(). That handler calls _get_image_mime_type_from_url() which tries to HTTP-fetch the URL — but Gemini Files API URLs return 403 when accessed directly, causing:

Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/37eh7rsw1vfe

Root Cause

The elif chain in _process_gemini_media() handles:

  1. gs:// URIs → GCS file_data
  2. https:// URLs where MIME type can be resolved → file_data
  3. http:///https:///base64 fallback → inline_data (fetches the URL)

Gemini Files API URIs hit case 2, fail the _get_image_mime_type_from_url() check (403), fall through to case 3, and crash when convert_to_anthropic_image_obj() also gets a 403.

Fix

Added an early elif that specifically matches Gemini Files API URLs (https://generativelanguage.googleapis.com/v1beta/files) and passes them through as file_data without any HTTP fetch. When an explicit format is provided, it's included as mime_type; otherwise the Gemini API infers the MIME type from its stored file metadata.

This follows the exact fix direction suggested by the issue reporter @rodriciru.

Tests

  • test_gemini_files_api_uri_without_format — verifies Gemini Files API URIs work without explicit format (the core bug)
  • test_gemini_files_api_uri_with_format — verifies explicit format is correctly forwarded
  • Existing test_file_data_field_order continues to pass (field ordering preserved)

Changed files

  • litellm/llms/vertex_ai/gemini/transformation.py (modified, +15/-0)
  • tests/test_litellm/llms/vertex_ai/gemini/test_vertex_ai_gemini_transformation.py (modified, +47/-0)

Code Example

elif (
            "https://generativelanguage.googleapis.com/v1beta/files" in image_url
        ):
            file_data = FileDataType(file_uri=image_url)
            part = {"file_data": file_data}
            return _apply_gemini_3_metadata(
                part, model, media_resolution_enum, video_metadata
            )
        elif (
            "https://" in image_url
            and (image_type := format or _get_image_mime_type_from_url(image_url))
            is not None
        ):
            file_data = FileDataType(mime_type=image_type, file_uri=image_url)
            part = {"file_data": file_data}
            return _apply_gemini_3_metadata(
                part, model, media_resolution_enum, video_metadata
            )
        elif "http://" in image_url or "https://" in image_url or "base64" in image_url:
            image = convert_to_anthropic_image_obj(image_url, format=format)
            _blob: BlobType = {"data": image["data"], "mime_type": image["media_type"]}
            part = {"inline_data": cast(BlobType, _blob)}
            return _apply_gemini_3_metadata(
                part, model, media_resolution_enum, video_metadata
            )

---

Error: 500 litellm.APIConnectionError: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format
Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 401, in _gemini_convert_messages_with_history
    _part = _process_gemini_media(
        image_url=passed_file,
    ...<3 lines>...
        video_metadata=video_metadata,
    )
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 230, in _process_gemini_media
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 222, in _process_gemini_media
    image = convert_to_anthropic_image_obj(image_url, format=format)
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/factory.py", line 892, in convert_to_anthropic_image_obj
    openai_image_url = convert_url_to_base64(url=openai_image_url)
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 113, in convert_url_to_base64
    return _process_image_response(response, url)
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 21, in _process_image_response
    raise litellm.ImageFetchError(
        f"Error: Unable to fetch image from URL. Status code: {response.status_code}, url={url}"
    )
litellm.exceptions.ImageFetchError: litellm.BadRequestError: Error: Unable to fetch image from URL. Status code: 403, url=https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/litellm/main.py", line 620, in acompletion
    response = await init_response
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 2738, in async_completion
    request_body = await async_transform_request_body(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
    )  # type: ignore
    ^
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 875, in async_transform_request_body
    return _transform_request_body(
        messages=messages,
    ...<4 lines>...
        optional_params=optional_params,
    )
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 778, in _transform_request_body
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 702, in _transform_request_body
    content = litellm.GoogleAIStudioGeminiConfig()._transform_messages(
        messages=messages, model=model
    )
  File "/usr/lib/python3.13/site-packages/litellm/llms/gemini/chat/transformation.py", line 153, in _transform_messages
    return _gemini_convert_messages_with_history(messages=messages, model=model)
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 635, in _gemini_convert_messages_with_history
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 410, in _gemini_convert_messages_with_history
    raise Exception(
    ...<3 lines>...
    )
Exception: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 5586, in async_function_with_retries
    response = await self.make_call(original_function, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 5754, in make_call
    response = await response
               ^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 3891, in _ageneric_api_call_with_fallbacks_helper
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 3877, in _ageneric_api_call_with_fallbacks_helper
    response = await response  # type: ignore
               ^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 2094, in wrapper_async
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 1893, in wrapper_async
    result = await original_function(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/responses/main.py", line 580, in aresponses
    raise litellm.exception_type(
    ...<5 lines>...
    )
  File "/usr/lib/python3.13/site-packages/litellm/responses/main.py", line 558, in aresponses
    response = await init_response
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/responses/litellm_completion_transformation/handler.py", line 114, in async_response_api_handler
    ] = await litellm.acompletion(
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
        **acompletion_args,
        ^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 2094, in wrapper_async
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 1893, in wrapper_async
    result = await original_function(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/main.py", line 639, in acompletion
    raise exception_type(
          ~~~~~~~~~~~~~~^
        model=model,
        ^^^^^^^^^^^^
    ...<3 lines>...
        extra_kwargs=kwargs,
        ^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2456, in exception_type
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2432, in exception_type
    raise APIConnectionError(
    ...<8 lines>...
    )
litellm.exceptions.APIConnectionError: litellm.APIConnectionError: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format
Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 401, in _gemini_convert_messages_with_history
    _part = _process_gemini_media(
        image_url=passed_file,
    ...<3 lines>...
        video_metadata=video_metadata,
    )
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 230, in _process_gemini_media
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 222, in _process_gemini_media
    image = convert_to_anthropic_image_obj(image_url, format=format)
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/factory.py", line 892, in convert_to_anthropic_image_obj
    openai_image_url = convert_url_to_base64(url=openai_image_url)
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 113, in convert_url_to_base64
    return _process_image_response(response, url)
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 21, in _process_image_response
    raise litellm.ImageFetchError(
        f"Error: Unable to fetch image from URL. Status code: {response.status_code}, url={url}"
    )
litellm.exceptions.ImageFetchError: litellm.BadRequestError: Error: Unable to fetch image from URL. Status code: 403, url=https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/litellm/main.py", line 620, in acompletion
    response = await init_response
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 2738, in async_completion
    request_body = await async_transform_request_body(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
    )  # type: ignore
    ^
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 875, in async_transform_request_body
    return _transform_request_body(
        messages=messages,
    ...<4 lines>...
        optional_params=optional_params,
    )
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 778, in _transform_request_body
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 702, in _transform_request_body
    content = litellm.GoogleAIStudioGeminiConfig()._transform_messages(
        messages=messages, model=model
    )
  File "/usr/lib/python3.13/site-packages/litellm/llms/gemini/chat/transformation.py", line 153, in _transform_messages
    return _gemini_convert_messages_with_history(messages=messages, model=model)
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 635, in _gemini_convert_messages_with_history
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 410, in _gemini_convert_messages_with_history
    raise Exception(
    ...<3 lines>...
    )
Exception: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 401, in _gemini_convert_messages_with_history
    _part = _process_gemini_media(
        image_url=passed_file,
    ...<3 lines>...
        video_metadata=video_metadata,
    )
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 230, in _process_gemini_media
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 222, in _process_gemini_media
    image = convert_to_anthropic_image_obj(image_url, format=format)
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/factory.py", line 892, in convert_to_anthropic_image_obj
    openai_image_url = convert_url_to_base64(url=openai_image_url)
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 113, in convert_url_to_base64
    return _process_image_response(response, url)
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 21, in _process_image_response
    raise litellm.ImageFetchError(
        f"Error: Unable to fetch image from URL. Status code: {response.status_code}, url={url}"
    )
litellm.exceptions.ImageFetchError: litellm.BadRequestError: Error: Unable to fetch image from URL. Status code: 403, url=https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/litellm/main.py", line 620, in acompletion
    response = await init_response
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 2738, in async_completion
    request_body = await async_transform_request_body(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
    )  # type: ignore
    ^
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 875, in async_transform_request_body
    return _transform_request_body(
        messages=messages,
    ...<4 lines>...
        optional_params=optional_params,
    )
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 778, in _transform_request_body
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 702, in _transform_request_body
    content = litellm.GoogleAIStudioGeminiConfig()._transform_messages(
        messages=messages, model=model
    )
  File "/usr/lib/python3.13/site-packages/litellm/llms/gemini/chat/transformation.py", line 153, in _transform_messages
    return _gemini_convert_messages_with_history(messages=messages, model=model)
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 635, in _gemini_convert_messages_with_history
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 410, in _gemini_convert_messages_with_history
    raise Exception(
    ...<3 lines>...
    )
Exception: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format
. Received Model Group=gemini/gemini-2.5-flash-Promia
Available Model Group Fallbacks=None
Serialized Error: {
  status: 500,
  headers: {
    constructor: 'Function<Headers>',
    append: 'Function<append>',
    delete: 'Function<delete>',
    get: 'Function<get>',
    has: 'Function<has>',
    set: 'Function<set>',
    getSetCookie: 'Function<getSetCookie>',
    keys: 'Function<keys>',
    values: 'Function<values>',
    entries: 'Function<entries>',
    forEach: 'Function<forEach>'
  },
  requestID: null,
  error: {
    message: 'litellm.APIConnectionError: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format\n' +
      'Traceback (most recent call last):\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 401, in _gemini_convert_messages_with_history\n' +
      '    _part = _process_gemini_media(\n' +
      '        image_url=passed_file,\n' +
      '    ...<3 lines>...\n' +
      '        video_metadata=video_metadata,\n' +
      '    )\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 230, in _process_gemini_media\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 222, in _process_gemini_media\n' +
      '    image = convert_to_anthropic_image_obj(image_url, format=format)\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/factory.py", line 892, in convert_to_anthropic_image_obj\n' +
      '    openai_image_url = convert_url_to_base64(url=openai_image_url)\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 113, in convert_url_to_base64\n' +
      '    return _process_image_response(response, url)\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 21, in _process_image_response\n' +
      '    raise litellm.ImageFetchError(\n' +
      '        f"Error: Unable to fetch image from URL. Status code: {response.status_code}, url={url}"\n' +
      '    )\n' +
      'litellm.exceptions.ImageFetchError: litellm.BadRequestError: Error: Unable to fetch image from URL. Status code: 403, url=https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw\n' +
      '\n' +
      'During handling of the above exception, another exception occurred:\n' +
      '\n' +
      'Traceback (most recent call last):\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/main.py", line 620, in acompletion\n' +
      '    response = await init_response\n' +
      '               ^^^^^^^^^^^^^^^^^^^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 2738, in async_completion\n' +
      '    request_body = await async_transform_request_body(\n' +
      '                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n' +
      '    ...<4 lines>...\n' +
      '    )  # type: ignore\n' +
      '    ^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 875, in async_transform_request_body\n' +
      '    return _transform_request_body(\n' +
      '        messages=messages,\n' +
      '    ...<4 lines>...\n' +
      '        optional_params=optional_params,\n' +
      '    )\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 778, in _transform_request_body\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 702, in _transform_request_body\n' +
      '    content = litellm.GoogleAIStudioGeminiConfig()._transform_messages(\n' +
      '        messages=messages, model=model\n' +
      '    )\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/gemini/chat/transformation.py", line 153, in _transform_messages\n' +
      '    return _gemini_convert_messages_with_history(messages=messages, model=model)\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 635, in _gemini_convert_messages_with_history\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 410, in _gemini_convert_messages_with_history\n' +
      '    raise Exception(\n' +
      '    ...<3 lines>...\n' +
      '    )\n' +
      'Exception: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format\n' +
      '\n' +
      'During handling of the above exception, another exception occurred:\n' +
      '\n' +
      'Traceback (most recent call last):\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 5586, in async_function_with_retries\n' +
      '    response = await self.make_call(original_function, *args, **kwargs)\n' +
      '               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 5754, in make_call\n' +
      '    response = await response\n' +
      '               ^^^^^^^^^^^^^^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 3891, in _ageneric_api_call_with_fallbacks_helper\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 3877, in _ageneric_api_call_with_fallbacks_helper\n' +
      '    response = await response  # type: ignore\n' +
      '               ^^^^^^^^^^^^^^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 2094, in wrapper_async\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 1893, in wrapper_async\n' +
      '    result = await original_function(*args, **kwargs)\n' +
      '             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/responses/main.py", line 580, in aresponses\n' +
      '    raise litellm.exception_type(\n' +
      '    ...<5 lines>...\n' +
      '    )\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/responses/main.py", line 558, in aresponses\n' +
      '    response = await init_response\n' +
      '               ^^^^^^^^^^^^^^^^^^^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/responses/litellm_completion_transformation/handler.py", line 114, in async_response_api_handler\n' +
      '    ] = await litellm.acompletion(\n' +
      '        ^^^^^^^^^^^^^^^^^^^^^^^^^^\n' +
      '        **acompletion_args,\n' +
      '        ^^^^^^^^^^^^^^^^^^^\n' +
      '    )\n' +
      '    ^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 2094, in wrapper_async\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 1893, in wrapper_async\n' +
      '    result = await original_function(*args, **kwargs)\n' +
      '             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/main.py", line 639, in acompletion\n' +
      '    raise exception_type(\n' +
      '          ~~~~~~~~~~~~~~^\n' +
      '        model=model,\n' +
      '        ^^^^^^^^^^^^\n' +
      '    ...<3 lines>...\n' +
      '        extra_kwargs=kwargs,\n' +
      '        ^^^^^^^^^^^^^^^^^^^^\n' +
      '    )\n' +
      '    ^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2456, in exception_type\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2432, in exception_type\n' +
      '    raise APIConnectionError(\n' +
      '    ...<8 lines>...\n' +
      '    )\n' +
      'litellm.exceptions.APIConnectionError: litellm.APIConnectionError: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format\n' +
      'Traceback (most recent call last):\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 401, in _gemini_convert_messages_with_history\n' +
      '    _part = _process_gemini_media(\n' +
      '        image_url=passed_file,\n' +
      '    ...<3 lines>...\n' +
      '        video_metadata=video_metadata,\n' +
      '    )\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 230, in _process_gemini_media\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 222, in _process_gemini_media\n' +
      '    image = convert_to_anthropic_image_obj(image_url, format=format)\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/factory.py", line 892, in convert_to_anthropic_image_obj\n' +
      '    openai_image_url = convert_url_to_base64(url=openai_image_url)\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 113, in convert_url_to_base64\n' +
      '    return _process_image_response(response, url)\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 21, in _process_image_response\n' +
      '    raise litellm.ImageFetchError(\n' +
      '        f"Error: Unable to fetch image from URL. Status code: {response.status_code}, url={url}"\n' +
      '    )\n' +
      'litellm.exceptions.ImageFetchError: litellm.BadRequestError: Error: Unable to fetch image from URL. Status code: 403, url=https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw\n' +
      '\n' +
      'During handling of the above exception, another exception occurred:\n' +
      '\n' +
      'Traceback (most recent call last):\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/main.py", line 620, in acompletion\n' +
      '    response = await init_response\n' +
      '               ^^^^^^^^^^^^^^^^^^^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 2738, in async_completion\n' +
      '    request_body = await async_transform_request_body(\n' +
      '                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n' +
      '    ...<4 lines>...\n' +
      '    )  # type: ignore\n' +
      '    ^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 875, in async_transform_request_body\n' +
      '    return _transform_request_body(\n' +
      '        messages=messages,\n' +
      '    ...<4 lines>...\n' +
      '        optional_params=optional_params,\n' +
      '    )\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 778, in _transform_request_body\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 702, in _transform_request_body\n' +
      '    content = litellm.GoogleAIStudioGeminiConfig()._transform_messages(\n' +
      '        messages=messages, model=model\n' +
      '    )\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/gemini/chat/transformation.py", line 153, in _transform_messages\n' +
      '    return _gemini_convert_messages_with_history(messages=messages, model=model)\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 635, in _gemini_convert_messages_with_history\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 410, in _gemini_convert_messages_with_history\n' +
      '    raise Exception(\n' +
      '    ...<3 lines>...\n' +
      '    )\n' +
      'Exception: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format\n' +
      '\n' +
      '\n' +
      'During handling of the above excepti'... 3579 more characters,
    type: null,
    param: null,
    code: '500'
  },
  code: '500',
  param: null
}
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/37eh7rsw1vfe, set this explicitly using message[0].content[1].file.format

That's because in this code https://github.com/BerriAI/litellm/blob/33c3f13443eaf990ac8c6e3da78bddbc2b7d0e7a/litellm/llms/vertex_ai/gemini/transformation.py#L211-L227

the Gemini URI starts with https so it fails in the last elif but it can't get a mime type from that URI because It's not directly a file. So it fails with a 403.

A fix could be that, but I'm not python developer or understand completely LiteLLM files. It works for me on non img files:

        elif (
            "https://generativelanguage.googleapis.com/v1beta/files" in image_url
        ):
            file_data = FileDataType(file_uri=image_url)
            part = {"file_data": file_data}
            return _apply_gemini_3_metadata(
                part, model, media_resolution_enum, video_metadata
            )
        elif (
            "https://" in image_url
            and (image_type := format or _get_image_mime_type_from_url(image_url))
            is not None
        ):
            file_data = FileDataType(mime_type=image_type, file_uri=image_url)
            part = {"file_data": file_data}
            return _apply_gemini_3_metadata(
                part, model, media_resolution_enum, video_metadata
            )
        elif "http://" in image_url or "https://" in image_url or "base64" in image_url:
            image = convert_to_anthropic_image_obj(image_url, format=format)
            _blob: BlobType = {"data": image["data"], "mime_type": image["media_type"]}
            part = {"inline_data": cast(BlobType, _blob)}
            return _apply_gemini_3_metadata(
                part, model, media_resolution_enum, video_metadata
            )

Steps to Reproduce

  1. Upload a file (a TXT) to Gemini (I do with LiteLLM files API)
  2. try to use in responses API

Relevant log output

Error: 500 litellm.APIConnectionError: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format
Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 401, in _gemini_convert_messages_with_history
    _part = _process_gemini_media(
        image_url=passed_file,
    ...<3 lines>...
        video_metadata=video_metadata,
    )
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 230, in _process_gemini_media
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 222, in _process_gemini_media
    image = convert_to_anthropic_image_obj(image_url, format=format)
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/factory.py", line 892, in convert_to_anthropic_image_obj
    openai_image_url = convert_url_to_base64(url=openai_image_url)
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 113, in convert_url_to_base64
    return _process_image_response(response, url)
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 21, in _process_image_response
    raise litellm.ImageFetchError(
        f"Error: Unable to fetch image from URL. Status code: {response.status_code}, url={url}"
    )
litellm.exceptions.ImageFetchError: litellm.BadRequestError: Error: Unable to fetch image from URL. Status code: 403, url=https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/litellm/main.py", line 620, in acompletion
    response = await init_response
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 2738, in async_completion
    request_body = await async_transform_request_body(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
    )  # type: ignore
    ^
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 875, in async_transform_request_body
    return _transform_request_body(
        messages=messages,
    ...<4 lines>...
        optional_params=optional_params,
    )
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 778, in _transform_request_body
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 702, in _transform_request_body
    content = litellm.GoogleAIStudioGeminiConfig()._transform_messages(
        messages=messages, model=model
    )
  File "/usr/lib/python3.13/site-packages/litellm/llms/gemini/chat/transformation.py", line 153, in _transform_messages
    return _gemini_convert_messages_with_history(messages=messages, model=model)
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 635, in _gemini_convert_messages_with_history
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 410, in _gemini_convert_messages_with_history
    raise Exception(
    ...<3 lines>...
    )
Exception: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 5586, in async_function_with_retries
    response = await self.make_call(original_function, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 5754, in make_call
    response = await response
               ^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 3891, in _ageneric_api_call_with_fallbacks_helper
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 3877, in _ageneric_api_call_with_fallbacks_helper
    response = await response  # type: ignore
               ^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 2094, in wrapper_async
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 1893, in wrapper_async
    result = await original_function(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/responses/main.py", line 580, in aresponses
    raise litellm.exception_type(
    ...<5 lines>...
    )
  File "/usr/lib/python3.13/site-packages/litellm/responses/main.py", line 558, in aresponses
    response = await init_response
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/responses/litellm_completion_transformation/handler.py", line 114, in async_response_api_handler
    ] = await litellm.acompletion(
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
        **acompletion_args,
        ^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 2094, in wrapper_async
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 1893, in wrapper_async
    result = await original_function(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/main.py", line 639, in acompletion
    raise exception_type(
          ~~~~~~~~~~~~~~^
        model=model,
        ^^^^^^^^^^^^
    ...<3 lines>...
        extra_kwargs=kwargs,
        ^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2456, in exception_type
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2432, in exception_type
    raise APIConnectionError(
    ...<8 lines>...
    )
litellm.exceptions.APIConnectionError: litellm.APIConnectionError: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format
Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 401, in _gemini_convert_messages_with_history
    _part = _process_gemini_media(
        image_url=passed_file,
    ...<3 lines>...
        video_metadata=video_metadata,
    )
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 230, in _process_gemini_media
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 222, in _process_gemini_media
    image = convert_to_anthropic_image_obj(image_url, format=format)
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/factory.py", line 892, in convert_to_anthropic_image_obj
    openai_image_url = convert_url_to_base64(url=openai_image_url)
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 113, in convert_url_to_base64
    return _process_image_response(response, url)
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 21, in _process_image_response
    raise litellm.ImageFetchError(
        f"Error: Unable to fetch image from URL. Status code: {response.status_code}, url={url}"
    )
litellm.exceptions.ImageFetchError: litellm.BadRequestError: Error: Unable to fetch image from URL. Status code: 403, url=https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/litellm/main.py", line 620, in acompletion
    response = await init_response
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 2738, in async_completion
    request_body = await async_transform_request_body(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
    )  # type: ignore
    ^
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 875, in async_transform_request_body
    return _transform_request_body(
        messages=messages,
    ...<4 lines>...
        optional_params=optional_params,
    )
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 778, in _transform_request_body
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 702, in _transform_request_body
    content = litellm.GoogleAIStudioGeminiConfig()._transform_messages(
        messages=messages, model=model
    )
  File "/usr/lib/python3.13/site-packages/litellm/llms/gemini/chat/transformation.py", line 153, in _transform_messages
    return _gemini_convert_messages_with_history(messages=messages, model=model)
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 635, in _gemini_convert_messages_with_history
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 410, in _gemini_convert_messages_with_history
    raise Exception(
    ...<3 lines>...
    )
Exception: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 401, in _gemini_convert_messages_with_history
    _part = _process_gemini_media(
        image_url=passed_file,
    ...<3 lines>...
        video_metadata=video_metadata,
    )
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 230, in _process_gemini_media
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 222, in _process_gemini_media
    image = convert_to_anthropic_image_obj(image_url, format=format)
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/factory.py", line 892, in convert_to_anthropic_image_obj
    openai_image_url = convert_url_to_base64(url=openai_image_url)
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 113, in convert_url_to_base64
    return _process_image_response(response, url)
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 21, in _process_image_response
    raise litellm.ImageFetchError(
        f"Error: Unable to fetch image from URL. Status code: {response.status_code}, url={url}"
    )
litellm.exceptions.ImageFetchError: litellm.BadRequestError: Error: Unable to fetch image from URL. Status code: 403, url=https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/litellm/main.py", line 620, in acompletion
    response = await init_response
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 2738, in async_completion
    request_body = await async_transform_request_body(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
    )  # type: ignore
    ^
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 875, in async_transform_request_body
    return _transform_request_body(
        messages=messages,
    ...<4 lines>...
        optional_params=optional_params,
    )
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 778, in _transform_request_body
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 702, in _transform_request_body
    content = litellm.GoogleAIStudioGeminiConfig()._transform_messages(
        messages=messages, model=model
    )
  File "/usr/lib/python3.13/site-packages/litellm/llms/gemini/chat/transformation.py", line 153, in _transform_messages
    return _gemini_convert_messages_with_history(messages=messages, model=model)
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 635, in _gemini_convert_messages_with_history
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 410, in _gemini_convert_messages_with_history
    raise Exception(
    ...<3 lines>...
    )
Exception: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format
. Received Model Group=gemini/gemini-2.5-flash-Promia
Available Model Group Fallbacks=None
Serialized Error: {
  status: 500,
  headers: {
    constructor: 'Function<Headers>',
    append: 'Function<append>',
    delete: 'Function<delete>',
    get: 'Function<get>',
    has: 'Function<has>',
    set: 'Function<set>',
    getSetCookie: 'Function<getSetCookie>',
    keys: 'Function<keys>',
    values: 'Function<values>',
    entries: 'Function<entries>',
    forEach: 'Function<forEach>'
  },
  requestID: null,
  error: {
    message: 'litellm.APIConnectionError: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format\n' +
      'Traceback (most recent call last):\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 401, in _gemini_convert_messages_with_history\n' +
      '    _part = _process_gemini_media(\n' +
      '        image_url=passed_file,\n' +
      '    ...<3 lines>...\n' +
      '        video_metadata=video_metadata,\n' +
      '    )\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 230, in _process_gemini_media\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 222, in _process_gemini_media\n' +
      '    image = convert_to_anthropic_image_obj(image_url, format=format)\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/factory.py", line 892, in convert_to_anthropic_image_obj\n' +
      '    openai_image_url = convert_url_to_base64(url=openai_image_url)\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 113, in convert_url_to_base64\n' +
      '    return _process_image_response(response, url)\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 21, in _process_image_response\n' +
      '    raise litellm.ImageFetchError(\n' +
      '        f"Error: Unable to fetch image from URL. Status code: {response.status_code}, url={url}"\n' +
      '    )\n' +
      'litellm.exceptions.ImageFetchError: litellm.BadRequestError: Error: Unable to fetch image from URL. Status code: 403, url=https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw\n' +
      '\n' +
      'During handling of the above exception, another exception occurred:\n' +
      '\n' +
      'Traceback (most recent call last):\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/main.py", line 620, in acompletion\n' +
      '    response = await init_response\n' +
      '               ^^^^^^^^^^^^^^^^^^^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 2738, in async_completion\n' +
      '    request_body = await async_transform_request_body(\n' +
      '                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n' +
      '    ...<4 lines>...\n' +
      '    )  # type: ignore\n' +
      '    ^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 875, in async_transform_request_body\n' +
      '    return _transform_request_body(\n' +
      '        messages=messages,\n' +
      '    ...<4 lines>...\n' +
      '        optional_params=optional_params,\n' +
      '    )\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 778, in _transform_request_body\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 702, in _transform_request_body\n' +
      '    content = litellm.GoogleAIStudioGeminiConfig()._transform_messages(\n' +
      '        messages=messages, model=model\n' +
      '    )\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/gemini/chat/transformation.py", line 153, in _transform_messages\n' +
      '    return _gemini_convert_messages_with_history(messages=messages, model=model)\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 635, in _gemini_convert_messages_with_history\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 410, in _gemini_convert_messages_with_history\n' +
      '    raise Exception(\n' +
      '    ...<3 lines>...\n' +
      '    )\n' +
      'Exception: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format\n' +
      '\n' +
      'During handling of the above exception, another exception occurred:\n' +
      '\n' +
      'Traceback (most recent call last):\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 5586, in async_function_with_retries\n' +
      '    response = await self.make_call(original_function, *args, **kwargs)\n' +
      '               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 5754, in make_call\n' +
      '    response = await response\n' +
      '               ^^^^^^^^^^^^^^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 3891, in _ageneric_api_call_with_fallbacks_helper\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 3877, in _ageneric_api_call_with_fallbacks_helper\n' +
      '    response = await response  # type: ignore\n' +
      '               ^^^^^^^^^^^^^^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 2094, in wrapper_async\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 1893, in wrapper_async\n' +
      '    result = await original_function(*args, **kwargs)\n' +
      '             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/responses/main.py", line 580, in aresponses\n' +
      '    raise litellm.exception_type(\n' +
      '    ...<5 lines>...\n' +
      '    )\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/responses/main.py", line 558, in aresponses\n' +
      '    response = await init_response\n' +
      '               ^^^^^^^^^^^^^^^^^^^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/responses/litellm_completion_transformation/handler.py", line 114, in async_response_api_handler\n' +
      '    ] = await litellm.acompletion(\n' +
      '        ^^^^^^^^^^^^^^^^^^^^^^^^^^\n' +
      '        **acompletion_args,\n' +
      '        ^^^^^^^^^^^^^^^^^^^\n' +
      '    )\n' +
      '    ^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 2094, in wrapper_async\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 1893, in wrapper_async\n' +
      '    result = await original_function(*args, **kwargs)\n' +
      '             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/main.py", line 639, in acompletion\n' +
      '    raise exception_type(\n' +
      '          ~~~~~~~~~~~~~~^\n' +
      '        model=model,\n' +
      '        ^^^^^^^^^^^^\n' +
      '    ...<3 lines>...\n' +
      '        extra_kwargs=kwargs,\n' +
      '        ^^^^^^^^^^^^^^^^^^^^\n' +
      '    )\n' +
      '    ^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2456, in exception_type\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2432, in exception_type\n' +
      '    raise APIConnectionError(\n' +
      '    ...<8 lines>...\n' +
      '    )\n' +
      'litellm.exceptions.APIConnectionError: litellm.APIConnectionError: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format\n' +
      'Traceback (most recent call last):\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 401, in _gemini_convert_messages_with_history\n' +
      '    _part = _process_gemini_media(\n' +
      '        image_url=passed_file,\n' +
      '    ...<3 lines>...\n' +
      '        video_metadata=video_metadata,\n' +
      '    )\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 230, in _process_gemini_media\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 222, in _process_gemini_media\n' +
      '    image = convert_to_anthropic_image_obj(image_url, format=format)\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/factory.py", line 892, in convert_to_anthropic_image_obj\n' +
      '    openai_image_url = convert_url_to_base64(url=openai_image_url)\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 113, in convert_url_to_base64\n' +
      '    return _process_image_response(response, url)\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/prompt_templates/image_handling.py", line 21, in _process_image_response\n' +
      '    raise litellm.ImageFetchError(\n' +
      '        f"Error: Unable to fetch image from URL. Status code: {response.status_code}, url={url}"\n' +
      '    )\n' +
      'litellm.exceptions.ImageFetchError: litellm.BadRequestError: Error: Unable to fetch image from URL. Status code: 403, url=https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw\n' +
      '\n' +
      'During handling of the above exception, another exception occurred:\n' +
      '\n' +
      'Traceback (most recent call last):\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/main.py", line 620, in acompletion\n' +
      '    response = await init_response\n' +
      '               ^^^^^^^^^^^^^^^^^^^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 2738, in async_completion\n' +
      '    request_body = await async_transform_request_body(\n' +
      '                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n' +
      '    ...<4 lines>...\n' +
      '    )  # type: ignore\n' +
      '    ^\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 875, in async_transform_request_body\n' +
      '    return _transform_request_body(\n' +
      '        messages=messages,\n' +
      '    ...<4 lines>...\n' +
      '        optional_params=optional_params,\n' +
      '    )\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 778, in _transform_request_body\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 702, in _transform_request_body\n' +
      '    content = litellm.GoogleAIStudioGeminiConfig()._transform_messages(\n' +
      '        messages=messages, model=model\n' +
      '    )\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/gemini/chat/transformation.py", line 153, in _transform_messages\n' +
      '    return _gemini_convert_messages_with_history(messages=messages, model=model)\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 635, in _gemini_convert_messages_with_history\n' +
      '    raise e\n' +
      '  File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/transformation.py", line 410, in _gemini_convert_messages_with_history\n' +
      '    raise Exception(\n' +
      '    ...<3 lines>...\n' +
      '    )\n' +
      'Exception: Unable to determine mime type for file_id: https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw, set this explicitly using message[0].content[1].file.format\n' +
      '\n' +
      '\n' +
      'During handling of the above excepti'... 3579 more characters,
    type: null,
    param: null,
    code: '500'
  },
  code: '500',
  param: null
}

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

v1.82.3

Twitter / LinkedIn details

No response

extent analysis

TL;DR

The issue can be resolved by setting the mime type explicitly for the file_id in the message content.

Guidance

  1. Identify the file_id: Locate the file_id in the error message, which is https://generativelanguage.googleapis.com/v1beta/files/n1vhxa28lyaw.
  2. Set the mime type: Set the mime type explicitly using message[0].content[1].file.format for the identified file_id.
  3. Check the file type: Verify the type of file being uploaded (e.g., TXT) to ensure the correct mime type is set.
  4. Review the code: Examine the code in transformation.py to understand how mime types are handled for different file types and URLs.

Example

No code example is provided as the issue is related to setting a specific value (mime type) rather than modifying code.

Notes

  • The error message suggests a 403 status code, indicating a permission issue, but the primary problem seems to be the inability to determine the mime type.
  • The solution involves setting the mime type explicitly, which might require adjustments based on the specific file types being handled.

Recommendation

Apply the workaround by setting the mime type explicitly for the file_id in the message content, as this directly addresses the error message's suggestion.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING