mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-23 10:02:10 -05:00
[GH-ISSUE #24564] bug: API calls to /api/chat/completions fail: "'NoneType' object has no attribute 'startswith'" #107330
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
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
README.md.Expected Behavior
API requests to
/api/chat/completionsshould return a successful chat completion response, as documented at https://docs.openwebui.com/reference/api-endpoints.Actual Behavior
Every API request to
/api/chat/completionsreturns HTTP 400 with:This affects all models (Ollama and OpenAI-compatible/Anthropic). The same models work correctly through the browser UI.
Steps to Reproduce
{"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:
Full traceback (obtained by adding
log.error('Full traceback: %s', traceback.format_exc())to the error handler inmain.py):Additional Information
Root cause
In
open_webui/socket/main.py, line 902:When called via the API (no browser chat session),
metadata['chat_id']isNone. The.get('chat_id', '')call returnsNonerather than the default''because the key exists in the dict with aNonevalue —dict.get()only uses the default when the key is absent, not when its value isNone.Fix
Replace:
with:
The same pattern exists in multiple other places across the codebase and should be fixed everywhere:
open_webui/socket/main.pyline 902 — primary crash siteopen_webui/utils/middleware.py— ~11 instances ofmetadata['chat_id'].startswith(...)without a null guardopen_webui/main.py— 1 instance ofmetadata['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 achat_idvia the WebSocket session.@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:
Example:
bug: Login fails when the password contains special characters@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:
🟣 #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/completionsvs/api/chat/completions, but the failure mode and root symptom are the same.by ThefloorMiner
🟢 #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🟣 #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.
@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:
The image is generated on to comfyui side and not received/stored in openwebui.
@da-astro commented on GitHub (May 11, 2026):
Duplicate of #24553