[GH-ISSUE #24564] bug: API calls to /api/chat/completions fail: "'NoneType' object has no attribute 'startswith'" #91075

Closed
opened 2026-05-15 16:21:01 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @da-astro on GitHub (May 11, 2026).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/24564

Check Existing Issues

  • I have searched for any existing and/or related issues.
  • I have searched for any existing and/or related discussions.
  • I have also searched in the CLOSED issues AND CLOSED discussions and found no related items (your issue might already be addressed on the development branch!).
  • I am using the latest version of Open WebUI.

Installation Method

Docker

Open WebUI Version

main branch, image pulled 2026-05-10 (commit 3660bc00fd)

Ollama Version (if applicable)

0.23.2

Operating System

Ubuntu 24.04 LTS (server)

Browser (if applicable)

N/A — this is an API-only bug, no browser involved.

Confirmation

  • I have read and followed all instructions in README.md.
  • I am using 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 every relevant configuration, setting, and environment variable used in my setup.
  • I have clearly listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc).
  • I have documented step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation. My steps:
  • Start with the initial platform/version/OS and dependencies used,
  • Specify exact install/launch/configure commands,
  • List URLs visited, user input (incl. example values/emails/passwords if needed),
  • Describe all options and toggles enabled or changed,
  • Include any files or environmental changes,
  • Identify the expected and actual result at each stage,
  • Ensure any reasonably skilled user can follow and hit the same issue.

Expected Behavior

API requests to /api/chat/completions should return a successful chat completion response, as documented at https://docs.openwebui.com/reference/api-endpoints.

Actual Behavior

Every API request to /api/chat/completions returns HTTP 400 with:

{"detail":"'NoneType' object has no attribute 'startswith'"}

This affects all models (Ollama and OpenAI-compatible/Anthropic). The same models work correctly through the browser UI.

Steps to Reproduce

  1. Start with Ubuntu 24.04 server running Docker.
  2. Run Open WebUI via Docker:
    docker run -d -p 3000:8080 --name open-webui \
      -v open-webui:/app/backend/data \
      ghcr.io/open-webui/open-webui:main
    
  3. Connect Ollama (running on the host at port 11434) and/or an OpenAI-compatible API (e.g. Anthropic) via Admin Panel → Settings → Connections.
  4. Verify models work in the browser UI — send a message to any model and confirm a response.
  5. Enable API Keys in Admin Panel → Settings → General → Enable API Keys.
  6. Obtain a JWT token from the browser console:
    localStorage.getItem('token')
    
  7. Send an API request:
    curl -X POST http://localhost:3000/api/chat/completions \
      -H "Authorization: Bearer YOUR_JWT_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{"model":"llama3.2:latest","messages":[{"role":"user","content":"hi"}]}'
    
  8. Observe the response: {"detail":"'NoneType' object has no attribute 'startswith'"}

No environment variables, Docker Compose overrides, or custom settings were used beyond the steps above.

Logs & Screenshots

Docker container log at the moment of the failing request:

2026-05-11 04:32:59.469 | ERROR | open_webui.main:process_chat:2015 - Error processing chat payload: 'NoneType' object has no attribute 'startswith'
2026-05-11 04:32:59.469 | INFO  | uvicorn.protocols.http.httptools_impl:send:483 - 192.168.4.50:0 - "POST /api/chat/completions HTTP/1.1" 400

Full traceback (obtained by adding log.error('Full traceback: %s', traceback.format_exc()) to the error handler in main.py):

Traceback (most recent call last):
  File "/app/backend/open_webui/main.py", line 1977, in process_chat
    form_data, metadata, events = await process_chat_payload(request, form_data, user, metadata, model)
  File "/app/backend/open_webui/utils/middleware.py", line 2359, in process_chat_payload
    event_emitter = await get_event_emitter(metadata)
  File "/app/backend/open_webui/socket/main.py", line 902, in get_event_emitter
    if request_info.get('chat_id', '').startswith('channel:'):
AttributeError: 'NoneType' object has no attribute 'startswith'

Additional Information

Root cause

In open_webui/socket/main.py, line 902:

if request_info.get('chat_id', '').startswith('channel:'):

When called via the API (no browser chat session), metadata['chat_id'] is None. The .get('chat_id', '') call returns None rather than the default '' because the key exists in the dict with a None value — dict.get() only uses the default when the key is absent, not when its value is None.

Fix

Replace:

request_info.get('chat_id', '').startswith(...)

with:

(request_info.get('chat_id') or '').startswith(...)

The same pattern exists in multiple other places across the codebase and should be fixed everywhere:

  • open_webui/socket/main.py line 902 — primary crash site
  • open_webui/utils/middleware.py — ~11 instances of metadata['chat_id'].startswith(...) without a null guard
  • open_webui/main.py — 1 instance of metadata['chat_id'].startswith(...)

This bug makes the documented OpenAI-compatible API endpoint (/api/chat/completions) completely non-functional for any external client. The browser UI is unaffected because it always provides a chat_id via the WebSocket session.

Originally created by @da-astro on GitHub (May 11, 2026). Original GitHub issue: https://github.com/open-webui/open-webui/issues/24564 ### Check Existing Issues - [x] I have searched for any existing and/or related issues. - [x] I have searched for any existing and/or related discussions. - [x] I have also searched in the CLOSED issues AND CLOSED discussions and found no related items (your issue might already be addressed on the development branch!). - [x] I am using the latest version of Open WebUI. ### Installation Method Docker ### Open WebUI Version main branch, image pulled 2026-05-10 (commit 3660bc00fd807deced3400a63bfa6db47811a3bb) ### Ollama Version (if applicable) 0.23.2 ### Operating System Ubuntu 24.04 LTS (server) ### Browser (if applicable) N/A — this is an API-only bug, no browser involved. ### Confirmation - [x] I have read and followed all instructions in `README.md`. - [x] I am using 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 every relevant configuration, setting, and environment variable used in my setup.** - [x] I have clearly **listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup** (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc). - [x] I have documented **step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation**. My steps: - Start with the initial platform/version/OS and dependencies used, - Specify exact install/launch/configure commands, - List URLs visited, user input (incl. example values/emails/passwords if needed), - Describe all options and toggles enabled or changed, - Include any files or environmental changes, - Identify the expected and actual result at each stage, - Ensure any reasonably skilled user can follow and hit the same issue. ### Expected Behavior API requests to `/api/chat/completions` should return a successful chat completion response, as documented at https://docs.openwebui.com/reference/api-endpoints. ### Actual Behavior Every API request to `/api/chat/completions` returns HTTP 400 with: ```json {"detail":"'NoneType' object has no attribute 'startswith'"} ``` This affects all models (Ollama and OpenAI-compatible/Anthropic). The same models work correctly through the browser UI. ### Steps to Reproduce 1. Start with Ubuntu 24.04 server running Docker. 2. Run Open WebUI via Docker: ```bash docker run -d -p 3000:8080 --name open-webui \ -v open-webui:/app/backend/data \ ghcr.io/open-webui/open-webui:main ``` 3. Connect Ollama (running on the host at port 11434) and/or an OpenAI-compatible API (e.g. Anthropic) via Admin Panel → Settings → Connections. 4. Verify models work in the browser UI — send a message to any model and confirm a response. 5. Enable API Keys in Admin Panel → Settings → General → Enable API Keys. 6. Obtain a JWT token from the browser console: ```javascript localStorage.getItem('token') ``` 7. Send an API request: ```bash curl -X POST http://localhost:3000/api/chat/completions \ -H "Authorization: Bearer YOUR_JWT_TOKEN" \ -H "Content-Type: application/json" \ -d '{"model":"llama3.2:latest","messages":[{"role":"user","content":"hi"}]}' ``` 8. Observe the response: `{"detail":"'NoneType' object has no attribute 'startswith'"}` No environment variables, Docker Compose overrides, or custom settings were used beyond the steps above. ### Logs & Screenshots Docker container log at the moment of the failing request: ``` 2026-05-11 04:32:59.469 | ERROR | open_webui.main:process_chat:2015 - Error processing chat payload: 'NoneType' object has no attribute 'startswith' 2026-05-11 04:32:59.469 | INFO | uvicorn.protocols.http.httptools_impl:send:483 - 192.168.4.50:0 - "POST /api/chat/completions HTTP/1.1" 400 ``` Full traceback (obtained by adding `log.error('Full traceback: %s', traceback.format_exc())` to the error handler in `main.py`): ``` Traceback (most recent call last): File "/app/backend/open_webui/main.py", line 1977, in process_chat form_data, metadata, events = await process_chat_payload(request, form_data, user, metadata, model) File "/app/backend/open_webui/utils/middleware.py", line 2359, in process_chat_payload event_emitter = await get_event_emitter(metadata) File "/app/backend/open_webui/socket/main.py", line 902, in get_event_emitter if request_info.get('chat_id', '').startswith('channel:'): AttributeError: 'NoneType' object has no attribute 'startswith' ``` ### Additional Information ## Root cause In `open_webui/socket/main.py`, line 902: ```python if request_info.get('chat_id', '').startswith('channel:'): ``` When called via the API (no browser chat session), `metadata['chat_id']` is `None`. The `.get('chat_id', '')` call returns `None` rather than the default `''` because the key **exists** in the dict with a `None` value — `dict.get()` only uses the default when the key is **absent**, not when its value is `None`. ## Fix Replace: ```python request_info.get('chat_id', '').startswith(...) ``` with: ```python (request_info.get('chat_id') or '').startswith(...) ``` The same pattern exists in multiple other places across the codebase and should be fixed everywhere: - `open_webui/socket/main.py` line 902 — **primary crash site** - `open_webui/utils/middleware.py` — ~11 instances of `metadata['chat_id'].startswith(...)` without a null guard - `open_webui/main.py` — 1 instance of `metadata['chat_id'].startswith(...)` This bug makes the documented OpenAI-compatible API endpoint (`/api/chat/completions`) completely non-functional for any external client. The browser UI is unaffected because it always provides a `chat_id` via the WebSocket session.
GiteaMirror added the bug label 2026-05-15 16:21:01 -05:00
Author
Owner

