Skip to content

Invalid request leads to 500 error instead of 400 #252

@adubovik

Description

@adubovik

The error is reproducible for deployments declared in GPT4O_DEPLOYMENTS:

Request:

curl http://localhost:5006/openai/deployments/gpt-4o/chat/completions \
  -H "Content-Type: application/json" \
  -H "api-key:dummy" \
  -H "X-UPSTREAM-ENDPOINT:http://localhost:5007/openai/deployments/gpt-4o/chat/completions" \
  -H "X-UPSTREAM-KEY:dummy" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "What is in this image?"
          },
          {
            "type": "image_url",
            "image_url": "https://en.wikipedia.org/static/images/icons/wikipedia.png"
          }
        ]
      }
    ]
  }'

Response:

< HTTP/1.1 500 Internal Server Error
< date: Mon, 21 Jul 2025 12:35:34 GMT
< server: uvicorn
< content-length: 21
< content-type: text/plain; charset=utf-8
< 
* Connection #0 to host localhost left intact
Internal Server Error

Stack trace:

  File "aidial_adapter_openai/endpoints/chat_completion.py", line 174, in chat_completion
    await call_chat_completion(
  File "aidial_adapter_openai/endpoints/chat_completion.py", line 130, in call_chat_completion
    return await gpt4o_chat_completion(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "aidial_adapter_openai/gpt4_multi_modal/chat_completion.py", line 102, in gpt4o_chat_completion
    transform_result = await ResourceProcessor(
                       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "aidial_adapter_openai/gpt4_multi_modal/transformation.py", line 150, in transform_messages
    transformations = [
                      ^
  File "aidial_adapter_openai/gpt4_multi_modal/transformation.py", line 151, in <listcomp>
    await self.transform_message(message) for message in messages
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "aidial_adapter_openai/gpt4_multi_modal/transformation.py", line 127, in transform_message
    content_meta = await self.download_content_images(content)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "aidial_adapter_openai/gpt4_multi_modal/transformation.py", line 104, in download_content_images
    if image_url and (url := image_url.get("url")):
                             ^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'get'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions