fix(proxy): stop /{provider}/v1/files from capturing /anthropic passthrough - #37412
Conversation
…hrough
The native files and batches routers mount before the passthrough router, so
/anthropic/v1/files matched /{provider}/v1/files with provider="anthropic" and
422'd on the OpenAI-only `purpose` field instead of forwarding to Anthropic's
Files API. Give /anthropic its own router mounted ahead of batches and files,
mirroring the fix already applied to /openai_passthrough in BerriAI#36092.
Greptile SummaryThis PR gives the Anthropic passthrough route a dedicated router mounted before the generic batches and files routers, preventing generic provider routes from capturing Anthropic SDK requests.
Confidence Score: 5/5The PR appears safe to merge because the dedicated router corrects the intended route precedence without changing authentication or unrelated provider routing. The Anthropic handler retains its route-level authentication and app middleware while moving ahead of only the generic files and batches routes that incorrectly captured
|
| Filename | Overview |
|---|---|
| litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py | Moves the existing authenticated Anthropic passthrough handler to a dedicated router without changing handler behavior. |
| litellm/proxy/proxy_server.py | Mounts the Anthropic passthrough router before generic batches and files routers so the intended route wins FastAPI precedence. |
| tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py | Adds regression coverage against the production route table for affected Anthropic files, batches, and messages paths. |
Reviews (1): Last reviewed commit: "fix(proxy): stop /{provider}/v1/files fr..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Hitting the same symptom sequence (422 missing Our case: we're not proxying to direct Since the built-in catch-all owns the literal But moving to a non- The description says "every other provider prefix keeps today's behavior" — meaning even once merged, this specific case (a custom prefix pointing at a non-default Anthropic-compatible endpoint via Version note: we're seeing this on Ask: would it be possible to generalize the fix so any path explicitly declared in Happy to provide a minimal repro |
|
That's a separate root cause: custom pass_through_endpoints prefixes, not the /anthropic catch-all this PR fixes. Please file a new issue for it. |
|
Filed as #37925 — thanks for the quick triage. |
TLDR
Problem this solves:
/anthropic/v1/files422s on OpenAI-onlypurposeinstead of forwarding to Anthropic/openai_passthrough, now on/anthropicHow it solves it:
/anthropicits own router, mounted ahead of the batches and files routersUser Flow
Before: a developer using the Anthropic SDK against the gateway cannot upload a document at all, so the model never sees their PDF
https://litellm-domain/anthropicand sendPOST https://litellm-domain/anthropic/v1/fileswithfile=@plan.pdf, whatclient.beta.files.upload({ file })emits422 {"detail":[{"type":"missing","loc":["body","purpose"],"msg":"Field required"}]}, no file id, and nothing in their Anthropic accountPOST https://litellm-domain/anthropic/v1/messages, so the answer ignores their PDFAfter: the same upload reaches Anthropic instead of being intercepted locally
https://litellm-domain/anthropicand send the samePOST https://litellm-domain/anthropic/v1/fileswithfile=@plan.pdf, no extra fieldsapi.anthropic.com, so with a valid key they get back Anthropic's own file object and can reference itsfile_idin a later/anthropic/v1/messagescallRelevant issues
Fixes #37289
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Config used for both runs:
Run with
ANTHROPIC_API_KEY=sk-ant-invalid-key-for-local-reproon purpose, same technique as the issue: a request LiteLLM answers itself fails 422 onpurpose, a request that is forwarded to Anthropic fails 401 there instead.Before (41de13a)
POST /anthropic/v1/files:After (75fbc4b)
POST /anthropic/v1/files, now forwarded, 401 from Anthropic as expected with an invalid key:/anthropic/v1/messagesstill forwards normally, same 401:Unit test proof,
git checkout HEAD~1 -- litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py litellm/proxy/proxy_server.pythen running the new test:Restoring the fix and re-running the full file:
Type
🐛 Bug Fix
Caveats (if any)
QA runbook
Final Attestation