Skip to content

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
mainfrom
litellm_fix_lit9372_status_codes
Open

shivamrawat1 wants to merge 6 commits into
mainfrom
litellm_fix_lit9372_status_codes

Conversation

@shivamrawat1

@shivamrawat1 shivamrawat1 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • /v1/ocr with a missing or empty file returns 500
  • An unknown response id on /v1/responses/{id} returns 400 "model=None, no healthy deployments"
  • max_output_tokens of zero or less is silently raised to 16, so OpenAI's 400 is hidden behind a 200
  • Vector store file attributes are cut to 16 keys and number or boolean values are dropped, so OpenAI's 400 is hidden behind a 200

How it solves it:

  • OCR request parsing raises ProxyException (400 invalid_request_error, 413 when the file is too large) instead of ValueError
  • Router._init_responses_api_endpoints raises NotFoundError (404) when a response id carries no litellm model id and there is no model, default deployment or generic fallback that could route it
  • _enforce_min_max_output_tokens only raises values from 1 to 15 up to 16, so the max_tokens=1 Claude Code warmup still works
  • The OpenAI vector store file create and update transforms pass attributes through unchanged instead of running them through add_openai_metadata

User 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

  1. They POST https://litellm-domain/v1/ocr with model but no file part, or with a zero-byte file, and get 500 internal_server_error
  2. They GET https://litellm-domain/v1/responses/invalid-response-id-xyz and get 400 "You passed in model=None. There are no healthy deployments"
  3. They POST https://litellm-domain/v1/responses with "max_output_tokens": -1 and get 200 with a 16-token answer
  4. They POST https://litellm-domain/v1/vector_stores/{vs}/files/{file} with 17 attributes and get 200, but only 16 attributes are saved

After: the same requests come back with the 4xx the caller should see

  1. The same OCR request returns 400 invalid_request_error with param: "file"
  2. The same lookup returns 404 "Response 'invalid-response-id-xyz' not found", and so do DELETE, cancel and input_items
  3. The same responses call returns OpenAI's own 400 "Expected a value >= 16, but got -1"
  4. The same attributes update returns OpenAI's own 400 "too many properties", and number and boolean attributes are now saved

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:

  • 25: Bedrock accepts max_tokens=0 itself
  • 31: OpenAI accepts an empty search query itself
  • 23: a 422 is still a client error
  • 27: a null temperature means unset
  • 29: an end_date before start_date returns an empty 200 today

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review

Screenshots / 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

  1. curl -X POST $B/v1/ocr -H "$AUTH" -F model=azure/doc-intel
  2. HTTP 500 internal_server_error "Multipart OCR request must include a 'file' field with the document to process"

Item 9, OCR with an empty file

  1. curl -X POST $B/v1/ocr -H "$AUTH" -F model=azure/doc-intel -F "file=@empty.pdf;type=application/pdf"
  2. HTTP 500 internal_server_error "Uploaded file is empty"

Item 21, unknown response id

  1. curl -X GET $B/v1/responses/invalid-response-id-xyz -H "$AUTH"
  2. HTTP 400 "You passed in model=None. There are no healthy deployments for this model"

Item 28, negative max_output_tokens

  1. curl -X POST $B/v1/responses -H "$AUTH" -d '{"model":"gpt-4o","input":"Say pong","store":false,"max_output_tokens":-1}'
  2. HTTP 200. The recorder shows litellm sent max_output_tokens: 16 upstream. 0 and -100 behave the same

Item 32, 17 vector store file attributes

  1. curl -X POST $B/v1/vector_stores/$VS/files/$FID -H "$AUTH" -d '{"attributes":{"key_00":"v", ... "key_16":"v"}}'
  2. HTTP 200, and only 16 attributes are saved
  3. Creating a file with {"n":1,"b":true,"s":"x"}: the recorder shows only {"s":"x"} was sent upstream

After (1eeb844)

Item 8, OCR with no file

  1. Same request
  2. HTTP 400 {"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

  1. Same request
  2. HTTP 400 {"error":{"message":"Uploaded file is empty","type":"invalid_request_error","param":"file","code":"400"}}

Item 21, unknown response id

  1. Same request, plus DELETE, POST .../cancel and GET .../input_items
  2. HTTP 404 "litellm.NotFoundError: Response 'invalid-response-id-xyz' not found: the id does not identify a deployment. Pass model to look up a provider response id."
  3. GET and DELETE on a real response id from a store: true call still return 200

Item 28, negative max_output_tokens

  1. Same request with -1, 0 and -100
  2. HTTP 400 for each: OpenAI's own "Invalid 'max_output_tokens': integer below minimum value. Expected a value >= 16, but got -1 instead."
  3. max_output_tokens 1 and 20 still return 200, and the recorder shows 1 is still sent as 16

Item 32, 17 vector store file attributes

  1. Same request
  2. HTTP 400: OpenAI's own "Invalid 'attributes': too many properties. Expected an object with at most 16 properties, but got an object with 17 properties instead."
  3. Creating a file with {"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 before

The other 27 cases

  1. I re-ran the full 32-case script on the branch
  2. Every case other than 8, 9, 21, 28 and 32 returned the same status as on main

Type

🐛 Bug Fix

Caveats (if any)

Low

  • Callers relying on max_output_tokens <= 0 being raised to 16 now get the provider's 400. This also applies through the chat completions to responses bridge (openai/responses/... with max_tokens=0)
  • SDK callers of Router.aget_responses and its siblings that pass an unknown id with no model now get NotFoundError, where before they got the router's no-deployment error
  • OCR JSON-body rejections (empty body, type: "file", reducto:// ids) now return 400 instead of 500
  • Not verified live: an OCR request with a valid PDF. The venv's native bridge build fails the same way on main and on the branch, before and after this change
  • Not verified live: an Azure responses deployment. The available Azure resource has no deployments

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

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

…d provider-rejected responses and vector store params

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/proxy/ocr_endpoints/endpoints.py 75.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no new actionable finding or outstanding numbered finding

Summary

The PR returns client errors for bad OCR uploads and unroutable response IDs. It also lets OpenAI reject nonpositive token limits and invalid vector-store attributes instead of silently changing them

  • Invalid OCR requests return clear client errors.
  • Unknown response IDs return 404 when no route can identify them.
  • Nonpositive Responses API token limits reach OpenAI unchanged.
  • Vector-store file requests keep the attributes callers send.

Reviews (3) · Last reviewed commit: "fix(router): do not 404 response lookups..." · Reviewed by Greptile

Comment thread litellm/router.py Resolved
Comment thread litellm/router.py Resolved
@codspeed

codspeed Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_fix_lit9372_status_codes (1eeb844) with main (04f0ea8)

Open in CodSpeed

shivamrawat1 and others added 5 commits October 9, 2026 02:20
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>
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants