Check for existing issues
What happened?
Type:
APIConnectionError
Message:
litellm.APIConnectionError: APIConnectionError: OpenrouterException - Invalid response object Traceback (most recent call last):
File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/llm_response_utils/convert_dict_to_response.py", line 560, in convert_to_model_response_object
message = Message(
content=content,
...<8 lines>...
images=choice["message"].get("images", None),
)
File "/usr/lib/python3.13/site-packages/litellm/types/utils.py", line 1107, in init
super(Message, self).init(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
**init_values, # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
**params,
^^^^^^^^^
)
^
File "/usr/lib/python3.13/site-packages/pydantic/main.py", line 250, in init
validated_self = self.pydantic_validator.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 2 validation errors for Message
images.0.index
Field required [type=missing, input_value={'type': 'image_url', 'im...ukbpp6K973uumzdn/AP/Z'}}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.12/v/missing
images.1.index
Field required [type=missing, input_value={'type': 'image_url', 'im...tYaNPS/LdNbJO6bf4n//Z'}}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.12/v/missing
Steps to Reproduce
from litellm import completion
import json
import logging
logging.getLogger("litellm").setLevel(logging.ERROR)
try:
response = completion(
model="openrouter/google/gemini-3-pro-image-preview",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "Generate a bird image."},
],
}
],
api_key="your-openrouter-api-key",
)
with open("full_response.json", "w", encoding="utf-8") as f:
json.dump(dict(response), f, ensure_ascii=False, indent=2)
print("✅ Response successfully written to full_response.json")
except Exception as e:
with open("error_log.json", "w", encoding="utf-8") as f:
json.dump({"error": str(e)}, f, ensure_ascii=False, indent=2)
print("❌ API call failed, error has been written to error_log.json")
Relevant log output
[{
'images': [{
'type': 'image_url',
'image_url': {
'url': 'data:image/png;base64,iVBORw0KGgoA...'
}
}]
}]
{
"error": "litellm.APIConnectionError: APIConnectionError: OpenrouterException - Invalid response object Traceback (most recent call last):\n File \"C:\\Users\\ThinkPad\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python313\\site-packages\\litellm\\litellm_core_utils\\llm_response_utils\\convert_dict_to_response.py\", line 584, in convert_to_model_response_object\n message = Message(\n content=content,\n ...<8 lines>...\n images=choice[\"message\"].get(\"images\", None),\n )\n File \"C:\\Users\\ThinkPad\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python313\\site-packages\\litellm\\types\\utils.py\", line 1125, in __init__\n super(Message, self).__init__(\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^\n **init_values, # type: ignore\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n **params,\n ^^^^^^^^^\n )\n ^\n File \"C:\\Users\\ThinkPad\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python313\\site-packages\\pydantic\\main.py\", line 250, in __init__\n validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)\npydantic_core._pydantic_core.ValidationError: 1 validation error for Message\nimages.0.index\n Field required [type=missing, input_value={'type': 'image_url', 'im...pdB0AAAAASUVORK5CYII='}}, input_type=dict]\n For further information visit https://errors.pydantic.dev/2.12/v/missing\n\n\nreceived_args={'response_object': {'id': 'gen-1772527679-ZcJCdkOMprXPs7J8rCGS', 'object': 'chat.completion', 'created': 1772527679, 'model': 'google/gemini-3-pro-image-preview-20251120', 'provider': 'Google', 'choices': [{'index': 0, 'logprobs': None, 'finish_reason': 'stop', 'native_finish_reason': 'STOP', 'message': {'role': 'assistant', 'content': 'I hope you like this kingfisher!', 'refusal': None, 'reasoning': \"**Contemplating Avian Imagery**\\n\\nI'm focusing on crafting a visual narrative around a bird. My initial thought was quite general, so I'm narrowing it. I'm choosing a Kingfisher for its vibrant colors, and I'm already considering the bird's environment, actions, and artistic style to make the image engaging.\\n\\n\\n**Narrowing the Focus**\\n\\nI've selected the Kingfisher as the subject, settling on a riverbank environment. Now I'm refining the bird's action, I'm imagining it perched and hunting for fish. Considering a hyper-realistic photographic style to highlight the scene's details.\\n\\n\\n**Defining Visual Parameters**\\n\\nI've narrowed the focus to a realistic photograph of a kingfisher. The initial prompt was broad, so I aimed for something visually appealing. The setting will be a detailed natural environment.\\n\\n\\n**Co
What part of LiteLLM is this about?
SDK (litellm Python package)
What LiteLLM version are you on ?
v1.82.0
Twitter / LinkedIn details
No response
Check for existing issues
What happened?
Type:
APIConnectionError
Message:
litellm.APIConnectionError: APIConnectionError: OpenrouterException - Invalid response object Traceback (most recent call last):
File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/llm_response_utils/convert_dict_to_response.py", line 560, in convert_to_model_response_object
message = Message(
content=content,
...<8 lines>...
images=choice["message"].get("images", None),
)
File "/usr/lib/python3.13/site-packages/litellm/types/utils.py", line 1107, in init
super(Message, self).init(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
**init_values, # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
**params,
^^^^^^^^^
)
^
File "/usr/lib/python3.13/site-packages/pydantic/main.py", line 250, in init
validated_self = self.pydantic_validator.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 2 validation errors for Message
images.0.index
Field required [type=missing, input_value={'type': 'image_url', 'im...ukbpp6K973uumzdn/AP/Z'}}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.12/v/missing
images.1.index
Field required [type=missing, input_value={'type': 'image_url', 'im...tYaNPS/LdNbJO6bf4n//Z'}}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.12/v/missing
Steps to Reproduce
from litellm import completion
import json
import logging
logging.getLogger("litellm").setLevel(logging.ERROR)
try:
response = completion(
model="openrouter/google/gemini-3-pro-image-preview",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "Generate a bird image."},
],
}
],
api_key="your-openrouter-api-key",
)
except Exception as e:
with open("error_log.json", "w", encoding="utf-8") as f:
json.dump({"error": str(e)}, f, ensure_ascii=False, indent=2)
print("❌ API call failed, error has been written to error_log.json")
Relevant log output
[{ 'images': [{ 'type': 'image_url', 'image_url': { 'url': 'data:image/png;base64,iVBORw0KGgoA...' } }] }] { "error": "litellm.APIConnectionError: APIConnectionError: OpenrouterException - Invalid response object Traceback (most recent call last):\n File \"C:\\Users\\ThinkPad\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python313\\site-packages\\litellm\\litellm_core_utils\\llm_response_utils\\convert_dict_to_response.py\", line 584, in convert_to_model_response_object\n message = Message(\n content=content,\n ...<8 lines>...\n images=choice[\"message\"].get(\"images\", None),\n )\n File \"C:\\Users\\ThinkPad\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python313\\site-packages\\litellm\\types\\utils.py\", line 1125, in __init__\n super(Message, self).__init__(\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^\n **init_values, # type: ignore\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n **params,\n ^^^^^^^^^\n )\n ^\n File \"C:\\Users\\ThinkPad\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python313\\site-packages\\pydantic\\main.py\", line 250, in __init__\n validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)\npydantic_core._pydantic_core.ValidationError: 1 validation error for Message\nimages.0.index\n Field required [type=missing, input_value={'type': 'image_url', 'im...pdB0AAAAASUVORK5CYII='}}, input_type=dict]\n For further information visit https://errors.pydantic.dev/2.12/v/missing\n\n\nreceived_args={'response_object': {'id': 'gen-1772527679-ZcJCdkOMprXPs7J8rCGS', 'object': 'chat.completion', 'created': 1772527679, 'model': 'google/gemini-3-pro-image-preview-20251120', 'provider': 'Google', 'choices': [{'index': 0, 'logprobs': None, 'finish_reason': 'stop', 'native_finish_reason': 'STOP', 'message': {'role': 'assistant', 'content': 'I hope you like this kingfisher!', 'refusal': None, 'reasoning': \"**Contemplating Avian Imagery**\\n\\nI'm focusing on crafting a visual narrative around a bird. My initial thought was quite general, so I'm narrowing it. I'm choosing a Kingfisher for its vibrant colors, and I'm already considering the bird's environment, actions, and artistic style to make the image engaging.\\n\\n\\n**Narrowing the Focus**\\n\\nI've selected the Kingfisher as the subject, settling on a riverbank environment. Now I'm refining the bird's action, I'm imagining it perched and hunting for fish. Considering a hyper-realistic photographic style to highlight the scene's details.\\n\\n\\n**Defining Visual Parameters**\\n\\nI've narrowed the focus to a realistic photograph of a kingfisher. The initial prompt was broad, so I aimed for something visually appealing. The setting will be a detailed natural environment.\\n\\n\\n**CoWhat part of LiteLLM is this about?
SDK (litellm Python package)
What LiteLLM version are you on ?
v1.82.0
Twitter / LinkedIn details
No response