Skip to content

fix(files)!: scope provider and model file lists to the caller's managed files under require_managed_files - #47682

Merged
mateo-berri merged 11 commits into
mainfrom
litellm_scope_provider_file_list_to_owner
Oct 28, 2026
Merged

mateo-berri merged 11 commits into
mainfrom
litellm_scope_provider_file_list_to_owner

Conversation

@mateo-berri

@mateo-berri mateo-berri commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

With require_managed_files on, a non-admin file list that names a provider or a model now returns only the caller's own and team managed files there. Before, those lists read the shared provider key, so on Anthropic every key saw every file on it, other users' uploads included. Admin lists stay as they are on main

Paging works under the flag now too, with limit, after, and the Anthropic SDK's after_id and before_id

Original

Breaking change: with require_managed_files on, a non-admin's provider and model lists show only their own and team managed files, newest first, and answer 500 without the managed files hook. Admin lists are unchanged

TLDR

Problem this solves:

  • Anthropic file lists show every file on the shared key
  • limit and after are ignored under the flag

How it solves it:

  • Non-admin provider and model lists read the caller's own and team managed files there
  • after, after_id and before_id page newest first

User Flow

Before: with require_managed_files on, user B can list user A's Anthropic files

  1. With require_managed_files on, user A uploads with POST https://litellm-domain/anthropic/v1/files and target_model_names=claude-files
  2. User B sends GET https://litellm-domain/anthropic/v1/files with B's own key
  3. B gets 200 with every file on the shared Anthropic key, A's upload under its raw file_01... id
  4. B can't open A's file, but now knows its name and id

After: B sees only B's own files, and A pages through A's

  1. With require_managed_files on, user A uploads with POST https://litellm-domain/anthropic/v1/files and target_model_names=claude-files
  2. User B sends GET https://litellm-domain/anthropic/v1/files with B's own key
  3. B gets 200 with "data": [] on every provider or model list form
  4. A's same GET lists only A's uploads by managed id, and after_id or before_id pages through them

Design decisions

11 decisions
  • A provider in the path, ?provider=, or custom-llm-provider narrows the list to that provider's deployments, plus pass-through uploads on OpenAI and Azure
  • A model in x-litellm-model, the body, or target_model_names narrows it to every deployment serving that model, after the access check
  • A file matches by deployment id or model name, since LiteLLM maps the files it stores by model name. A stored file also shows on the provider a wildcard routes it to, and exact names win. So does one uploaded through a model_group_alias or a routing group, on the provider its model resolves to
  • after_id means after and before_id pages toward newer files, as the Anthropic SDK sends them. Conflicting cursors answer 400
  • An unknown provider answers 400 instead of an empty list
  • Lists are newest first, where main's flag-on OpenAI list was oldest first
  • With no limit, an Anthropic list returns 20 rows like Anthropic's API, and other lists keep the 10000 cap
  • With the flag off, lists behave as on main
  • An admin keeps main's provider list, hook or not, so ops still see every file on a shared key
  • Without the managed files hook (no database), a non-admin list answers 500 instead of the shared key's files
  • A provider or model list filters in raw SQL, since Prisma's JSON filter cannot match any of several keys, over a new created_by and created_at index built CONCURRENTLY. Filtering 40k owned rows in Python took about 7 s

Relevant issues

Related to #45071, which asked for a hook on provider-prefixed file routes. This PR builds that isolation in instead

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • 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. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • 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
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

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

Both legs ran the same scripts on real OpenAI, Anthropic and Azure, with a fresh database and 2 uvicorn workers per proxy. U1 to U12 are user A's uploads, listed in the shared setup. Rows other runs left on the shared key show as a count. The timing cases seed 200,000 rows, 40,000 of them B's and none on Anthropic

