Repository navigation
fix(proxy): return 4xx instead of 500 for proxy-side request validation errors - #43918
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
…on errors Co-authored-by: shivam <shivam@berri.ai> Co-authored-by: AtsutoNakayama <atsuto010707@gmail.com> Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
| "aspeech": ("input",), | ||
| "amoderation": ("input",), | ||
| "aimage_generation": ("prompt",), | ||
| "aimage_edit": ("image", "prompt"), |
| raise litellm.NotFoundError( | ||
| message=( | ||
| f"Response '{response_id}' not found. " | ||
| "It carries no LiteLLM routing information and no model was provided." | ||
| ), | ||
| model="", | ||
| llm_provider="", |
There was a problem hiding this comment.
Proxy error added to Router This adds a proxy-facing response-ID error message to the shared SDK Router. The repository requires proxy error messages to stay out of
router.py because they also affect SDK users.
Rule Used: Don’t add stuff to router.py that is error messages for proxy. This impacts SDK users. (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
TLDR
Problem this solves:
How it solves it:
Upstream provider errors already came through with the provider's own status. I checked 400, 401 and 404 across chat, streaming, completions, embeddings, speech, transcription, moderations, images, responses, files, batches and /v1/messages against the direct provider call. This PR only changes errors the proxy raises itself
User Flow
Before: a developer whose app forgets a required field gets a 500, so their retry logic treats it as an outage
modelandvoicebut noinputRouter.aspeech() missing 1 required positional argument: 'input'After: the same request comes back as a client error naming the field
input{"type":"invalid_request_error","param":"input"}, the same status OpenAI returnsLinear ticket
Resolves LIT-9016
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Screenshots / Proof of Fix
After was captured on 6593f28fcc, which differs from b88110f only in a suppression comment. A live proxy on localhost:4000 with real OpenAI and Anthropic deployments (
gpt-5-mini,gpt-4o-mini-tts,gpt-image-1-mini,claude-opus-4-8), master keysk-item159. Each case was also sent straight to the provider for comparison. The full 54-case matrix is summarized at the endBefore (3930c5b)
Speech missing input
curl -X POST localhost:4000/v1/audio/speech -H "Authorization: Bearer sk-item159" -H "Content-Type: application/json" -d '{"model":"gpt-4o-mini-tts","voice":"alloy","response_format":"mp3"}'500 {"error":{"message":"Router.aspeech() missing 1 required positional argument: 'input'","type":"None","param":"None","code":"500"}}, while OpenAI directly returns 400Image generation missing prompt
curl -X POST localhost:4000/v1/images/generations -H "Authorization: Bearer sk-item159" -H "Content-Type: application/json" -d '{"model":"gpt-image-1-mini","n":1,"size":"1024x1024","quality":"low"}'500 {"error":{"message":"Router.aimage_generation() missing 1 required positional argument: 'prompt'","type":"internal_server_error","param":null,"code":"500"}}, while OpenAI directly returns 400Messages missing max_tokens
curl -X POST localhost:4000/v1/messages -H "Authorization: Bearer sk-item159" -H "Content-Type: application/json" -d '{"model":"claude-opus-4-8","messages":[{"role":"user","content":"hi"}]}'500 {"type":"error","error":{"type":"api_error","message":"anthropic_messages() missing 1 required positional argument: 'max_tokens'"}}, while Anthropic directly returns 400Rerank missing query
curl -X POST localhost:4000/v1/rerank -H "Authorization: Bearer sk-item159" -H "Content-Type: application/json" -d '{"model":"gpt-5-mini"}'500 {"error":{"message":"arerank() missing 2 required positional arguments: 'query' and 'documents'","type":"internal_server_error","param":null,"code":"500"}}Responses GET unknown id
curl localhost:4000/v1/responses/resp_0000000000000000000000000000000000000000000000ab -H "Authorization: Bearer sk-item159"400 {"error":{"message":"litellm.BadRequestError: You passed in model=None. There are no healthy deployments for this model","type":"invalid_request_error","param":null,"code":"400"}}, while OpenAI directly returns 404Spend logs bad date
curl "localhost:4000/spend/logs?start_date=notadate&end_date=alsonot" -H "Authorization: Bearer sk-item159"500 {"error":{"message":"/spend/logs Errortime data 'notadate' does not match format '%Y-%m-%d'","type":"internal_error","param":"None","code":"500"}}Upstream 400 passthrough
curl -X POST localhost:4000/v1/chat/completions -H "Authorization: Bearer sk-item159" -H "Content-Type: application/json" -d '{"model":"gpt-5-mini","messages":[{"role":"user","content":"hi"}],"reasoning_effort":"bogus"}'400 {"error":{"message":"litellm.BadRequestError: OpenAIException - Unsupported value: 'reasoning_effort' does not support 'bogus' with this model..., matching OpenAI's 400After (b88110f)
Speech missing input
400 {"error":{"message":"/audio/speech: Missing required parameter: 'input'.","type":"invalid_request_error","param":"input","code":"400"}}Image generation missing prompt
400 {"error":{"message":"/images/generations: Missing required parameter: 'prompt'.","type":"invalid_request_error","param":"prompt","code":"400"}}Messages missing max_tokens
400 {"type":"error","error":{"type":"invalid_request_error","message":"/v1/messages: Missing required parameter: 'max_tokens'."}}Rerank missing query
400 {"error":{"message":"/rerank: Missing required parameter: 'query'.","type":"invalid_request_error","param":"query","code":"400"}}Responses GET unknown id
404 {"error":{"message":"litellm.NotFoundError: Response 'resp_0000000000000000000000000000000000000000000000ab' not found. It carries no LiteLLM routing information and no model was provided.","type":"invalid_request_error",...,"code":"404"}}Spend logs bad date
400 {"error":{"message":"/spend/logs: Invalid start_date 'notadate', expected YYYY-MM-DD","type":"invalid_request_error","param":"start_date","code":"400"}}Upstream 400 passthrough
400, unchanged, still matching OpenAIAcross the whole matrix, 14 rows changed status and all of them moved from 500 (or the wrong 4xx) to the 4xx the provider returns. These were speech, moderations, image generation and edits, completions, rerank, search, /v1/messages missing messages or max_tokens, daily activity
page=0, /spend/logs bad date, and responses GET/DELETE for an unknown id. No other row changedType
🐛 Bug Fix
✅ Test
Caveats (if any)
Medium
invalid-response-id-xyznow gets 404, OpenAI returns 400Low
router.asearchcatchingValueErrorfor an unknown tool now getlitellm.BadRequestError/v1/threadswithoutassistants_configstill returns 500, which is a server misconfigurationqueryavoids the default search model regression Greptile flagged thereFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/c431842b4f6d4ccd9daef79826e6e2c7
Open in Devin Desktop: https://app.devin.ai/desktop/session/c431842b4f6d4ccd9daef79826e6e2c7?variant=devin
Requested by: @yucheng-berri