litellm - 💡(How to fix) Fix [Bug]: POST /chat/completions returns HTTP 200 with error body instead of 4xx when model is not found in config [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#27030Fetched 2026-05-02 05:28:07
View on GitHub
Comments
2
Participants
2
Timeline
11
Reactions
0
Timeline (top)
comment_deleted ×3closed ×2commented ×2labeled ×1

When calling POST /chat/completions with a model name that does not exist in the LiteLLM proxy config, the proxy returns HTTP 200 with a JSON error body instead of the expected HTTP 404 or HTTP 400.

Error Message

When calling POST /chat/completions with a model name that does not exist in the LiteLLM proxy config, the proxy returns HTTP 200 with a JSON error body instead of the expected HTTP 404 or HTTP 400. HTTP 404 or 400 with a JSON error describing that the model is not configured. HTTP 200 returned, but the JSON body contains an error message like: {"error": {"message": "No models available...", "type": "invalid_request_error"}}

Root Cause

When calling POST /chat/completions with a model name that does not exist in the LiteLLM proxy config, the proxy returns HTTP 200 with a JSON error body instead of the expected HTTP 404 or HTTP 400.

Code Example

litellm --port 4000 --master_key sk-1234

---

curl -s -w "\nHTTP %{http_code}"   -H "Authorization: Bearer sk-1234"   -H "Content-Type: application/json"   http://localhost:4000/chat/completions   -d '{"model": "totally-nonexistent-model-xyz", "messages": [{"role": "user", "content": "hi"}]}'

---

{"error": {"message": "No models available...", "type": "invalid_request_error"}}
RAW_BUFFERClick to expand / collapse

Description

When calling POST /chat/completions with a model name that does not exist in the LiteLLM proxy config, the proxy returns HTTP 200 with a JSON error body instead of the expected HTTP 404 or HTTP 400.

Steps to Reproduce

  1. Start the LiteLLM proxy with no custom model config (or default config only):
litellm --port 4000 --master_key sk-1234
  1. Call completions with a made-up model name:
curl -s -w "\nHTTP %{http_code}"   -H "Authorization: Bearer sk-1234"   -H "Content-Type: application/json"   http://localhost:4000/chat/completions   -d '{"model": "totally-nonexistent-model-xyz", "messages": [{"role": "user", "content": "hi"}]}'

Expected Behavior

HTTP 404 or 400 with a JSON error describing that the model is not configured.

Actual Behavior

HTTP 200 returned, but the JSON body contains an error message like:

{"error": {"message": "No models available...", "type": "invalid_request_error"}}

Clients that only check the HTTP status code (not the body) will misinterpret this as a success.

Environment

  • LiteLLM version: latest main
  • Python: 3.11
  • OS: macOS / Linux

extent analysis

TL;DR

The LiteLLM proxy should be modified to return an HTTP error status code (e.g., 404 or 400) when a non-existent model is requested, instead of returning a 200 status code with an error in the response body.

Guidance

  • Verify that the model name is correctly checked against the configured models in the LiteLLM proxy code.
  • Consider adding a check to return a 404 status code when the model is not found, to align with standard HTTP practices.
  • Review the error handling mechanism to ensure that it correctly sets the HTTP status code based on the error type.
  • Test the API with different model names and error scenarios to ensure the correct status codes are returned.

Example

No code snippet is provided as the issue does not contain sufficient information about the LiteLLM proxy's internal implementation.

Notes

The solution may require modifying the LiteLLM proxy code to handle model not found errors correctly. The exact changes will depend on the implementation details of the proxy.

Recommendation

Apply a workaround by modifying the LiteLLM proxy code to return the correct HTTP status code for non-existent models, as this will ensure correct behavior for clients that rely on HTTP status codes.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - 💡(How to fix) Fix [Bug]: POST /chat/completions returns HTTP 200 with error body instead of 4xx when model is not found in config [2 comments, 2 participants]