Repository navigation
fix(proxy): resolve a team model's public name on files, batches, and vector store files routes - #50989
fix(proxy): resolve a team model's public name on files, batches, and vector store files routes#50989norkelbyte wants to merge 16 commits into
Conversation
… vector store files routes
GET /v1/files with target_model_names or an x-litellm-model header that names a team model's public name now scopes the list to the caller team's deployment, so a team key sees its own files instead of an empty list. Adds route tests for listing, uploading, and retrieving files by a team public model name
…files_team_model_hint
…files_team_model_hint # Conflicts: # litellm/proxy/openai_files_endpoints/common_utils.py # litellm/proxy/openai_files_endpoints/files_endpoints.py # litellm/proxy/vector_store_files_endpoints/endpoints.py # tests/unit/proxy/batches_endpoints/test_endpoints.py # tests/unit/proxy/openai_files_endpoint/test_files_common_utils.py
…list Files a team stores itself are keyed by the team model's public name, so the managed file list scope for a team deployment now includes that name next to the deployment's internal name and id
# Conflicts: # tests/unit/proxy/vector_store_files_endpoints/test_endpoints.py
Merging this PR will not alter performance1 warning
Comparing |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…files_team_model_hint # Conflicts: # litellm/proxy/openai_files_endpoints/files_endpoints.py # tests/unit/proxy/openai_files_endpoint/test_files_common_utils.py
…th the caller's team
…a managed file through its target model When a managed file's stored deployment is gone or the key cannot use it, the route fell back to the file's first target model and used that model's credentials, now resolved within the caller's team, without checking the key's model grants. The fallback now runs the same check the stored deployment path does
[Medium impact] The reviewed changes appear safe to merge, with no new blocking findings. SummaryThe PR passes the caller’s team into model lookups for files, batches, and vector store files.
Reviews (8) · Last reviewed commit: "fix(managed_files): refresh a team model..." · Reviewed by Greptile |
…params, and type the team model tests
… batch owner's team
…h the router When a managed file's stored deployment is gone and its target model is a team model the caller's team reaches, pin the call to that team deployment through the router instead of injecting the team's credentials and calling the provider directly. Spend now logs under the team's public model name and deployment id, and the router's per-deployment limits and cooldowns see the call. Proxy-wide models keep the existing path
…put read now passes
|
bugbot run |
… owner team's account
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 60a3f11. Configure here.
|
Closed to free an open-PR slot. Branch kept, and it reopens for final CI and bot reviews once ready |
A team key that names its team's own model on the files routes (with
x-litellm-model,?model=, or a bodymodel) got a 400 "Invalid model name", though the same key could chat with that model and create a vector store with it. Those routes looked the name up without the caller's team, so a team-only model never matchedNow those lookups pass the caller's team, so a team-only model resolves there as it does on chat, and a managed file list by that name shows the team's files. Another team's key still can't reach it
/stupid: What the PR adds
/stupid: What breaks
Original
TLDR
Problem this solves:
/v1/files,/v1/batches, and vector store filesPOST /v1/vector_storesHow it solves it:
?model=, body model, and model-encoded idsDecisions
POST /v1/filesfailed the same wayrequire_managed_files) by a team model's public name scopes to the caller team's deployment, so the team sees its own files, storage-backed ones included, and no other team'sUser Flow
Before: a developer whose team has only team models can create a vector store with one, but can't upload, attach, or list its files
gpt-5.6to their team with POST https://litellm-domain/model/new and"model_info": {"team_id": ...}, then gives them a team keyx-litellm-model: gpt-5.6and get 200 with avs_...idfile upload: Invalid model name passed in model=gpt-5.6file operation: Invalid model name passed in model=gpt-5.6require_managed_files: true, GET https://litellm-domain/v1/files?target_model_names=gpt-5.6 answers 400file list: Invalid model name ...After: the same calls reach OpenAI with the team's credential
file-...idrequire_managed_files: true, GET https://litellm-domain/v1/files?target_model_names=gpt-5.6 answers 200 with only that team's filesRelevant issues
Supersedes #35245 by @uday1bhanu, which threads the team the same way but predates the current files and batches auth code. Thanks for the original fix
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 moreDelays 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
Before ran at the merge base
f0d234c4c6and After at the PR, each on two proxies with 2 workers sharing Postgres and Redis, alternating calls. The team's credential was the proxy's only OpenAI credential. Every call hits real OpenAI (transcripts)Last updated:
60a3f116b8. Both re-add cases ran onaf076cd0b2, the batch cases on7b582f80fc, the managed file list on9300ada62aand the rest on8dd3f19986. Later product commits change only batch output reads and two managed file paths, which those cases skip.da60cc6f72only fixes test fakesWhy the team refresh in 60a3f11 keeps this proof
Two runs on
60a3f116b8andda60cc6f72made the provider file read fail during the batch retrieve, then read the output file as the team key, the master key and another team. Every route answered the same on both commits (run 7 after, run 7 before, run 8 after, run 8 before). A file id that carries its model goes straight to the provider, or answers 400 to a key without that model, so it never reaches the managed file refresh. A managed batch row stores the deployment id, which resolves without the team.test_afile_retrieve_refreshes_a_team_model_output_from_the_owner_team_accountcovers the team lookup for two teams, and the 314 managed files hook tests pass at the tipFile upload (headline)
POST /v1/fileswithx-litellm-model: gpt-5.6(proxy B)Before
After
File get
GET /v1/files/{file_id}(proxy A)Before
After
Managed file list
This case ran on
9300ada62aon its own proxies, set up the same way pluslitellm_settings.require_managed_files: true(transcripts)POST /v1/fileswith-F target_model_names=gpt-5.6(proxy B)Before
After
GET /v1/files?target_model_names=gpt-5.6(proxy A)Before
After
The other team's key,
GET /v1/files?target_model_names=gpt-5.6(proxy A)Before
After
Vector store files add, list, and get
POST /v1/vector_stores/{vs_id}/files(proxy B)Before
After
GET /v1/vector_stores/{vs_id}/files(proxy A)Before
After
GET /v1/vector_stores/{vs_id}/files/{file_id}(proxy A)Before
After
Batch create, get, and cancel
On After, OpenAI failed the batch between the get and the cancel, so the cancel reached the batch and got OpenAI's 409
POST /v1/batches(proxy A)Before
After
GET /v1/batches/{batch_id}(proxy B)Before has no batch to read, since create answered 400 above. The before leg's call with a stand-in id only reached OpenAI's own 404, and it stays in the transcripts
After
POST /v1/batches/{batch_id}/cancel(proxy B)Before has no batch to read, since create answered 400 above. The before leg's call with a stand-in id only reached OpenAI's own 404, and it stays in the transcripts
After
The store's copy of a managed file after the team re-adds its model
The team adds a second model,
gpt-5.6-b, uploads one file withtarget_model_names=gpt-5.6,gpt-5.6-b, and adds it to a new vector store, which then holds thegpt-5.6copy. The admin deletesgpt-5.6(70dfdc24-e348-4128-b011-02facb0e5f30on After) and adds it again (93e79474-43cd-4c0e-8b82-3d3448834d4e), and chat on both proxies answers from the new deployment before the reads below. After ran ataf076cd0b2, where both reads go through the router to the re-added deployment, as theirx-litellm-model-idheaders show. Steps 18 to 23c are in the transcriptsPOST /v1/vector_stores/{vs_id}/fileswith the managed file, before the re-add (proxy B)Before
After
GET /v1/vector_stores/{vs_id}/files/{managed_file_id}after the re-add (proxy A)Before
After
The same
GETon the other proxy (proxy B)Before
After
A team key not granted the file's model
Before the re-add, the team mints a key limited to
gpt-5.6-b. On both legs its chat withgpt-5.6and its read of the managed file from the store that holds thegpt-5.6copy answer 403The key limited to
gpt-5.6-bchats withgpt-5.6(proxy B)Before
After
The same key,
GET /v1/vector_stores/{vs_id}/files/{managed_file_id}(proxy A)Before
After
Another team's key
POST /v1/fileswith the other team's key (proxy A)Before
After
GET /v1/vector_stores/{vs_id}/fileswith the other team's key (proxy B)Before
After
Team batch on gpt-5.6-luna, its output and its spend
OpenAI's Batch API refuses
gpt-5.6, so this case adds the team modelgpt-5.6-lunawith custom prices of 0.00001 and 0.00002 per input and output token. Base answers 400 at upload, so no batch exists therePOST /v1/fileswithx-litellm-model: gpt-5.6-luna,purpose=batch(proxy B)Before
After, then
POST /v1/batcheson proxy A answers 200, and the final poll (proxy A) shows it completedThe team key downloads the output (proxy B), and the other team's key is denied (proxy A)
Spend logs (master key). The batch row carries the team deployment's id and 8 prompt and 4 completion tokens at 0.00008, which is the custom price at the batch discount (half of 8 x 0.00001 + 4 x 0.00002). OpenAI's own price for this model would give 0.0000032
A team batch's output file in the team's file list
After the same team batch completes, the team key lists its files (proxy A). At
4172d59439, the commit before7b582f80fc, the proxy recorded the output file without the team, so it shows 0 bytes and the raw OpenAI id as its name. At7b582f80fcit shows OpenAI's size and name. Reading the file by id fetches it from OpenAI and matches on bothAt
4172d59439At
7b582f80fcSpend row after the team deletes and re-adds its model
The team model
team-solo(openai/gpt-5.6on the team's credential) backs a managed file in a vector store. The team deletes the model and adds it again, so the file's stored deployment is gone. The team key then reads the file's content (proxy B). At4172d59439this call went straight to OpenAI and its spend row showedopenai/gpt-5.6as the model group. Now both legs log the team's model name and the re-added deployment's idBefore, the call and its spend row (master key)
After, the call, its spend row, and the team's deployments in
/model/info(master key)Control chat and vector store create
POST /v1/chat/completionswithmodel: gpt-5.6(proxy B)Before
After
POST /v1/vector_storeswithx-litellm-model: gpt-5.6(proxy A)Before
After
What QA noticed
gpt-5.6batch, so cancel got 409Type
🐛 Bug Fix
Caveats (if any)
Severe
Medium
Low
model_aliasesstill answer 400 on these routes. Unchanged, tracked separatelyFinal Attestation
Bugbot summary