@owui-terminator[bot] commented on GitHub (May 11, 2026):

⚠️ Missing Issue Title Prefix

@da-astro, your issue title is missing a categorising prefix (e.g. bug:, feat:, docs:).

Please update the title to lead with one of:

  • bug: bug report or error
  • feat: feature request or enhancement
  • docs: documentation issue
  • question: usage question
  • help: support request

Example: bug: Login fails when the password contains special characters

<!-- gh-comment-id:4417727107 --> @owui-terminator[bot] commented on GitHub (May 11, 2026): # ⚠️ Missing Issue Title Prefix @da-astro, your issue title is missing a categorising prefix (e.g. `bug:`, `feat:`, `docs:`). Please update the title to lead with one of: - **bug**: bug report or error - **feat**: feature request or enhancement - **docs**: documentation issue - **question**: usage question - **help**: support request Example: `bug: Login fails when the password contains special characters`
Author
Owner

@owui-terminator[bot] commented on GitHub (May 11, 2026):

🔍 Related Issues Found

I found some existing issues that might be related. Please check if any of these are duplicates or contain helpful solutions:

  1. 🟣 #24550 bug: NoneType object has no attribute 'startswith' — all /api/v1/chat/completions calls return 400 (v0.9.5, direct connections)
    This is the closest match: it reports the same 'NoneType' object has no attribute 'startswith' error on completions API calls, affecting external/API clients while the web UI works. The reported endpoint differs only by /api/v1/chat/completions vs /api/chat/completions, but the failure mode and root symptom are the same.
    by ThefloorMiner

  2. 🟢 #24553 issue: /api/chat/completions runs into error
    This open issue describes the same completions API crash with the exact 'NoneType' object has no attribute 'startswith' message on v0.9.5. Its reproduction is an API-only POST to /api/chat/completions, making it highly overlapping with the new report.
    by tweinberger-lei · bug

  3. 🟣 #24554 issue: Open WebUI v0.9.5 Broken Completions API
    This closed issue is another report of the completions API becoming broken in v0.9.5 with the same 400/error text and multiple external clients affected. It appears to be the same regression from a different reporter and client setup.
    by xcjs · bug


