[BETA] LiteLLM Managed Files
- Reuse the same file across different providers.
- Prevent users from seeing files they don't have access to on
listandretrievecalls.
Free Enterprise feature
Available with the litellm[proxy] package or any litellm docker image. No Enterprise license is required.
| Property | Value | Comments |
|---|---|---|
| Proxy | ✅ | |
| SDK | ❌ | Requires postgres DB for storing file ids. |
| Available across all providers | ✅ | |
| Supported endpoints | /chat/completions, /batch, /fine_tuning, /responses |
Usage
1. Setup config.yaml
model_list:
- model_name: "gemini-3.8-flash"
litellm_params:
model: vertex_ai/gemini-3.8-flash
vertex_project: my-project-id
vertex_location: us-central1
- model_name: "gpt-6-luna-openai"
litellm_params:
model: gpt-6-luna
api_key: os.environ/OPENAI_API_KEY
general_settings:
master_key: os.environ/LITELLM_MASTER_KEY # alternatively use the env var - LITELLM_MASTER_KEY
database_url: "postgresql://<user>:<password>@<host>:<port>/<dbname>" # alternatively use the env var - DATABASE_URL
litellm_settings:
require_managed_files: true # optional - reject POST /v1/files without target_model_names
(Optional) Enforce managed files on upload
By default, POST /v1/files falls back to the classic provider file path when target_model_names is omitted. Set require_managed_files: true under litellm_settings to require managed files on every upload.
litellm_settings:
require_managed_files: true
When enabled, uploads without target_model_names return 400. Existing managed-file behavior is unchanged when target_model_names is provided.
# String (comma-separated for multiple models)
extra_body={"target_model_names": "gpt-6-luna-openai, gemini-3.8-flash"}
# List (OpenAI Python SDK sends this as target_model_names[] in multipart form)
extra_body={"target_model_names": ["gpt-6-luna-openai"]}
2. Start proxy
litellm --config /path/to/config.yaml
3. Test it!
Specify target_model_names to use the same file id across different providers. This is the list of model_names set via config.yaml (or 'public_model_names' on UI).
target_model_names="gpt-6-luna-openai, gemini-3.8-flash" # Specify model_names
Check /v1/models to see the list of available model names for a key.
Store a PDF file
from openai import OpenAI
client = OpenAI(base_url="http://0.0.0.0:4000", api_key="sk-<your-litellm-api-key>", max_retries=0)
# Download and save the PDF locally
url = (
"https://storage.googleapis.com/cloud-samples-data/generative-ai/pdf/2403.05530.pdf"
)
response = requests.get(url)
response.raise_for_status()
# Save the PDF locally
with open("2403.05530.pdf", "wb") as f:
f.write(response.content)
file = client.files.create(
file=open("2403.05530.pdf", "rb"),
purpose="user_data", # can be any openai 'purpose' value
extra_body={"target_model_names": "gpt-6-luna-openai, gemini-3.8-flash"}, # Specify model_names
)
print(f"file id={file.id}")
Use the same file id across different providers
- OpenAI
- Vertex AI
completion = client.chat.completions.create(
model="gpt-6-luna-openai",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "What is in this recording?"},
{
"type": "file",
"file": {
"file_id": file.id,
},
},
],
},
]
)
print(completion.choices[0].message)
completion = client.chat.completions.create(
model="gemini-3.8-flash",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "What is in this recording?"},
{
"type": "file",
"file": {
"file_id": file.id,
},
},
],
},
]
)
print(completion.choices[0].message)