Because request.app.state.OPENAI_MODELS is empty here, it will always fail.
My current workaround soltution is to add a await get_all_models(request) above the mentioned code. This way request.app.state.OPENAI_MODELS gets filled before the check actually gets executed.
awaitget_all_models(request)model=request.app.state.OPENAI_MODELS.get(model_id)ifmodel:idx=model["urlIdx"]else:raiseHTTPException(status_code=404,detail="Model not found",)
Reproduction Details
Steps to Reproduce:
See curl command above.
Logs and Screenshots
Browser Console Logs:
curl -H "Authorization: Bearer S3CR3T123" -H 'Content-Type: application/json' 'http://openwebui.host/openai/chat/completions' -d '{"model":"gpt-4o-mini", "messages": [{"role": "user", "content":"Write a 50 word story"}], "stream": false}'
{
"detail": "Model not found"
}
Docker Container Logs:
INFO: 192.168.178.20 - "POST /openai/chat/completions HTTP/1.1" 404 Not Found
Originally created by @McBane87 on GitHub (Jan 11, 2025).
# Bug Report
## Installation Method
Docker
## Environment
- **Open WebUI Version:** 0.5.4
- **Operating System:** Ubuntu 24.04
**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:
API Proxy/Endpoint `/openai/chat/completions` should proxy requests to specified model, when doing for example:
```
curl -H "Authorization: Bearer S3CR3T123" -H 'Content-Type: application/json' 'http://openwebui.host/openai/chat/completions' -d '{"model":"gpt-4o-mini", "messages": [{"role": "user", "content":"Write a 50 word story"}], "stream": false}'
```
## Actual Behavior:
Instead of doing the wanted task, it gives a `404 - {"detail": "Model not found"}` response.
## Description
**Bug Summary:**
The bug seems to be caused by:
https://github.com/open-webui/open-webui/blob/4269df041fef62208d59babe0faae866d2bfbc3c/backend/open_webui/routers/openai.py#L576-L583
Because `request.app.state.OPENAI_MODELS` is empty here, it will always fail.
My current workaround soltution is to add a `await get_all_models(request)` above the mentioned code. This way `request.app.state.OPENAI_MODELS` gets filled before the check actually gets executed.
```python
await get_all_models(request)
model = request.app.state.OPENAI_MODELS.get(model_id)
if model:
idx = model["urlIdx"]
else:
raise HTTPException(
status_code=404,
detail="Model not found",
)
```
## Reproduction Details
**Steps to Reproduce:**
See curl command above.
## Logs and Screenshots
**Browser Console Logs:**
```
curl -H "Authorization: Bearer S3CR3T123" -H 'Content-Type: application/json' 'http://openwebui.host/openai/chat/completions' -d '{"model":"gpt-4o-mini", "messages": [{"role": "user", "content":"Write a 50 word story"}], "stream": false}'
{
"detail": "Model not found"
}
```
**Docker Container Logs:**
```
INFO: 192.168.178.20 - "POST /openai/chat/completions HTTP/1.1" 404 Not Found
```
**Screenshots/Screen Recordings (if applicable):**
None
## Additional Information
None
a doubt,
shouldn't it be curl https://openwebui.host/openai/v1/chat/completions -H "Content-Type: application/json" -H "Authorization: Bearer $OPENAI_API_KEY" -d '{"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Say this is a test!"}], "temperature": 0.7 }'
?
(I emphasize .../v1/chat/completions)
(https://platform.openai.com/docs/api-reference/making-requests)
@rgaricano commented on GitHub (Jan 11, 2025):
a doubt,
shouldn't it be
`curl https://openwebui.host/openai/v1/chat/completions -H "Content-Type: application/json" -H "Authorization: Bearer $OPENAI_API_KEY" -d '{"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Say this is a test!"}], "temperature": 0.7 }'`
?
(I emphasize .../**v1**/chat/completions)
(https://platform.openai.com/docs/api-reference/making-requests)
There is no "/v1" route defined in open-webui/backend/open_webui/routers/openai.py. So I guess no, my approach (without v1) is correct. What also makes me think it's correct: It works, without "v1", if I add my workaround.
@McBane87 commented on GitHub (Jan 11, 2025):
There is no "/v1" route defined in `open-webui/backend/open_webui/routers/openai.py`. So I guess no, my approach (without v1) is correct. What also makes me think it's correct: It works, without "v1", if I add my workaround.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @McBane87 on GitHub (Jan 11, 2025).
Bug Report
Installation Method
Docker
Environment
Confirmation:
Expected Behavior:
API Proxy/Endpoint
/openai/chat/completionsshould proxy requests to specified model, when doing for example:Actual Behavior:
Instead of doing the wanted task, it gives a
404 - {"detail": "Model not found"}response.Description
Bug Summary:
The bug seems to be caused by:
https://github.com/open-webui/open-webui/blob/4269df041fef62208d59babe0faae866d2bfbc3c/backend/open_webui/routers/openai.py#L576-L583
Because
request.app.state.OPENAI_MODELSis empty here, it will always fail.My current workaround soltution is to add a
await get_all_models(request)above the mentioned code. This wayrequest.app.state.OPENAI_MODELSgets filled before the check actually gets executed.Reproduction Details
Steps to Reproduce:
See curl command above.
Logs and Screenshots
Browser Console Logs:
Docker Container Logs:
Screenshots/Screen Recordings (if applicable):
None
Additional Information
None
@rgaricano commented on GitHub (Jan 11, 2025):
a doubt,
shouldn't it be
curl https://openwebui.host/openai/v1/chat/completions -H "Content-Type: application/json" -H "Authorization: Bearer $OPENAI_API_KEY" -d '{"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Say this is a test!"}], "temperature": 0.7 }'?
(I emphasize .../v1/chat/completions)
(https://platform.openai.com/docs/api-reference/making-requests)
@McBane87 commented on GitHub (Jan 11, 2025):
There is no "/v1" route defined in
open-webui/backend/open_webui/routers/openai.py. So I guess no, my approach (without v1) is correct. What also makes me think it's correct: It works, without "v1", if I add my workaround.@tjbck commented on GitHub (Jan 12, 2025):
Fixed with
5d3f778b2a, Thanks!