💡 If your issue is a duplicate, please close it and add any additional details to the existing issue instead.

This comment was generated automatically. React with 👍 if helpful, 👎 if not.

<!-- gh-comment-id:4417727754 --> @owui-terminator[bot] commented on GitHub (May 11, 2026): <!-- terminator-bot:related-issues-reply --> 🔍 **Related Issues Found** I found some existing issues that might be related. Please check if any of these are duplicates or contain helpful solutions: 1. 🟣 [#24550](https://github.com/open-webui/open-webui/issues/24550) **bug: NoneType object has no attribute 'startswith' — all /api/v1/chat/completions calls return 400 (v0.9.5, direct connections)** *This is the closest match: it reports the same `'NoneType' object has no attribute 'startswith'` error on completions API calls, affecting external/API clients while the web UI works. The reported endpoint differs only by `/api/v1/chat/completions` vs `/api/chat/completions`, but the failure mode and root symptom are the same.* *by ThefloorMiner* 2. 🟢 [#24553](https://github.com/open-webui/open-webui/issues/24553) **issue: /api/chat/completions runs into error** *This open issue describes the same completions API crash with the exact `'NoneType' object has no attribute 'startswith'` message on v0.9.5. Its reproduction is an API-only POST to `/api/chat/completions`, making it highly overlapping with the new report.* *by tweinberger-lei · `bug`* 3. 🟣 [#24554](https://github.com/open-webui/open-webui/issues/24554) **issue: Open WebUI v0.9.5 Broken Completions API** *This closed issue is another report of the completions API becoming broken in v0.9.5 with the same 400/error text and multiple external clients affected. It appears to be the same regression from a different reporter and client setup.* *by xcjs · `bug`* --- 💡 If your issue is a duplicate, please close it and add any additional details to the existing issue instead. *This comment was generated automatically.* React with 👍 if helpful, 👎 if not.
Author
Owner

@sacredbone commented on GitHub (May 11, 2026):

I receive the same error message when the LLM is using generate_image with a connected local comfyUI installation:

{
    "type": "function_call",
    "id": "call_o6kbvrt0",
    "call_id": "call_o6kbvrt0",
    "name": "generate_image",
    "arguments": "{\"prompt\": \"A cute, small, highly detailed robot, standing in a vibrant, sunlit meadow. The robot has big, expressive blue optical sensors and small, articulated limbs. Cinematic lighting with gentle sun rays filtering through the green leaves. The robot should have a slightly weathered, polished metallic chassis. Cute, Pixar/anime style, 8k resolution.\"}",
    "status": "completed"
  },
  {
    "type": "function_call_output",
    "id": "fco_89f9348aba1c4133838042a6",
    "call_id": "call_o6kbvrt0",
    "output": [
      {
        "type": "input_text",
        "text": "{\n  \"success\": false,\n  \"error\": \"Internal error: 400: [ERROR: 'NoneType' object has no attribute 'lower']\",\n  \"internal_trace\": \"Traceback (most recent call last):\\n  File \\\"/app/backend/open_webui/routers/images.py\\\", line 714, in image_generations\\n    _, url = await upload_image(\\n             ^^^^^^^^^^^^^^^^^^^\\n  File \\\"/app/backend/open_webui/routers/images.py\\\", line 475, in upload_image\\n    image_format = mimetypes.guess_extension(content_type)\\n                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"/usr/local/lib/python3.11/mimetypes.py\\\", line 347, in guess_extension\\n    return _db.guess_extension(type, strict)\\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"/usr/local/lib/python3.11/mimetypes.py\\\", line 202, in guess_extension\\n    extensions = self.guess_all_extensions(type, strict)\\n                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"/usr/local/lib/python3.11/mimetypes.py\\\", line 181, in guess_all_extensions\\n    type = type.lower()\\n           ^^^^^^^^^^\\nAttributeError: 'NoneType' object has no attribute 'lower'\\n\\nDuring handling of the above exception, another exception occurred:\\n\\nTraceback (most recent call last):\\n  File \\\"<string>\\\", line 448, in generate_image\\n  File \\\"/app/backend/open_webui/routers/images.py\\\", line 773, in image_generations\\n    raise HTTPException(status_code=400, detail=ERROR_MESSAGES.DEFAULT(error))\\nfastapi.exceptions.HTTPException: 400: [ERROR: 'NoneType' object has no attribute 'lower']\\n\",\n  \"valves_config\": {\n    \"debug\": true,\n    \"verbose\": true\n  }\n}"
      }
    ],
    "status": "completed"
  },

The image is generated on to comfyui side and not received/stored in openwebui.

<!-- gh-comment-id:4417770833 --> @sacredbone commented on GitHub (May 11, 2026): I receive the same error message when the LLM is using generate_image with a connected local comfyUI installation: ``` { "type": "function_call", "id": "call_o6kbvrt0", "call_id": "call_o6kbvrt0", "name": "generate_image", "arguments": "{\"prompt\": \"A cute, small, highly detailed robot, standing in a vibrant, sunlit meadow. The robot has big, expressive blue optical sensors and small, articulated limbs. Cinematic lighting with gentle sun rays filtering through the green leaves. The robot should have a slightly weathered, polished metallic chassis. Cute, Pixar/anime style, 8k resolution.\"}", "status": "completed" }, { "type": "function_call_output", "id": "fco_89f9348aba1c4133838042a6", "call_id": "call_o6kbvrt0", "output": [ { "type": "input_text", "text": "{\n \"success\": false,\n \"error\": \"Internal error: 400: [ERROR: 'NoneType' object has no attribute 'lower']\",\n \"internal_trace\": \"Traceback (most recent call last):\\n File \\\"/app/backend/open_webui/routers/images.py\\\", line 714, in image_generations\\n _, url = await upload_image(\\n ^^^^^^^^^^^^^^^^^^^\\n File \\\"/app/backend/open_webui/routers/images.py\\\", line 475, in upload_image\\n image_format = mimetypes.guess_extension(content_type)\\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n File \\\"/usr/local/lib/python3.11/mimetypes.py\\\", line 347, in guess_extension\\n return _db.guess_extension(type, strict)\\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n File \\\"/usr/local/lib/python3.11/mimetypes.py\\\", line 202, in guess_extension\\n extensions = self.guess_all_extensions(type, strict)\\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n File \\\"/usr/local/lib/python3.11/mimetypes.py\\\", line 181, in guess_all_extensions\\n type = type.lower()\\n ^^^^^^^^^^\\nAttributeError: 'NoneType' object has no attribute 'lower'\\n\\nDuring handling of the above exception, another exception occurred:\\n\\nTraceback (most recent call last):\\n File \\\"<string>\\\", line 448, in generate_image\\n File \\\"/app/backend/open_webui/routers/images.py\\\", line 773, in image_generations\\n raise HTTPException(status_code=400, detail=ERROR_MESSAGES.DEFAULT(error))\\nfastapi.exceptions.HTTPException: 400: [ERROR: 'NoneType' object has no attribute 'lower']\\n\",\n \"valves_config\": {\n \"debug\": true,\n \"verbose\": true\n }\n}" } ], "status": "completed" }, ``` The image is generated on to comfyui side and not received/stored in openwebui.
Author
Owner

@da-astro commented on GitHub (May 11, 2026):

Duplicate of #24553

<!-- gh-comment-id:4417788335 --> @da-astro commented on GitHub (May 11, 2026): Duplicate of #24553
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#91075