Repository navigation
fix(proxy): return 4xx for OCR upload errors, unknown response ids and provider-rejected responses and vector store params - #45483
Open
shivamrawat1 wants to merge 6 commits into
Open
shivamrawat1 wants to merge 6 commits into
shivamrawat1 wants to merge 6 commits into
Conversation
…d provider-rejected responses and vector store params Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
|
Contributor
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…eutral message Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
Contributor
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR
Problem this solves:
/v1/ocrwith a missing or empty file returns 500/v1/responses/{id}returns 400 "model=None, no healthy deployments"max_output_tokensof zero or less is silently raised to 16, so OpenAI's 400 is hidden behind a 200How it solves it:
ProxyException(400invalid_request_error, 413 when the file is too large) instead ofValueErrorRouter._init_responses_api_endpointsraisesNotFoundError(404) when a response id carries no litellm model id and there is nomodel, default deployment or generic fallback that could route it_enforce_min_max_output_tokensonly raises values from 1 to 15 up to 16, so themax_tokens=1Claude Code warmup still worksattributesthrough unchanged instead of running them throughadd_openai_metadataUser Flow
Before: a developer who sends a bad request gets a 500 or a 200, so they cannot tell their own mistake from a gateway failure
modelbut nofilepart, or with a zero-byte file, and get 500internal_server_error"max_output_tokens": -1and get 200 with a 16-token answerAfter: the same requests come back with the 4xx the caller should see
invalid_request_errorwithparam: "file"Linear ticket
Resolves LIT-9372
The ticket lists 32 cases found on 1.104.0-rc.1. I re-ran all 32 live on main at f48d837. 22 of them are already fixed on main, mostly by #43787. This PR fixes items 8, 9, 21, 28 and 32. I left these alone on purpose:
max_tokens=0itselftemperaturemeans unsetend_datebeforestart_datereturns an empty 200 todayPre-Submission checklist
uv run pytest tests/unit/<your_test_file>.py -vScreenshots / Proof of Fix
Setup: a live proxy with real Postgres and real providers (OpenAI gpt-4o, OpenAI vector stores, Azure Document Intelligence). Before ran on main and After ran on the branch, with the same config and the same requests. A forwarding recorder sat in front of api.openai.com on both runs to diff what litellm sent upstream
Before (f48d837)
Item 8, OCR with no file
curl -X POST $B/v1/ocr -H "$AUTH" -F model=azure/doc-intelinternal_server_error"Multipart OCR request must include a 'file' field with the document to process"Item 9, OCR with an empty file
curl -X POST $B/v1/ocr -H "$AUTH" -F model=azure/doc-intel -F "file=@empty.pdf;type=application/pdf"internal_server_error"Uploaded file is empty"Item 21, unknown response id
curl -X GET $B/v1/responses/invalid-response-id-xyz -H "$AUTH"Item 28, negative max_output_tokens
curl -X POST $B/v1/responses -H "$AUTH" -d '{"model":"gpt-4o","input":"Say pong","store":false,"max_output_tokens":-1}'max_output_tokens: 16upstream. 0 and -100 behave the sameItem 32, 17 vector store file attributes
curl -X POST $B/v1/vector_stores/$VS/files/$FID -H "$AUTH" -d '{"attributes":{"key_00":"v", ... "key_16":"v"}}'{"n":1,"b":true,"s":"x"}: the recorder shows only{"s":"x"}was sent upstreamAfter (1eeb844)
Item 8, OCR with no file
{"error":{"message":"Multipart OCR request must include a 'file' field with the document to process","type":"invalid_request_error","param":"file","code":"400"}}Item 9, OCR with an empty file
{"error":{"message":"Uploaded file is empty","type":"invalid_request_error","param":"file","code":"400"}}Item 21, unknown response id
POST .../cancelandGET .../input_itemsmodelto look up a provider response id."store: truecall still return 200Item 28, negative max_output_tokens
max_output_tokens1 and 20 still return 200, and the recorder shows 1 is still sent as 16Item 32, 17 vector store file attributes
{"n":1,"b":true,"s":"x"}now sends all three upstream, and retrieving the file directly from OpenAI shows{"b": true, "n": 1, "s": "x"}. Requests with only string attributes, or with no attributes, send the same body as beforeThe other 27 cases
Type
🐛 Bug Fix
Caveats (if any)
Low
max_output_tokens <= 0being raised to 16 now get the provider's 400. This also applies through the chat completions to responses bridge (openai/responses/...withmax_tokens=0)Router.aget_responsesand its siblings that pass an unknown id with no model now getNotFoundError, where before they got the router's no-deployment errortype: "file",reducto://ids) now return 400 instead of 500Final Attestation
Link to Devin session: https://app.devin.ai/sessions/6febf2f6874e4a5aad3a1fda6573fabb
Open in Devin Desktop: https://app.devin.ai/desktop/session/6febf2f6874e4a5aad3a1fda6573fabb?variant=devin
Requested by: @shivamrawat1