OpenAI Proxy endpoint "/openai/chat/completions" is broken #3248

Closed
opened 2025-11-11 15:26:50 -06:00 by GiteaMirror · 3 comments
Owner

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:

4269df041f/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.

    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

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
Author
Owner

@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)

@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)
Author
Owner

@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.

@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.
Author
Owner

@tjbck commented on GitHub (Jan 12, 2025):

Fixed with 5d3f778b2a, Thanks!

@tjbck commented on GitHub (Jan 12, 2025): Fixed with 5d3f778b2aff510f2470ba70ea8a03fd0f3cce0a, Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#3248