[GH-ISSUE #6514] OpenAI-compatible API: content as array causes crash (error 500) #14392

Closed
opened 2026-04-19 20:46:13 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @dguembel-itomig on GitHub (Oct 28, 2024).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/6514


Installation Method

Docker

Environment

  • Open WebUI Version: v0.3.35

  • Ollama (if applicable): 0.3.14

  • Operating System: Ubuntu 22.04.5 LTS

  • Browser (if applicable): (does not matter here)

Confirmation:

  • I have read and followed all the instructions provided in the README.md.
  • I am on the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • I have included the Docker container logs.
  • I have provided the exact steps to reproduce the bug in the "Steps to Reproduce" section below.

Expected Behavior:

The follwing JSON is a valid request to the OpenAI API, with the `content" being an array. This is valid as per the OpenAI API doc: https://platform.openai.com/docs/api-reference/chat/create and even supported according to ollama: https://github.com/ollama/ollama/blob/main/docs/openai.md ("Supported request fields": "Array of content parts")

{ "top_p": 1, "frequency_penalty": 0, "messages": [ { "role": "system", "content": "Du bist ein hilfreicher Assistent." }, { "role": "user", "content": [ { "type": "text", "text": "Wer ist Emmanuel Macron" } ] } ], "temperature": 1, "presence_penalty": 0, "stream": false, "model": "llama3.2:latest" }

Changing the request to content being plain text (not an array) as follows returns a valid response from the server:

{ "top_p": 1, "frequency_penalty": 0, "messages": [ { "role": "system", "content": "Du bist ein hilfreicher Assistent." }, { "role": "user", "content": "Wer ist Emmanuel Macron" } ], "temperature": 1, "presence_penalty": 0, "stream": false, "model": "llama3.2:latest" }

Actual Behavior:

Crash with error 500.

Description

The OpenAI API allows for the "content" element to be either a string/text or an array[1]. If the latter is used, it crashes open-webui.
[1] https://platform.openai.com/docs/api-reference/chat/create

Reproduction Details

Steps to Reproduce:
Send HTTP request to https://<your-webui-instance>/v1/chat/completions as detailed before. Observe error 500.

Logs and Screenshots

Browser Console Logs:
N/A

Docker Container Logs:
Open-WebUI docker container log entry:
INFO: 172.19.0.1:49182 - "POST /ollama/v1/chat/completions HTTP/1.0" 500 Internal Server Error

Ollama docker image logs show nothing, request seems not to reach it.

Screenshots/Screen Recordings (if applicable):
N/A

Additional Information

Happy to provide whatever might be desired, but I think the issue is clearly described :)

Originally created by @dguembel-itomig on GitHub (Oct 28, 2024). Original GitHub issue: https://github.com/open-webui/open-webui/issues/6514 --- ## Installation Method Docker ## Environment - **Open WebUI Version:** v0.3.35 - **Ollama (if applicable):** 0.3.14 - **Operating System:** Ubuntu 22.04.5 LTS - **Browser (if applicable):** (does not matter here) **Confirmation:** - [X] I have read and followed all the instructions provided in the README.md. - [X] I am on the latest version of both Open WebUI and Ollama. - [X] I have included the browser console logs. - [X] I have included the Docker container logs. - [X] I have provided the exact steps to reproduce the bug in the "Steps to Reproduce" section below. ## Expected Behavior: The follwing JSON is a valid request to the OpenAI API, with the `content" being an array. This is valid as per the OpenAI API doc: https://platform.openai.com/docs/api-reference/chat/create and even supported according to ollama: https://github.com/ollama/ollama/blob/main/docs/openai.md ("Supported request fields": "Array of content parts") `{ "top_p": 1, "frequency_penalty": 0, "messages": [ { "role": "system", "content": "Du bist ein hilfreicher Assistent." }, { "role": "user", "content": [ { "type": "text", "text": "Wer ist Emmanuel Macron" } ] } ], "temperature": 1, "presence_penalty": 0, "stream": false, "model": "llama3.2:latest" }` Changing the request to `content` being plain text (not an array) as follows returns a valid response from the server: `{ "top_p": 1, "frequency_penalty": 0, "messages": [ { "role": "system", "content": "Du bist ein hilfreicher Assistent." }, { "role": "user", "content": "Wer ist Emmanuel Macron" } ], "temperature": 1, "presence_penalty": 0, "stream": false, "model": "llama3.2:latest" }` ## Actual Behavior: Crash with error 500. ## Description The OpenAI API allows for the "content" element to be either a string/text or an array[1]. If the latter is used, it crashes open-webui. [1] https://platform.openai.com/docs/api-reference/chat/create ## Reproduction Details **Steps to Reproduce:** Send HTTP request to `https://<your-webui-instance>/v1/chat/completions` as detailed before. Observe error 500. ## Logs and Screenshots **Browser Console Logs:** N/A **Docker Container Logs:** Open-WebUI docker container log entry: `INFO: 172.19.0.1:49182 - "POST /ollama/v1/chat/completions HTTP/1.0" 500 Internal Server Error ` Ollama docker image logs show nothing, request seems not to reach it. **Screenshots/Screen Recordings (if applicable):** N/A ## Additional Information Happy to provide whatever might be desired, but I think the issue is clearly described :)
Author
Owner

@tjbck commented on GitHub (Oct 28, 2024):

PR welcome!

<!-- gh-comment-id:2442430288 --> @tjbck commented on GitHub (Oct 28, 2024): PR welcome!
Author
Owner

@dguembel-itomig commented on GitHub (Oct 29, 2024):

I had a look at the code. I think all is missing would be

# If content is a single dict, convert it to a list
if isinstance(content, dict):
    content = [content]

In Line 108 of /backend/open_webui/utils/payload.py

That should ensure the code is always working with a list even if the content has only one element (one-element list).

Does that sound about right?-)

<!-- gh-comment-id:2443270692 --> @dguembel-itomig commented on GitHub (Oct 29, 2024): I had a look at the code. I think all is missing would be ``` # If content is a single dict, convert it to a list if isinstance(content, dict): content = [content] ``` In Line 108 of `/backend/open_webui/utils/payload.py` That should ensure the code is always working with a list even if the `content` has only one element (one-element list). Does that sound about right?-)
Author
Owner

@tjbck commented on GitHub (Nov 3, 2024):

Fixed on dev!

<!-- gh-comment-id:2453359924 --> @tjbck commented on GitHub (Nov 3, 2024): Fixed on dev!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#14392