[GH-ISSUE #6646] POST /v1/chat/completions returns 404 not 400 for model not found #66219

Closed
opened 2026-05-04 00:55:36 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @codefromthecrypt on GitHub (Sep 5, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/6646

What is the issue?

POST /v1/chat/completions returns 404 not 400 for model not found. Semantically, the better code here is 400, as it is an invalid argument on a correct route. Using 404 messages on a route that exists is confusing and had me doubting if the routes were mounted or not.

This seems to be the same for other routes. Basically, I suggest any code that looks like this:

			c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("model '%s' not found", req.Model)})

switch it to bad request

			c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("model '%s' not found", req.Model)})

That way, we know the parameter was wrong vs not being able to find the route. I can raise a PR if you like

OS

Linux

GPU

Apple

CPU

No response

Ollama version

0.3.9

Originally created by @codefromthecrypt on GitHub (Sep 5, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/6646 ### What is the issue? POST /v1/chat/completions returns 404 not 400 for model not found. Semantically, the better code here is 400, as it is an invalid argument on a correct route. Using 404 messages on a route that exists is confusing and had me doubting if the routes were mounted or not. This seems to be the same for other routes. Basically, I suggest any code that looks like this: ```go c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("model '%s' not found", req.Model)}) ``` switch it to bad request ```go c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("model '%s' not found", req.Model)}) ``` That way, we know the parameter was wrong vs not being able to find the route. I can raise a PR if you like ### OS Linux ### GPU Apple ### CPU _No response_ ### Ollama version 0.3.9
GiteaMirror added the bug label 2026-05-04 00:55:37 -05:00
Author
Owner

@jmorganca commented on GitHub (Sep 5, 2024):

Thanks @codefromthecrypt. A PR would be awesome!

<!-- gh-comment-id:2330428576 --> @jmorganca commented on GitHub (Sep 5, 2024): Thanks @codefromthecrypt. A PR would be awesome!
Author
Owner

@codefromthecrypt commented on GitHub (Sep 5, 2024):

actually, I double checked.. openai uses 404 for model not found, surprising to me. So, we have a choice of using 400 only in our endpoints, or using 404 because openai does, for ollama endpoints. preferences?

$ curl -v https://api.openai.com/v1/chat/completions \
>                                 -H "Content-Type: application/json" \
>                                 -H "Authorization: Bearer $OPENAI_API_KEY" \
>                                 -d '{
>                                   "model": "gpt-4l",
>                                   "messages": [
>                                     {
>                                       "role": "user",
>                                       "content": [
>                                         {
>                                           "type": "text",
>                                           "text": "hello?"
>                                         }
>                                       ]
>                                     }
>                                   ],
>                                   "max_tokens": 10
>                                 }'
--snip--
< HTTP/2 404 
< date: Thu, 05 Sep 2024 01:53:03 GMT
< content-type: application/json; charset=utf-8
< content-length: 212
--snip--
{
    "error": {
        "message": "The model `gpt-4l` does not exist or you do not have access to it.",
        "type": "invalid_request_error",
        "param": null,
        "code": "model_not_found"
    }
}
<!-- gh-comment-id:2330450112 --> @codefromthecrypt commented on GitHub (Sep 5, 2024): actually, I double checked.. openai uses 404 for model not found, surprising to me. So, we have a choice of using 400 only in our endpoints, or using 404 because openai does, for ollama endpoints. preferences? ```bash $ curl -v https://api.openai.com/v1/chat/completions \ > -H "Content-Type: application/json" \ > -H "Authorization: Bearer $OPENAI_API_KEY" \ > -d '{ > "model": "gpt-4l", > "messages": [ > { > "role": "user", > "content": [ > { > "type": "text", > "text": "hello?" > } > ] > } > ], > "max_tokens": 10 > }' --snip-- < HTTP/2 404 < date: Thu, 05 Sep 2024 01:53:03 GMT < content-type: application/json; charset=utf-8 < content-length: 212 --snip-- { "error": { "message": "The model `gpt-4l` does not exist or you do not have access to it.", "type": "invalid_request_error", "param": null, "code": "model_not_found" } } ```
Author
Owner

@pdevine commented on GitHub (Sep 9, 2024):

I would be worried about changing this given other people might be expecting 404 and not 400 in their own applications/scripts. Given there is precedent, let's leave this as it is.

<!-- gh-comment-id:2339255999 --> @pdevine commented on GitHub (Sep 9, 2024): I would be worried about changing this given other people might be expecting 404 and not 400 in their own applications/scripts. Given there is precedent, let's leave this as it is.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#66219