Case Before After
B on /anthropic/v1/files U6 to U3 + 16 empty
A on /anthropic/v1/files U6 to U3 + 16 U6 to U3
A with the wildcard stored-batch model 404 U10
A on Anthropic after the alias upload U11 20 rows from other runs U11, U6 to U3
A, Anthropic SDK auto-paging limit ignored, 20 rows U6 to U3, stops
Timing, B on Anthropic, run 1 200 in 0.22 s, 20 rows 200 in 0.21 s, 0 rows
All 48 cases
Case Before After
B on /openai/v1/files empty empty
B on /anthropic/v1/files U6 to U3 + 16 empty
B with ?provider=anthropic U6 to U3 + 16 empty
B with custom-llm-provider U6 to U3 + 16 empty
B with Claude target_model_names U6 to U3 + 16 empty
B with Claude x-litellm-model U6 to U3 + 16 empty
B on /azure/v1/files empty empty
B with no provider empty empty
B's gpt-only key, Claude model 403 403
B through the OpenAI SDK empty empty
B through the Anthropic SDK U6 to U3 + 16 empty
A on /openai/v1/files U1, U2, U7 U7, U2, U1
A on /anthropic/v1/files U6 to U3 + 16 U6 to U3
A with GPT target_model_names U1, U2, U7 U2, U1
A with Claude x-litellm-model U6 to U3 + 16 U4, U3
A with no provider U10 to U1 U10 to U1
A with anthropic/* wildcard model U6 to U3 + 16 U5
A on /azure/v1/files U9 U9
A with the stored-batch model 404 U8
A with the wildcard stored-batch model 404 U10
A with ?provider=hosted_vllm 404 U10, U8
A with ?provider=antropic 500 400
A on misspelled /antropic/v1/files 401 401
A, OpenAI limit=1 page 1 U1, U2, U7 U7
A, OpenAI page 2 with after U1, U2, U7 U2
A, Anthropic limit=1 page 1 U6 to U3 + 16 U6
A, Anthropic page 2 with after_id U6 to U3 + 16 U5
A, after=U2 with after_id=U1 U1, U2, U7 400
A, after=U2 with before_id=U1 U1 400
A, OpenAI SDK auto-paging U1, U2, U7, stops U7, U2, U1, stops
A, Anthropic SDK auto-paging limit ignored, 20 rows U6 to U3, stops
A, Anthropic SDK before_id=U3 limit ignored, 20 rows U4, U5, U6, stops
A on Anthropic after the alias upload U11 20 rows from other runs U11, U6 to U3
A with the alias in target_model_names 400 400
A on Anthropic after the routing-group upload U12 20 rows from other runs U12, U11, U6 to U3
B on Anthropic after U11 and U12 20 rows from other runs empty
Master key on /openai/v1/files U1, U2, U7 U1, U2, U7
Master key on /anthropic/v1/files 20 rows from other runs U6 to U3 + 16
D on /anthropic/v1/files 20 rows, has_more false 20 rows, has_more true
D with Claude x-litellm-model 20 rows, has_more false 20 rows, has_more true
D on /v1/files 21 rows, has_more false 21 rows, has_more false
Flag off, A with no cursor U10 to U1 U10 to U1
Flag off, A with three cursors U1 U1
No database, master key upload 500 500
No database, master key list 5488 rows 5488 rows
Timing, B on Anthropic, run 1 200 in 0.22 s, 20 rows 200 in 0.21 s, 0 rows
Timing, B on Anthropic, run 2 200 in 0.15 s, 20 rows 200 in 0.08 s, 0 rows
Timing, B on Anthropic, run 3 200 in 0.17 s, 20 rows 200 in 0.08 s, 0 rows
Shared setup

A uploaded U1 and U2 to OpenAI, U3 to U6 to Anthropic (U5 through anthropic/*, U6 on an unprefixed model), U7 through the OpenAI pass-through, U8 as a batch input LiteLLM stores itself, U9 to Azure, and U10 as a stored batch input for a model only the hosted_vllm/* wildcard serves. After the paging cases A uploaded U11 to Azure Blob Storage through litellm-qa-files-claude-alias, a model_group_alias of the Claude model, and U12 through litellm-qa-files-claude-group, a routing group over it. D uploaded 21 Anthropic files. A flag-off proxy and a no-database proxy share the scripts

model_list:
  - model_name: litellm-qa-files-gpt
    litellm_params:
      model: openai/gpt-5.4-mini
      api_key: os.environ/OPENAI_API_KEY
  - model_name: litellm-qa-files-claude
    litellm_params:
      model: anthropic/claude-haiku-5-5
      api_key: os.environ/ANTHROPIC_API_KEY
  - model_name: anthropic/*
    litellm_params:
      model: anthropic/*
      api_key: os.environ/ANTHROPIC_API_KEY
  - model_name: litellm-qa-files-claude-bare
    litellm_params:
      model: claude-haiku-5-5
      api_key: os.environ/ANTHROPIC_API_KEY
  - model_name: litellm-qa-files-azure
    litellm_params:
      model: azure/gpt-5.4-mini
      api_base: os.environ/AZURE_FOUNDRY_API_BASE
      api_key: os.environ/AZURE_FOUNDRY_API_KEY
      api_version: "2024-10-21"
  - model_name: litellm-qa-files-vllm
    litellm_params:
      model: hosted_vllm/qwen-local
      api_base: os.environ/QA_VLLM_API_BASE
  - model_name: hosted_vllm/*
    litellm_params:
      model: hosted_vllm/*
      api_base: os.environ/QA_VLLM_API_BASE

litellm_settings:
  require_managed_files: true

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
  database_url: os.environ/DATABASE_URL
  passthrough_managed_object_ids: true

router_settings:
  model_group_alias:
    litellm-qa-files-claude-alias: litellm-qa-files-claude
  routing_groups:
    - group_name: litellm-qa-files-claude-group
      models:
        - litellm-qa-files-claude
      routing_strategy: simple-shuffle

U11 and U12 need AZURE_STORAGE_ACCOUNT_NAME, AZURE_STORAGE_FILE_SYSTEM and AZURE_STORAGE_ACCOUNT_KEY on the proxy. The flag-off proxy sets require_managed_files: false, and the no-database proxy drops database_url and boots with env -u DATABASE_URL LITELLM_MODE=PRODUCTION. litellm-qa-files-vllm and hosted_vllm/* point at a static file server that answers 404 on /v1/files, like a vLLM server with no Files API, so its batch upload is stored by LiteLLM

python3 -m http.server $VLLM_PORT --bind 127.0.0.1 --directory vllm_empty &
export QA_VLLM_API_BASE=http://127.0.0.1:$VLLM_PORT/v1
python litellm/proxy/proxy_cli.py --config config.yaml --port $PORT --num_workers 2 --timeout_worker_healthcheck 120 --detailed_debug
export B=http://127.0.0.1:$PORT
admin() { curl -sS $B/$1 -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' -d "$2"; }
for u in a b d; do admin user/new "{\"user_id\": \"qa-files-user-$u\", \"user_role\": \"internal_user\"}"; done
KEY_A=$(admin key/generate '{"user_id": "qa-files-user-a", "key_alias": "qa-files-key-a"}' | jq -r .key)
KEY_B=$(admin key/generate '{"user_id": "qa-files-user-b", "key_alias": "qa-files-key-b"}' | jq -r .key)
KEY_C=$(admin key/generate '{"user_id": "qa-files-user-b", "key_alias": "qa-files-key-b-gpt-only", "models": ["litellm-qa-files-gpt"]}' | jq -r .key)
KEY_D=$(admin key/generate '{"user_id": "qa-files-user-d", "key_alias": "qa-files-key-d"}' | jq -r .key)
upload() {
  echo "user A private note $PREFIX $2" > $PREFIX-$2.txt
  curl -sS $B/$1/v1/files -H "Authorization: Bearer $KEY_A" -F purpose=${4:-user_data} -F target_model_names=$3 -F file=@$PREFIX-$2.txt | jq -r .id
}
export U1=$(upload openai gpt-older litellm-qa-files-gpt)
export U2=$(upload openai gpt-newer litellm-qa-files-gpt)
export U3=$(upload anthropic claude-older litellm-qa-files-claude)
export U4=$(upload anthropic claude-newer litellm-qa-files-claude)
export U5=$(upload anthropic claude-wildcard anthropic/claude-haiku-5-5)
export U6=$(upload anthropic claude-unprefixed litellm-qa-files-claude-bare)
echo "user A private note $PREFIX passthrough" > $PREFIX-passthrough.txt
export U7=$(curl -sS $B/openai_passthrough/v1/files -H "Authorization: Bearer $KEY_A" -F purpose=user_data -F file=@$PREFIX-passthrough.txt | jq -r .id)
printf '{"custom_id":"r1","method":"POST","url":"/v1/chat/completions","body":{"model":"litellm-qa-files-vllm","messages":[{"role":"user","content":"hi"}]}}\n' > $PREFIX-vllm-batch.jsonl
export U8=$(curl -sS $B/v1/files -H "Authorization: Bearer $KEY_A" -F purpose=batch -F target_model_names=litellm-qa-files-vllm -F file=@$PREFIX-vllm-batch.jsonl | jq -r .id)
export U9=$(upload azure azure litellm-qa-files-azure assistants)
printf '{"custom_id":"r1","method":"POST","url":"/v1/chat/completions","body":{"model":"hosted_vllm/qwen-wild","messages":[{"role":"user","content":"hi"}]}}\n' > $PREFIX-vllm-wild-batch.jsonl
export U10=$(curl -sS $B/v1/files -H "Authorization: Bearer $KEY_A" -F purpose=batch -F target_model_names=hosted_vllm/qwen-wild -F file=@$PREFIX-vllm-wild-batch.jsonl | jq -r .id)
for g in alias group; do
  echo "user A private note $PREFIX $g" > $PREFIX-$g.txt
  curl -sS $B/v1/files -H "Authorization: Bearer $KEY_A" -F purpose=user_data -F target_model_names=litellm-qa-files-claude-$g -F target_storage=azure_storage -F file=@$PREFIX-$g.txt | jq -r .id
done
for n in {01..21}; do
  echo "user D note $PREFIX d-$n" > $PREFIX-d-$n.txt
  curl -sS $B/anthropic/v1/files -H "Authorization: Bearer $KEY_D" -F purpose=user_data -F target_model_names=litellm-qa-files-claude -F file=@$PREFIX-d-$n.txt > /dev/null
done

D's uploads run after every A and B case. Every list response goes through this filter. It keeps rows whose id is U1 to U12 or whose file name starts with the run's prefix, and collapses every other row on the shared key into a count

redact_foreign_rows() {
  jq --indent 1 --argjson ids "$IDS" '
    def ours: (.id as $i | $ids | index($i)) or ((.filename // "") | startswith(env.PREFIX));
    if type == "object" and has("data") and (.data | type) == "array" then
      .data |= ([.[] | select(ours)] + ([.[] | select(ours | not)] | length | if . > 0 then ["(\(.) more rows: files on the shared provider key that this run did not upload, collapsed)"] else [] end))
    else . end'
}

The no-database master key list is every file on the shared OpenAI key, so the gist keeps only its row count

Before (c7c895d)

B on /anthropic/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/anthropic/v1/files -H "Authorization: Bearer $KEY_B"
  2. Observe the raw output, 54 lines of JSON

Other cases, before

B on /openai/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/openai/v1/files -H "Authorization: Bearer $KEY_B"
  2. Observe

    HTTP 200
    {
     "data": [],
     "has_more": false,
     "object": "list",
     "first_id": null,
     "last_id": null
    }
    

B on /v1/files?provider=anthropic

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?provider=anthropic" -H "Authorization: Bearer $KEY_B"
  2. Observe the raw output, 54 lines of JSON

B on /v1/files with custom-llm-provider: anthropic

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/v1/files -H "Authorization: Bearer $KEY_B" -H "custom-llm-provider: anthropic"
  2. Observe the raw output, 54 lines of JSON

B on /v1/files?target_model_names=litellm-qa-files-claude

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?target_model_names=litellm-qa-files-claude" -H "Authorization: Bearer $KEY_B"
  2. Observe the raw output, 54 lines of JSON

B on /v1/files with x-litellm-model: litellm-qa-files-claude

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/v1/files -H "Authorization: Bearer $KEY_B" -H "x-litellm-model: litellm-qa-files-claude"
  2. Observe the raw output, 54 lines of JSON

B on /azure/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/azure/v1/files -H "Authorization: Bearer $KEY_B"
  2. Observe

    HTTP 200
    {
     "data": [],
     "has_more": false,
     "object": "list",
     "first_id": null,
     "last_id": null
    }
    

B on /v1/files with no provider

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/v1/files -H "Authorization: Bearer $KEY_B"
  2. Observe

    HTTP 200
    {
     "object": "list",
     "data": [],
     "first_id": null,
     "last_id": null,
     "has_more": false
    }
    

B's gpt-only key asks for the Claude model's list

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?target_model_names=litellm-qa-files-claude" -H "Authorization: Bearer $KEY_C"
  2. Observe

    HTTP 403
    {
     "error": {
      "message": "The requested model 'litellm-qa-files-claude' is not available for this API key, or the model name is invalid. Check the models available to you and try again.",
      "type": "key_model_access_denied",
      "param": "model",
      "code": "403"
     }
    }
    

B with the OpenAI SDK

  1. Save openai_list.py

    import json, os
    from openai import OpenAI
    
    client = OpenAI(base_url=os.environ["B"] + "/openai/v1", api_key=os.environ["KEY"], max_retries=0)
    page = client.files.list()
    print(json.dumps({"data": [f.model_dump() for f in page.data], "has_more": page.has_more}))
  2. Run

    KEY=$KEY_B python3 openai_list.py
  3. Observe

    {
     "data": [],
     "has_more": false
    }
    

B with the Anthropic SDK

  1. Save anthropic_list.py

    import json, os
    from anthropic import Anthropic
    
    client = Anthropic(base_url=os.environ["B"] + "/anthropic", api_key=os.environ["KEY"], max_retries=0)
    page = client.beta.files.list()
    print(json.dumps({"data": [f.model_dump(mode="json") for f in page.data], "has_more": page.has_more}))
  2. Run

    KEY=$KEY_B python3 anthropic_list.py
  3. Observe the raw output, 66 lines of JSON

A on /openai/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/openai/v1/files -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 42 lines of JSON

A on /anthropic/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/anthropic/v1/files -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 54 lines of JSON

A on /v1/files?target_model_names=litellm-qa-files-gpt

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?target_model_names=litellm-qa-files-gpt" -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 42 lines of JSON

A on /v1/files with x-litellm-model: litellm-qa-files-claude

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/v1/files -H "Authorization: Bearer $KEY_A" -H "x-litellm-model: litellm-qa-files-claude"
  2. Observe the raw output, 54 lines of JSON

A on /v1/files with no provider

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/v1/files -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 119 lines of JSON

A on /v1/files?target_model_names=anthropic/claude-haiku-5-5, served by the anthropic/* wildcard

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?target_model_names=anthropic/claude-haiku-5-5" -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 54 lines of JSON

A on /azure/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/azure/v1/files -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 20 lines of JSON

A on /v1/files?target_model_names=litellm-qa-files-vllm, the model whose batch input LiteLLM stored

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?target_model_names=litellm-qa-files-vllm" -H "Authorization: Bearer $KEY_A"
  2. Observe

    HTTP 404
    {
     "error": {
      "message": "<!DOCTYPE HTML>\n<html lang=\"en\">\n    <head>\n        <meta charset=\"utf-8\">\n        <title>Error response</title>\n    </head>\n    <body>\n        <h1>Error response</h1>\n        <p>Error code: 404</p>\n        <p>Message: File not found.</p>\n        <p>Error code explanation: 404 - Nothing matches the given URI.</p>\n    </body>\n</html>",
      "type": "invalid_request_error",
      "param": null,
      "code": "404"
     }
    }
    

A on /v1/files?target_model_names=hosted_vllm/qwen-wild, the stored file's wildcard model

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?target_model_names=hosted_vllm/qwen-wild" -H "Authorization: Bearer $KEY_A"
  2. Observe

    HTTP 404
    {
     "error": {
      "message": "<!DOCTYPE HTML>\n<html lang=\"en\">\n    <head>\n        <meta charset=\"utf-8\">\n        <title>Error response</title>\n    </head>\n    <body>\n        <h1>Error response</h1>\n        <p>Error code: 404</p>\n        <p>Message: File not found.</p>\n        <p>Error code explanation: 404 - Nothing matches the given URI.</p>\n    </body>\n</html>",
      "type": "invalid_request_error",
      "param": null,
      "code": "404"
     }
    }
    

A on /v1/files?provider=hosted_vllm, those models' provider

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?provider=hosted_vllm" -H "Authorization: Bearer $KEY_A"
  2. Observe

    HTTP 404
    {
     "error": {
      "message": "<!DOCTYPE HTML>\n<html lang=\"en\">\n    <head>\n        <meta charset=\"utf-8\">\n        <title>Error response</title>\n    </head>\n    <body>\n        <h1>Error response</h1>\n        <p>Error code: 404</p>\n        <p>Message: File not found.</p>\n        <p>Error code explanation: 404 - Nothing matches the given URI.</p>\n    </body>\n</html>",
      "type": "invalid_request_error",
      "param": null,
      "code": "404"
     }
    }
    

A on /v1/files?provider=antropic, a misspelled provider in the query

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?provider=antropic" -H "Authorization: Bearer $KEY_A"
  2. Observe

    HTTP 500
    {
     "error": {
      "message": "'antropic' is not a valid LlmProviders",
      "type": "internal_server_error",
      "param": null,
      "code": "500"
     }
    }
    

A on /antropic/v1/files, a misspelled provider

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/antropic/v1/files -H "Authorization: Bearer $KEY_A"
  2. Observe

    HTTP 401
    {
     "error": {
      "message": "Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams. Route=/antropic/v1/files. Your role=internal_user. Your user_id=qa-fil*******-a",
      "type": "auth_error",
      "param": "None",
      "code": "401"
     }
    }
    

A pages /openai/v1/files, page 1

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/openai/v1/files?limit=1" -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 42 lines of JSON

A pages /openai/v1/files, page 2 with after=<page 1 last_id>

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/openai/v1/files?limit=1&after=$P1" -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 42 lines of JSON

A pages /anthropic/v1/files, page 1

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/anthropic/v1/files?limit=1" -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 54 lines of JSON

A pages /anthropic/v1/files, page 2 with after_id=<page 1 last_id>

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/anthropic/v1/files?limit=1&after_id=$P3" -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 54 lines of JSON

A sends two different cursors, after=U2 and after_id=U1

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/openai/v1/files?after=$U2&after_id=$U1" -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 42 lines of JSON

A sends both directions, after=U2 and before_id=U1

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?after=$U2&before_id=$U1" -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 20 lines of JSON

A auto-pages with the OpenAI SDK, limit=1

  1. Save openai_autopage.py

    import json, os
    from itertools import islice
    from openai import OpenAI
    
    client = OpenAI(base_url=os.environ["B"] + "/openai/v1", api_key=os.environ["KEY"], max_retries=0)
    seen = [f.id for f in islice(client.files.list(limit=1), 6)]
    print(json.dumps({"auto_paged_ids": seen, "stopped_on_its_own": len(seen) < 6}))
  2. Run

    KEY=$KEY_A python3 openai_autopage.py
  3. Observe the raw output, 8 lines of JSON

A auto-pages with the Anthropic SDK, limit=1

  1. Save anthropic_autopage.py

    import json, os
    from itertools import islice
    from anthropic import Anthropic
    
    client = Anthropic(base_url=os.environ["B"] + "/anthropic", api_key=os.environ["KEY"], max_retries=0)
    seen = [f.id for f in islice(client.beta.files.list(limit=1), 6)]
    print(json.dumps({"auto_paged_ids": seen, "stopped_on_its_own": len(seen) < 6}))
  2. Run

    KEY=$KEY_A python3 anthropic_autopage.py
  3. Observe

    {
     "auto_paged_ids": [
      "file_013mHwFp9fVFTfmrxCpbNRmZ",
      "file_019XovGmdECNhnwhFoy67tRw",
      "file_017H1BW36cuuaxFBQBjCkx8T",
      "file_018UuYinyxsV92UmXjKLAyn3",
      "file_01FuFs7NzzXC6XGLqA5btUnp",
      "file_012Uq84ombXhACHaYLThhDCQ"
     ],
     "stopped_on_its_own": false
    }
    

A pages backwards with the Anthropic SDK from U3, limit=1

  1. Save anthropic_before_id.py

    import json, os
    from itertools import islice
    from anthropic import Anthropic, APIStatusError
    
    client = Anthropic(base_url=os.environ["B"] + "/anthropic", api_key=os.environ["KEY"], max_retries=0)
    try:
        seen = [f.id for f in islice(client.beta.files.list(limit=1, before_id=os.environ["U3"]), 6)]
        print(json.dumps({"auto_paged_ids": seen, "stopped_on_its_own": len(seen) < 6}))
    except APIStatusError as e:
        print(json.dumps({"status_code": e.status_code, "error": e.body}))
  2. Run

    KEY=$KEY_A python3 anthropic_before_id.py
  3. Observe

    {
     "auto_paged_ids": [
      "file_013mHwFp9fVFTfmrxCpbNRmZ",
      "file_019XovGmdECNhnwhFoy67tRw",
      "file_017H1BW36cuuaxFBQBjCkx8T",
      "file_018UuYinyxsV92UmXjKLAyn3",
      "file_01FuFs7NzzXC6XGLqA5btUnp",
      "file_012Uq84ombXhACHaYLThhDCQ"
     ],
     "stopped_on_its_own": false
    }
    

A on /anthropic/v1/files, the alias's provider, after uploading U11

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/anthropic/v1/files -H "Authorization: Bearer $KEY_A"
  2. Observe

    HTTP 200
    {
     "object": "list",
     "data": [
      "(20 more rows: files on the shared provider key that this run did not upload, collapsed)"
     ],
     "first_id": "file_013mHwFp9fVFTfmrxCpbNRmZ",
     "last_id": "file_013nWKQmUDeZ8D9zJURvf5WN",
     "has_more": false
    }
    

A on /v1/files?target_model_names=litellm-qa-files-claude-alias

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?target_model_names=litellm-qa-files-claude-alias" -H "Authorization: Bearer $KEY_A"
  2. Observe

    HTTP 400
    {
     "error": {
      "message": "{'error': 'file list: Invalid model name passed in model=litellm-qa-files-claude-alias. Call `/v1/models` to view available models for your key.'}",
      "type": "invalid_request_error",
      "param": null,
      "code": "400"
     }
    }
    

A on /anthropic/v1/files, the routing group's provider, after uploading U12

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/anthropic/v1/files -H "Authorization: Bearer $KEY_A"
  2. Observe

    HTTP 200
    {
     "object": "list",
     "data": [
      "(20 more rows: files on the shared provider key that this run did not upload, collapsed)"
     ],
     "first_id": "file_013mHwFp9fVFTfmrxCpbNRmZ",
     "last_id": "file_013nWKQmUDeZ8D9zJURvf5WN",
     "has_more": false
    }
    

B on /anthropic/v1/files after A's alias and routing-group uploads

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/anthropic/v1/files -H "Authorization: Bearer $KEY_B"
  2. Observe

    HTTP 200
    {
     "object": "list",
     "data": [
      "(20 more rows: files on the shared provider key that this run did not upload, collapsed)"
     ],
     "first_id": "file_013mHwFp9fVFTfmrxCpbNRmZ",
     "last_id": "file_013nWKQmUDeZ8D9zJURvf5WN",
     "has_more": false
    }
    

Admin with the master key on /openai/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/openai/v1/files -H "Authorization: Bearer $MASTER_KEY"
  2. Observe the raw output, 42 lines of JSON

Admin with the master key on /anthropic/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/anthropic/v1/files -H "Authorization: Bearer $MASTER_KEY"
  2. Observe the raw output, 10 lines of JSON

D on /anthropic/v1/files with no limit

  1. Run

    curl -sS $B/anthropic/v1/files -H "Authorization: Bearer $KEY_D" | jq -c '{rows: (.data | length), has_more, rows_uploaded_by_d: ([.data[] | select((.filename // "") | startswith(env.PREFIX + "-d-"))] | length)}'
  2. Observe

    {"rows":20,"has_more":false,"rows_uploaded_by_d":20}
    

D on /v1/files with x-litellm-model: litellm-qa-files-claude and no limit

  1. Run

    curl -sS $B/v1/files -H "Authorization: Bearer $KEY_D" -H "x-litellm-model: litellm-qa-files-claude" | jq -c '{rows: (.data | length), has_more, rows_uploaded_by_d: ([.data[] | select((.filename // "") | startswith(env.PREFIX + "-d-"))] | length)}'
  2. Observe

    {"rows":20,"has_more":false,"rows_uploaded_by_d":20}
    

D on /v1/files with no limit

  1. Run

    curl -sS $B/v1/files -H "Authorization: Bearer $KEY_D" | jq -c '{rows: (.data | length), has_more, rows_uploaded_by_d: ([.data[] | select((.filename // "") | startswith(env.PREFIX + "-d-"))] | length)}'
  2. Observe

    {"rows":21,"has_more":false,"rows_uploaded_by_d":21}
    

Flag off, A on /v1/files with no cursor

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/v1/files -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 2 lines of JSON

Flag off, A on /v1/files with after=U2, after_id=U1 and before_id=U3

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?after=$U2&after_id=$U1&before_id=$U3" -H "Authorization: Bearer $KEY_A"
  2. Observe

    HTTP 200
    {"data":[{"id":"bGl0ZWxsbV9wcm94eTp0ZXh0L3BsYWluO3VuaWZpZWRfaWQsNjZiNWMxZTQtOWUwOC00MWU4LTkyNjAtMmY3NGE1ZDBjN2YyO3RhcmdldF9tb2RlbF9uYW1lcyxsaXRlbGxtLXFhLWZpbGVzLWdwdDtsbG1fb3V0cHV0X2ZpbGVfaWQsZmlsZS1GU3NCcE5jcFhtV3M3TXN5cDk4VTZIO2xsbV9vdXRwdXRfZmlsZV9tb2RlbF9pZCwzMTlkMmE1ZWUxODBkZGY2MGFkNmQ3YWQ1NDc3MGRkMmRmNmM1ZDY0Nzg5YTVhOGUzM2FjMzlmZWZiMTM0NTdj","filename":"qa-files-qa-base-9baebb-gpt-older.txt"}],"has_more":false,"error":null}
    

No database, Admin uploads with the master key to /openai/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/openai/v1/files -H "Authorization: Bearer $MASTER_KEY" -F purpose=user_data -F target_model_names=litellm-qa-files-gpt -F file=@qa-files-qa-base-9baebb-nodb.txt
  2. Observe

    HTTP 500
    {"error":{"message":"Managed files hook not found","type":"internal_server_error","param":null,"code":"500"}}
    

No database, Admin with the master key on /openai/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/openai/v1/files -H "Authorization: Bearer $MASTER_KEY"
  2. Observe

    HTTP 200
    {"rows": 5488, "has_more": true, "note": "every file on the shared OpenAI key, collapsed to a count"}
    

Timing, B on /anthropic/v1/files, run 1

  1. Run

    curl -sS -o body.json -w '%{http_code} %{time_total}s\n' $B/anthropic/v1/files -H "Authorization: Bearer $KEY_B"; jq -c '{rows: (.data | length), has_more}' body.json
  2. Observe

    200 0.221313s
    {"rows":20,"has_more":false}
    

Timing, B on /anthropic/v1/files, run 2

  1. Run

    curl -sS -o body.json -w '%{http_code} %{time_total}s\n' $B/anthropic/v1/files -H "Authorization: Bearer $KEY_B"; jq -c '{rows: (.data | length), has_more}' body.json
  2. Observe

    200 0.151214s
    {"rows":20,"has_more":false}
    

Timing, B on /anthropic/v1/files, run 3

  1. Run

    curl -sS -o body.json -w '%{http_code} %{time_total}s\n' $B/anthropic/v1/files -H "Authorization: Bearer $KEY_B"; jq -c '{rows: (.data | length), has_more}' body.json
  2. Observe

    200 0.171650s
    {"rows":20,"has_more":false}
    

After (e6edd7e)

B on /anthropic/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/anthropic/v1/files -H "Authorization: Bearer $KEY_B"
  2. Observe

    HTTP 200
    {
     "object": "list",
     "data": [],
     "first_id": null,
     "last_id": null,
     "has_more": false
    }
    
Other cases, after

B on /openai/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/openai/v1/files -H "Authorization: Bearer $KEY_B"
  2. Observe

    HTTP 200
    {
     "object": "list",
     "data": [],
     "first_id": null,
     "last_id": null,
     "has_more": false
    }
    

B on /v1/files?provider=anthropic

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?provider=anthropic" -H "Authorization: Bearer $KEY_B"
  2. Observe

    HTTP 200
    {
     "object": "list",
     "data": [],
     "first_id": null,
     "last_id": null,
     "has_more": false
    }
    

B on /v1/files with custom-llm-provider: anthropic

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/v1/files -H "Authorization: Bearer $KEY_B" -H "custom-llm-provider: anthropic"
  2. Observe

    HTTP 200
    {
     "object": "list",
     "data": [],
     "first_id": null,
     "last_id": null,
     "has_more": false
    }
    

B on /v1/files?target_model_names=litellm-qa-files-claude

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?target_model_names=litellm-qa-files-claude" -H "Authorization: Bearer $KEY_B"
  2. Observe

    HTTP 200
    {
     "object": "list",
     "data": [],
     "first_id": null,
     "last_id": null,
     "has_more": false
    }
    

B on /v1/files with x-litellm-model: litellm-qa-files-claude

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/v1/files -H "Authorization: Bearer $KEY_B" -H "x-litellm-model: litellm-qa-files-claude"
  2. Observe

    HTTP 200
    {
     "object": "list",
     "data": [],
     "first_id": null,
     "last_id": null,
     "has_more": false
    }
    

B on /azure/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/azure/v1/files -H "Authorization: Bearer $KEY_B"
  2. Observe

    HTTP 200
    {
     "object": "list",
     "data": [],
     "first_id": null,
     "last_id": null,
     "has_more": false
    }
    

B on /v1/files with no provider

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/v1/files -H "Authorization: Bearer $KEY_B"
  2. Observe

    HTTP 200
    {
     "object": "list",
     "data": [],
     "first_id": null,
     "last_id": null,
     "has_more": false
    }
    

B's gpt-only key asks for the Claude model's list

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?target_model_names=litellm-qa-files-claude" -H "Authorization: Bearer $KEY_C"
  2. Observe

    HTTP 403
    {
     "error": {
      "message": "The requested model 'litellm-qa-files-claude' is not available for this API key, or the model name is invalid. Check the models available to you and try again.",
      "type": "key_model_access_denied",
      "param": "model",
      "code": "403"
     }
    }
    

B with the OpenAI SDK

  1. Save openai_list.py

    import json, os
    from openai import OpenAI
    
    client = OpenAI(base_url=os.environ["B"] + "/openai/v1", api_key=os.environ["KEY"], max_retries=0)
    page = client.files.list()
    print(json.dumps({"data": [f.model_dump() for f in page.data], "has_more": page.has_more}))
  2. Run

    KEY=$KEY_B python3 openai_list.py
  3. Observe

    {
     "data": [],
     "has_more": false
    }
    

B with the Anthropic SDK

  1. Save anthropic_list.py

    import json, os
    from anthropic import Anthropic
    
    client = Anthropic(base_url=os.environ["B"] + "/anthropic", api_key=os.environ["KEY"], max_retries=0)
    page = client.beta.files.list()
    print(json.dumps({"data": [f.model_dump(mode="json") for f in page.data], "has_more": page.has_more}))
  2. Run

    KEY=$KEY_B python3 anthropic_list.py
  3. Observe

    {
     "data": [],
     "has_more": false
    }
    

A on /openai/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/openai/v1/files -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 42 lines of JSON

A on /anthropic/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/anthropic/v1/files -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 53 lines of JSON

A on /v1/files?target_model_names=litellm-qa-files-gpt

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?target_model_names=litellm-qa-files-gpt" -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 31 lines of JSON

A on /v1/files with x-litellm-model: litellm-qa-files-claude

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/v1/files -H "Authorization: Bearer $KEY_A" -H "x-litellm-model: litellm-qa-files-claude"
  2. Observe the raw output, 31 lines of JSON

A on /v1/files with no provider

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/v1/files -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 119 lines of JSON

A on /v1/files?target_model_names=anthropic/claude-haiku-5-5, served by the anthropic/* wildcard

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?target_model_names=anthropic/claude-haiku-5-5" -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 20 lines of JSON

A on /azure/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/azure/v1/files -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 20 lines of JSON

A on /v1/files?target_model_names=litellm-qa-files-vllm, the model whose batch input LiteLLM stored

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?target_model_names=litellm-qa-files-vllm" -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 20 lines of JSON

A on /v1/files?target_model_names=hosted_vllm/qwen-wild, the stored file's wildcard model

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?target_model_names=hosted_vllm/qwen-wild" -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 20 lines of JSON

A on /v1/files?provider=hosted_vllm, those models' provider

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?provider=hosted_vllm" -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 31 lines of JSON

A on /v1/files?provider=antropic, a misspelled provider in the query

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?provider=antropic" -H "Authorization: Bearer $KEY_A"
  2. Observe

    HTTP 400
    {
     "error": {
      "message": "Unknown provider 'antropic' for listing files.",
      "type": "invalid_request_error",
      "param": null,
      "code": "400"
     }
    }
    

A on /antropic/v1/files, a misspelled provider

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/antropic/v1/files -H "Authorization: Bearer $KEY_A"
  2. Observe

    HTTP 401
    {
     "error": {
      "message": "Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams. Route=/antropic/v1/files. Your role=internal_user. Your user_id=qa-fil*******-a",
      "type": "auth_error",
      "param": "None",
      "code": "401"
     }
    }
    

A pages /openai/v1/files, page 1

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/openai/v1/files?limit=1" -H "Authorization: Bearer $KEY_A"
  2. Observe

    HTTP 200
    {
     "object": "list",
     "data": [
      {
       "id": "bGl0ZWxsbV9wcm94eTpwYXNzdGhyb3VnaDtwcm92aWRlcjpvcGVuYWk7dW5pZmllZF9pZCxiZGFlOTQyOC0wODkxLTQ0N2MtOGEwZS01NmVmMWY2MmY0MTM7cmF3X2lkLGZpbGUtRGtCeFBUUlNVbWhkOEUzY1Q1Y1labg",
       "bytes": 56,
       "created_at": 1793207104,
       "filename": "qa-files-qa-head-cdd358-passthrough.txt",
       "object": "file",
       "purpose": "user_data",
       "status": "processed",
       "expires_at": null,
       "status_details": null
      }
     ],
     "first_id": "bGl0ZWxsbV9wcm94eTpwYXNzdGhyb3VnaDtwcm92aWRlcjpvcGVuYWk7dW5pZmllZF9pZCxiZGFlOTQyOC0wODkxLTQ0N2MtOGEwZS01NmVmMWY2MmY0MTM7cmF3X2lkLGZpbGUtRGtCeFBUUlNVbWhkOEUzY1Q1Y1labg",
     "last_id": "bGl0ZWxsbV9wcm94eTpwYXNzdGhyb3VnaDtwcm92aWRlcjpvcGVuYWk7dW5pZmllZF9pZCxiZGFlOTQyOC0wODkxLTQ0N2MtOGEwZS01NmVmMWY2MmY0MTM7cmF3X2lkLGZpbGUtRGtCeFBUUlNVbWhkOEUzY1Q1Y1labg",
     "has_more": true
    }
    

A pages /openai/v1/files, page 2 with after=<page 1 last_id>

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/openai/v1/files?limit=1&after=$P1" -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 20 lines of JSON

A pages /anthropic/v1/files, page 1

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/anthropic/v1/files?limit=1" -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 20 lines of JSON

A pages /anthropic/v1/files, page 2 with after_id=<page 1 last_id>

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/anthropic/v1/files?limit=1&after_id=$P3" -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 20 lines of JSON

A sends two different cursors, after=U2 and after_id=U1

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/openai/v1/files?after=$U2&after_id=$U1" -H "Authorization: Bearer $KEY_A"
  2. Observe

    HTTP 400
    {
     "error": {
      "message": "Pass the list cursor as either 'after' or 'after_id', not both with different ids.",
      "type": "invalid_request_error",
      "param": null,
      "code": "400"
     }
    }
    

A sends both directions, after=U2 and before_id=U1

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?after=$U2&before_id=$U1" -H "Authorization: Bearer $KEY_A"
  2. Observe

    HTTP 400
    {
     "error": {
      "message": "Pass either 'after' (or 'after_id') or 'before_id' when listing files, not both.",
      "type": "invalid_request_error",
      "param": "before_id",
      "code": "400"
     }
    }
    

A auto-pages with the OpenAI SDK, limit=1

  1. Save openai_autopage.py

    import json, os
    from itertools import islice
    from openai import OpenAI
    
    client = OpenAI(base_url=os.environ["B"] + "/openai/v1", api_key=os.environ["KEY"], max_retries=0)
    seen = [f.id for f in islice(client.files.list(limit=1), 6)]
    print(json.dumps({"auto_paged_ids": seen, "stopped_on_its_own": len(seen) < 6}))
  2. Run

    KEY=$KEY_A python3 openai_autopage.py
  3. Observe the raw output, 8 lines of JSON

A auto-pages with the Anthropic SDK, limit=1

  1. Save anthropic_autopage.py

    import json, os
    from itertools import islice
    from anthropic import Anthropic
    
    client = Anthropic(base_url=os.environ["B"] + "/anthropic", api_key=os.environ["KEY"], max_retries=0)
    seen = [f.id for f in islice(client.beta.files.list(limit=1), 6)]
    print(json.dumps({"auto_paged_ids": seen, "stopped_on_its_own": len(seen) < 6}))
  2. Run

    KEY=$KEY_A python3 anthropic_autopage.py
  3. Observe the raw output, 9 lines of JSON

A pages backwards with the Anthropic SDK from U3, limit=1

  1. Save anthropic_before_id.py

    import json, os
    from itertools import islice
    from anthropic import Anthropic, APIStatusError
    
    client = Anthropic(base_url=os.environ["B"] + "/anthropic", api_key=os.environ["KEY"], max_retries=0)
    try:
        seen = [f.id for f in islice(client.beta.files.list(limit=1, before_id=os.environ["U3"]), 6)]
        print(json.dumps({"auto_paged_ids": seen, "stopped_on_its_own": len(seen) < 6}))
    except APIStatusError as e:
        print(json.dumps({"status_code": e.status_code, "error": e.body}))
  2. Run

    KEY=$KEY_A python3 anthropic_before_id.py
  3. Observe the raw output, 8 lines of JSON

A on /anthropic/v1/files, the alias's provider, after uploading U11

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/anthropic/v1/files -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 64 lines of JSON

A on /v1/files?target_model_names=litellm-qa-files-claude-alias

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?target_model_names=litellm-qa-files-claude-alias" -H "Authorization: Bearer $KEY_A"
  2. Observe

    HTTP 400
    {
     "error": {
      "message": "{'error': 'file list: Invalid model name passed in model=litellm-qa-files-claude-alias. Call `/v1/models` to view available models for your key.'}",
      "type": "invalid_request_error",
      "param": null,
      "code": "400"
     }
    }
    

A on /anthropic/v1/files, the routing group's provider, after uploading U12

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/anthropic/v1/files -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 75 lines of JSON

B on /anthropic/v1/files after A's alias and routing-group uploads

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/anthropic/v1/files -H "Authorization: Bearer $KEY_B"
  2. Observe

    HTTP 200
    {
     "object": "list",
     "data": [],
     "first_id": null,
     "last_id": null,
     "has_more": false
    }
    

Admin with the master key on /openai/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/openai/v1/files -H "Authorization: Bearer $MASTER_KEY"
  2. Observe the raw output, 42 lines of JSON

Admin with the master key on /anthropic/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/anthropic/v1/files -H "Authorization: Bearer $MASTER_KEY"
  2. Observe the raw output, 54 lines of JSON

D on /anthropic/v1/files with no limit

  1. Run

    curl -sS $B/anthropic/v1/files -H "Authorization: Bearer $KEY_D" | jq -c '{rows: (.data | length), has_more, rows_uploaded_by_d: ([.data[] | select((.filename // "") | startswith(env.PREFIX + "-d-"))] | length)}'
  2. Observe

    {"rows":20,"has_more":true,"rows_uploaded_by_d":20}
    

D on /v1/files with x-litellm-model: litellm-qa-files-claude and no limit

  1. Run

    curl -sS $B/v1/files -H "Authorization: Bearer $KEY_D" -H "x-litellm-model: litellm-qa-files-claude" | jq -c '{rows: (.data | length), has_more, rows_uploaded_by_d: ([.data[] | select((.filename // "") | startswith(env.PREFIX + "-d-"))] | length)}'
  2. Observe

    {"rows":20,"has_more":true,"rows_uploaded_by_d":20}
    

D on /v1/files with no limit

  1. Run

    curl -sS $B/v1/files -H "Authorization: Bearer $KEY_D" | jq -c '{rows: (.data | length), has_more, rows_uploaded_by_d: ([.data[] | select((.filename // "") | startswith(env.PREFIX + "-d-"))] | length)}'
  2. Observe

    {"rows":21,"has_more":false,"rows_uploaded_by_d":21}
    

Flag off, A on /v1/files with no cursor

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/v1/files -H "Authorization: Bearer $KEY_A"
  2. Observe the raw output, 2 lines of JSON

Flag off, A on /v1/files with after=U2, after_id=U1 and before_id=U3

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' "$B/v1/files?after=$U2&after_id=$U1&before_id=$U3" -H "Authorization: Bearer $KEY_A"
  2. Observe

    HTTP 200
    {"data":[{"id":"bGl0ZWxsbV9wcm94eTp0ZXh0L3BsYWluO3VuaWZpZWRfaWQsNjRlYTA3OTItMGEzMi00MDAyLTg4ODktMDE3Nzk2ZmU2NjM0O3RhcmdldF9tb2RlbF9uYW1lcyxsaXRlbGxtLXFhLWZpbGVzLWdwdDtsbG1fb3V0cHV0X2ZpbGVfaWQsZmlsZS1OWHA5SkNXbmJ6WUZXczI2alhGZHlhO2xsbV9vdXRwdXRfZmlsZV9tb2RlbF9pZCwzMTlkMmE1ZWUxODBkZGY2MGFkNmQ3YWQ1NDc3MGRkMmRmNmM1ZDY0Nzg5YTVhOGUzM2FjMzlmZWZiMTM0NTdj","filename":"qa-files-qa-head-cdd358-gpt-older.txt"}],"has_more":false,"error":null}
    

No database, Admin uploads with the master key to /openai/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/openai/v1/files -H "Authorization: Bearer $MASTER_KEY" -F purpose=user_data -F target_model_names=litellm-qa-files-gpt -F file=@qa-files-qa-head-cdd358-nodb.txt
  2. Observe

    HTTP 500
    {"error":{"message":"Managed files hook not found","type":"internal_server_error","param":null,"code":"500"}}
    

No database, Admin with the master key on /openai/v1/files

  1. Run

    curl -sS -w '\nHTTP %{http_code}\n' $B/openai/v1/files -H "Authorization: Bearer $MASTER_KEY"
  2. Observe

    HTTP 200
    {"rows": 5488, "has_more": true, "note": "every file on the shared OpenAI key, collapsed to a count"}
    

Timing, B on /anthropic/v1/files, run 1

  1. Run

    curl -sS -o body.json -w '%{http_code} %{time_total}s\n' $B/anthropic/v1/files -H "Authorization: Bearer $KEY_B"; jq -c '{rows: (.data | length), has_more}' body.json
  2. Observe

    200 0.212411s
    {"rows":0,"has_more":false}
    

Timing, B on /anthropic/v1/files, run 2

  1. Run

    curl -sS -o body.json -w '%{http_code} %{time_total}s\n' $B/anthropic/v1/files -H "Authorization: Bearer $KEY_B"; jq -c '{rows: (.data | length), has_more}' body.json
  2. Observe

    200 0.078940s
    {"rows":0,"has_more":false}
    

Timing, B on /anthropic/v1/files, run 3

  1. Run

    curl -sS -o body.json -w '%{http_code} %{time_total}s\n' $B/anthropic/v1/files -H "Authorization: Bearer $KEY_B"; jq -c '{rows: (.data | length), has_more}' body.json
  2. Observe

    200 0.076450s
    {"rows":0,"has_more":false}
    

Observations from the runs

  • Main's full Anthropic page says has_more false
  • An alias in target_model_names answers 400 on main too

/live-pr-risk at e6edd7e

I ran /live-pr-risk on the GCE box with real Postgres, two uvicorn workers per proxy, and real Anthropic, OpenAI and Azure calls, comparing the merge base c7c895d with the head. The same 40 cells gave the same results on GitHub's merge ref 5ed6242. The full report has every caller row, the dependency graph and the integration suites

No dependent path that answered correctly on base fails on head, and every backward-incompatible change below was in the code kerry-berri approved

Paths covered, backward-incompatible changes, and risks

It covered the paths the /qa cases and unit tests do not reach. These are team members, team service-account keys, keys with no user or team, both viewer roles, DB-stored deployments over two workers, a routing group over OpenAI and Azure, a deployment deleted after an upload, a github_copilot deployment, hostile cursors, and the index migration through prisma migrate deploy with a rollback to base

Backward incompatible

All of these apply only with require_managed_files on, and only to callers without an admin role. Provider and model lists hold only the caller's own and team managed files, internal_user_viewer gets an empty list there, and the lists come back newest first. purpose=bogus on /anthropic/v1/files answers 400 where Anthropic used to ignore it, and an unknown after, after_id or before_id answers 400 "no file found with id". Another user's id as a cursor gets that same 400, so it does not reveal whether a file exists. A file whose deployment was deleted drops out of the provider list but stays on /v1/files, and its content already answered 400 on both legs. The purpose and cursor checks already run on /v1/files on main, and this PR applies them to provider lists too. Every change in this paragraph was already in the code kerry-berri approved at 03cb854 in his review

Regression risk

The provider scope looks up each deployment's provider on every scoped list call. For a github_copilot or chatgpt deployment that reads the token file, and an expired token would be refreshed over the network inside the request, which the router avoids through declared_authenticating_provider. A stored model_mappings value that is not a JSON object would 500 the page, though no writer stores one

Not verified

Batch output files from a real finished batch, files written by fine-tuning or container flows, /azure_ai pass-through uploads, Azure deployments of non-OpenAI models, an expired github_copilot token, and require_managed_files without the managed files hook

Type

🐛 Bug Fix
✅ Test

Caveats (if any)

Medium

  • A pre-existing gap went to security engineering

Low

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
Bugbot summary

[!NOTE]
Medium Risk
Changes authenticated file-list behavior and adds raw SQL on managed file rows—a security-sensitive path, though scoped behind require_managed_files with extensive tests.

Overview
When require_managed_files is enabled, non-admin GET /v1/files requests that name a provider or model no longer forward to the shared provider API. They list only the caller’s (and team’s) rows from LiteLLM_ManagedFileTable, with admin behavior unchanged.

The proxy resolves scope from path, provider, headers, target_model_names, or model routing, builds a FileListModelScope, and calls the managed-files hook with after / after_id / before_id paging (newest-first; before_id pages toward newer rows). Provider/model filtering uses raw SQL on model_mappings (plus router checks for storage-backed files); purpose still filters in memory. Anthropic-scoped lists default to limit=20. Invalid cursors, unknown providers, and missing managed-files hook fail with 400/500 instead of leaking shared-key listings.

Adds a (created_by, created_at DESC) index (concurrent migration) and broad unit/integration coverage for isolation, paging, wildcards, and passthrough markers.

Reviewed by Cursor Bugbot for commit e6edd7e. Bugbot is set up for automated code reviews on this repo. Configure here.

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

@kerry-berri

kerry-berri commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

litellm-stampbot: risk low

Approved at 03cb854.

Rules (stampbot/risk_rules.yml):

  • low: 0 changed source lines (only tests, docs, cookbook, markdown or the cost map changed), approved without asking Bugbot or the judge

Judge: skipped, the rules alone decided.

Pushes do not re-run this check. Comment @litellm-stampbot again to re-check the new head.

@kerry-berri kerry-berri added the risk:low Small, isolated, low-risk change label Oct 20, 2026

@kerry-berri kerry-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low risk by rule and by judgement at 03cb854

@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.90244% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...lm/proxy/openai_files_endpoints/files_endpoints.py 94.11% 6 Missing ⚠️
...se/litellm_enterprise/proxy/hooks/managed_files.py 91.11% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mateo-berri mateo-berri changed the title fix(files): list only the caller's managed files on every list route under require_managed_files fix(files)!: list only the caller's managed files on every list route under require_managed_files Oct 21, 2026
@codspeed

codspeed Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 35 untouched benchmarks


Comparing litellm_scope_provider_file_list_to_owner (e6edd7e) with main (086daf4)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (8c9a768) during the generation of this report, so 086daf4 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@litereview

litereview Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

⚠️ code-review

5/5 · Ready for human review

Scope: full · Full PR review.

Completed · Some checks not run.

No correctness findings.

I reviewed the full range 6083cf97 to 03859487. Under require_managed_files, provider, model, header and target_model_names lists now go through the managed-files hook, filtered to the caller's own rows. Keyset paging covers after, after_id and before_id. The breaking change has the fix(files)!: marker and a stated impact. The earlier wildcard finding stays fixed at this head.

Checks and execution details
  • Passed · Real testing evidence (required): Not applicable: no LLM translation changes in the scoped paths.

The only scoped file is litellm/llms/base_llm/files/transformation.py. That diff adds the model_mapping_keys and before keyword parameters to the abstract BaseFileEndpoints.afile_list hook signature. It does not change how requests, responses, streaming or errors translate between providers. The rest of the change sits in litellm/proxy/** and enterprise/**.

  • Passed · Compatibility requirements (required): There is a real break, and the notice is in place.

These changes apply only with require_managed_files: true:

  • GET /anthropic/v1/files with a non-admin key used to return every file on the shared provider key. It now returns only the caller's managed files.
  • The master key now gets managed files instead of the raw provider list, sorted newest first. The OpenAI list used to be oldest first.
  • A non-admin list without the managed-files hook now returns 500 instead of the provider list.
  • ?provider=antropic now returns 400.
  • An Anthropic list with no limit now returns 20 rows by default.

The title carries fix(files)!:. The description's "Breaking change:" line and its Design decisions spell out each behavior change. The description also says that with the flag off, lists behave as on main, which is the fallback for anyone who needs raw lists.

  • Passed · Changed behavior and result consistency (required): Standards read: root and tests/integration/AGENTS.md (integration tests run on CircleCI only after merge).

Paths traced: list_files → list_owned_files_only gate (flag on, plus hook loaded or non-admin) → _listed_model_mapping_keys. That function checks a routed model first (already authorized by handle_model_based_routing), then target_model_names (with get_authorized_credentials_for_model), then the provider from the path, header, query or body. The result goes to ManagedFiles.afile_list, which applies the owner filter, the cursor row check, asc order plus a reversed page for before, and the model_mappings key filter, then builds the page via build_list_page.

Boundary cases checked:

  • An empty key set returns an empty page.
  • after together with before returns 400.
  • after and after_id with different ids returns 400.
  • An unknown provider returns 400.
  • An admin without the hook falls through to the legacy branch, which is unchanged.
  • With the flag off, the legacy branches keep ignoring after_id and before_id.

Executed reproducer (/tmp/wc.py) on this head, with a wildcard anthropic/* deployment plus an OpenAI deployment:

  • _model_mapping_keys_serving_model(..., 'anthropic/claude-haiku-4-5') includes the wildcard deployment id.
  • The provider anthropic set includes the same id.
  • antropic returns _UnscopedFileList(400).
  • The openai set includes _passthrough_openai.

Tests: tests/unit/proxy/openai_files_endpoint/test_files_endpoint.py and tests/unit/enterprise/proxy/test_managed_files_hook.py give 271 passed, 2 skipped. I had to run prisma generate first, because the setup environment lacked a generated client.

The new integration file tests/integration/security/test_managed_file_listing.py covers the intruder and owner cases across all five list forms, limit plus cursor paging, Anthropic SDK forward and backward auto-paging, and the master key. I did not run it locally because it needs the integration proxy stack. The PR's linked gist shows real OpenAI, Anthropic and Azure runs at head 03859487.

  • Passed · Unit tests for files endpoint and managed files hook (optional): Command: .venv/bin/python -m pytest tests/unit/proxy/openai_files_endpoint/test_files_endpoint.py tests/unit/enterprise/proxy/test_managed_files_hook.py -n 8

Result: 271 passed, 2 skipped. I ran prisma generate --schema litellm/proxy/schema.prisma first. Without it, 6 hook tests fail with ImportError: cannot import name 'Json' from 'prisma', which is an environment problem unrelated to this PR.

  • Not run · Integration test test_managed_file_listing.py (optional): Not run. It needs INTEGRATION_PROXY_URL, Postgres and the owned-proxy harness. Per tests/integration/AGENTS.md, it first runs in CircleCI on main.

View review · Reviewed 03859487e4b5

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@greptile-apps

greptile-apps Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the previous alias-listing issue fixed and no new blocking findings.

Summary

With require_managed_files enabled, non-admin provider and model lists return the caller's own and team managed files, with paging support. Admin lists keep their existing behavior.

The latest change fixes the previous finding by including storage-backed uploads made through aliases and routing groups. The updated tests cover both cases. No new actionable issues were found.

  • With managed files on, provider and model lists show only caller-owned or team files.
  • Managed file lists page newest first and support Anthropic's cursor names.

Reviews (5) · Last reviewed commit: "fix(files): list alias and routing-group..." · Reviewed by Greptile

…der or model and page with after_id and before_id
@mateo-berri mateo-berri changed the title fix(files)!: list only the caller's managed files on every list route under require_managed_files fix(files): scope provider and model file lists to the caller's managed files under require_managed_files Oct 21, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

or await get_custom_llm_provider_from_request_body(request=request)
)


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium · Model-filtered file list returns empty for the owner's own files on wildcard deployments

  1. The proxy runs with require_managed_files: true and has a single wildcard deployment, model_name: anthropic/*.
  2. User A uploads with target_model_names=anthropic/claude-haiku-4-5. The router resolves the wildcard and stores model_mappings = {&lt;wildcard deployment id>: file_...}.
  3. User A then sends GET /v1/files?target_model_names=anthropic/claude-haiku-4-5, or sets the same model in x-litellm-model. get_authorized_credentials_for_model accepts the model. _deployment_ids_serving_model then calls llm_router.get_model_ids(model_name=...). That call only checks the exact model_name index, so it returns an empty set.
  4. In afile_list, deployment_ids.isdisjoint(row.model_mappings) is true for every row. A gets "data": [] even though the file is A's own upload on that deployment.

Team public model names have the same gap, because get_model_ids does not consult team_model_to_deployment_indices. To fix it, resolve deployment ids the same way upload routing does: exact name, team public name, then wildcard pattern_router.route(...), collecting model_info.id from each match.

Evidence

Reproducer (executed on the PR checkout, /tmp/wc.py):

r = Router(model_list=[{"model_name":"anthropic/*","litellm_params":{"model":"anthropic/*","api_key":"sk-x"}}])
deps = await r.async_get_healthy_deployments(model="anthropic/claude-haiku-4-5", ...)
add_model_file_id_mappings(deps, [F()])
_deployment_ids_serving_model(r, "anthropic/claude-haiku-4-5")
_deployment_ids_on_provider(r, "anthropic")

Output:

upload model_mappings: {'6cd11d07...e84b': 'file_abc'}
list by model: frozenset()
list by provider: frozenset({'6cd11d07...e84b'})

Access check passes for the same model (/tmp/wc2.py): get_authorized_credentials_for_model(..., model_id="anthropic/claude-haiku-4-5") returns provider anthropic, so the request reaches the empty filter. It is not rejected with 403/404.

Router.get_model_ids(model_name=...) (litellm/router.py:12778) reads only model_name_to_deployment_indices. get_credential_deployment (router.py:11851) also checks team public names and wildcard patterns. Upload uses that broader resolution.

New tests (_callers_files_on_every_deployment, integration test_managed_file_listing.py) cover only exact model_name deployments, so they cannot catch this case.

Latest summary by code-review · View this review · Reviewed 2cb4bb5cb563

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6643800, which matches every deployment serving the model, wildcards included. Team public names already answer 400 at the access check on base

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finding withdrawn

The reply is correct.

  • Wildcard case: _deployment_ids_serving_model now uses llm_router.get_model_list(model_name=model), which includes _get_wildcard_deployments, in place of get_model_ids. A list filtered by anthropic/claude-haiku-4-5 now returns the same wildcard deployment id that upload stores in model_mappings. The owner sees their own file.
  • Team public name: this case fails at the access check. get_credentials_for_model calls get_deployment_credentials_with_provider without a team_id, so the lookup finds no deployment and the request fails with a 400. It never reaches the deployment_ids filter and never returns a silent "data": []. The original finding's description of this case does not apply.
Evidence

litellm/proxy/openai_files_endpoints/files_endpoints.py:1723-1726:

def _deployment_ids_serving_model(llm_router: Router, model: str) -> frozenset[str]:
    if llm_router.has_model_id(model):
        return frozenset((model,))
    return _deployment_ids(llm_router.get_model_list(model_name=model) or ())

Router.get_model_list (litellm/router.py ~13545) also appends _get_wildcard_deployments(model_name=...).

Reproducer /tmp/wc.py on head 66438008:

upload ids ['6cd11d0786de...fe84b']
by model frozenset({'6cd11d0786de...fe84b'})
by provider frozenset({'6cd11d0786de...fe84b'})

Reproducer /tmp/tp.py (team deployment with team_public_model_name=my-claude, key in team1):

serving frozenset()
raised ProxyModelNotFoundError 400 ... 'file list: Invalid model name passed in model=my-claude.'

_listed_deployment_ids calls get_authorized_credentials_for_model before _deployment_ids_serving_model (files_endpoints.py:1776-1782).

tests/unit/proxy/openai_files_endpoint/test_files_endpoint.py::test_require_managed_files_lists_the_callers_files_wherever_the_router_put_them: the wildcard-target-model-names and wildcard-model-header cases assert ["unified-wildcard"]. Run result: 4 passed.

GitHub does not allow this App to resolve this thread. A repository maintainer must do it manually.

Reviewed 66438008a1f0 · View follow-up

…ts that cannot be scoped

A model name now matches every deployment that serves it, wildcards and
aliases included, and a provider matches deployments by the provider
uploads resolve, so anthropic/* and unprefixed Claude models count. The
OpenAI and Azure lists also return the caller's pass-through uploads.
An unknown provider and different after and after_id cursors answer 400,
and a list with no matching deployment skips the database read.
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@mateo-berri mateo-berri changed the title fix(files): scope provider and model file lists to the caller's managed files under require_managed_files fix(files)!: scope provider and model file lists to the caller's managed files under require_managed_files Oct 21, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

…as on main

Under require_managed_files, a narrowed list now matches a file's model
mappings by deployment id or model name, so files LiteLLM stores in its own
database show on their model and provider lists. The Anthropic list defaults
to 20 rows when no limit is sent, after_id, before_id and the cursor 400s
apply only under the flag, and an admin keeps the provider list when the
managed files hook is not loaded. List errors are returned as values and
mapped to HTTP errors in one place.
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview guide

@litereview

litereview Bot commented Oct 21, 2026

Copy link
Copy Markdown

⚠️ guide

Open preview

Scope: full · Full PR review.

Completed · Some checks not run.

Today, with require_managed_files on, any user who asks for the Anthropic file list gets 200 with every file on the shared provider key. That includes other users' uploads, with their file names and raw file_01... ids. The Anthropic SDK's paging also never stops.

The walkthrough, one request (user B lists Anthropic files):

  1. User A uploads a note for a Claude model through /anthropic/v1/files. This is the same both ways.
  2. User B calls GET /anthropic/v1/files with their own key. Same both ways.
  3. The proxy accepts B's key. Same both ways.
  4. The proxy picks where to read the list. This is where it breaks: it reads from the shared Anthropic key. This is also where it's fixed: it now reads only B's managed file records on Anthropic deployments.
  5. Paging. Before, limit, after, after_id and before_id were ignored and the SDK looped. After, pages come newest first and stop at the end.
  6. B gets the answer. Before, it was A's file names and ids. After, it's "data": [].

What changes for the caller: with the flag on, every list that names a provider or model (path, ?provider=, custom-llm-provider, target_model_names, x-litellm-model) returns only the caller's own managed files, newest first. The master key also gets managed files here, not raw provider rows. There are also new error codes:

  • An unknown provider gets 400.
  • Mixing cursors (before_id with after, or two different after values) gets 400.
  • A missing managed files hook gets 500 for normal keys.

Tests added: 7 integration tests in tests/integration/security/test_managed_file_listing.py, covering isolation, owner lists, cursor paging, SDK paging both ways and the master key. Also 11 endpoint unit tests and 1 hook unit test. I ran the touched unit tests: 33 endpoint tests and 38 hook tests passed. I did not run the integration suite.

Black box coverage: Nay. Isolation and paging are covered by the integration tests. These are not:

  • Files placed through an anthropic/* wildcard or a bare Claude name.
  • Pass-through uploads showing up in /openai/v1/files.
  • The 500 when the managed files hook is missing.
  • The 400 errors.
  • The default of 20 files per page on Anthropic lists.
Checks and execution details
  • Passed · Endpoint unit tests for the changed list paths (optional): Ran uv run --frozen pytest tests/unit/proxy/openai_files_endpoint/test_files_endpoint.py -k "require_managed_files or anthropic_default or cursor_params": 33 passed.
  • Passed · Managed files hook afile_list unit tests (optional): Ran uv run --frozen pytest tests/unit/enterprise/proxy/test_managed_files_hook.py -k afile_list: 38 passed.
  • Not run · Integration suite tests/integration/security/test_managed_file_listing.py (optional): Not run. It needs a shared gateway, a database and the proxy process harness. I checked coverage by reading the code, which the guide skill allows.
  • Passed · Preview radio wiring (required): Checked the generated HTML: 12 radios (2N for N=6), exactly one checked, every for= matches an id, no em dashes.

View review · Reviewed 03859487e4b5

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

Under require_managed_files, an admin keeps the provider list as on main, and
only a non-admin list reads the caller's own and team managed files. A stored
file now also shows on the provider its model name routes to through a
wildcard, with exact model names first, and a list routed to a model takes the
default page size of the provider serving it. A new index on created_by and
created_at keeps each chunk of the walk an index read, and the model check
runs before the file object is parsed.
A non-admin list scoped to a provider or model now asks Postgres only for the
caller's rows that map to one of that scope's deployments or models, or that
live in file storage, instead of reading every owned row and filtering them in
Python. A caller with many files on other providers no longer waits for the
whole set to be read. Team members' files are matched in the same query.
@mateo-berri
mateo-berri requested a review from a team October 28, 2026 11:06
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 e6edd7e. Configure here.

@mateo-berri
mateo-berri merged commit 9007e0f into main Oct 28, 2026
103 of 109 checks passed
@mateo-berri
mateo-berri deleted the litellm_scope_provider_file_list_to_owner branch October 28, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:low Small, isolated, low-risk change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants