Managed files
Provider file APIs are account specific. A file uploaded to OpenAI cannot be used with a Bedrock model, and anyone with the provider key can read any file. Managed files solve both problems. The gateway issues its own file id, uploads the file once to each model you name when you upload it, maps the id to the provider file behind each of those deployments, and lets only the uploader's team use it. Managed files are an enterprise feature and need a database. They are used through the API, the Admin UI has no files page.
Scenario
A contracts team uploads agreements once for the two models they switch between, whichever is cheaper that week. With managed files the upload returns one gateway file id, the gateway stores a copy at the provider behind each of the two models, and the team references that one id in chat completions with either model. Another team's key cannot read the file even though both teams share the provider account.
Steps
-
Check the license. In the Admin UI the Enterprise usage card at the bottom of the left nav shows the license and its expiry date when a valid Spanway license is loaded, and
GET /health/licenseanswers{"has_license": true, ...}, see enterprise. Managed files also needDATABASE_URLset. -
Register the models the file should work with in Models + Endpoints (
/ui/models-and-endpoints) and create a key in Virtual Keys (/ui/api-keys) that may use them. -
Upload a file and name every model group it should work with. The gateway uploads it right away to one deployment of each named model. To use the file with another model later, upload it again naming that model.
curl -X POST http://localhost:4000/v1/files \-H "Authorization: Bearer $SPANWAY_API_KEY" \-F "purpose=user_data" \-F "target_model_names=claude-sonnet-5-5,gpt-6.1-sol" \-F "file=@contract.pdf" -
Reference the managed id in a chat completion. Put the
idthe upload returned inFILE_ID.curl -X POST http://localhost:4000/v1/chat/completions \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"model": "claude-sonnet-5-5", "messages": [{"role": "user", "content": [{"type": "file", "file": {"file_id": "'"$FILE_ID"'"}}, {"type": "text", "text": "Summarize the termination clause."}]}]}' -
Check who can see the file.
GET /v1/fileswith noprovider,custom_llm_providerortarget_model_nameslists the managed files your user or team owns, newest first, and pages withlimit(1 to 10000) andafter(the last id of the previous page). The same call with another team's key does not list it. Addingtarget_model_names=<one model>instead lists the files the provider account behind that model holds, which is a provider listing and not limited to your files. Open Logs (/ui/logs) to see the upload and the completion under the key.
Expected result
{"id": "c3BhbndheV9wcm94eTphcHBsaWNhdGlvbi9wZGY7dW5pZmllZF9pZCw3ZjNjMmExZS0wYjRkLTRmNmEtOWM4ZS0yZDViMWEzZjRlNmM7dGFyZ2V0X21vZGVsX25hbWVzLGNsYXVkZS1zb25uZXQtNS01LGdwdC02LjEtc29sO2xsbV9vdXRwdXRfZmlsZV9pZCw7bGxtX291dHB1dF9maWxlX21vZGVsX2lkLA", "object": "file", "purpose": "user_data", "filename": "contract.pdf", "bytes": 48213, "created_at": 1760441234, "status": "uploaded"}
The returned id is a gateway managed id, a base64 string that starts with c3BhbndheV9wcm94e. A file-... id is a raw provider id and is not managed. The chat completion answers normally, and the gateway swapped the managed id for the provider file id of the deployment that served the call. A request that names the file is routed only to the deployments that hold a copy, so a model you did not name at upload time has no deployment for it.
Ownership and access
Each managed file records the user and team that uploaded it, and the key only when the key has neither a user nor a team. Every key on the uploader's team, and every key of the uploading user, may list, read, download, use and delete the file. Keys of other teams get 403. Proxy admins and admin viewers can read every file. Deleting a file removes it from every provider it was uploaded to. Batches created with a managed input file are tracked the same way, and their output files get managed ids with the same team rule.
Who changed what
Every upload and delete through /v1/files writes an audit row with the key, user and team that did it, the file id, and the purpose, file name, size, target models and whether the id is managed. The file content is never stored. Read the rows on the Logs page, Audit Logs tab, see audit logs.
Managed vector stores
The same mechanism covers vector stores. A managed vector store id maps to provider stores per deployment, and files added to it are uploaded to the right backend. See vector store files.
Configuration
Managed files and managed vector stores need any valid Spanway license and a database, because the id mapping is stored in Postgres. Provider credentials for uploads come from the deployments in model_list, so no separate files_settings block is required. Without target_model_names, /v1/files forwards to the provider named by custom_llm_provider or configured in files_settings, and returns the provider's own file ids, see batches.
| Setting | Where | Default | What it does |
|---|---|---|---|
require_managed_files | spanway_settings | false | When on, every file, batch and fine-tuning call must use a gateway managed id and every upload must name target_model_names, so nobody can reach another team's file by guessing its raw provider id. When off, raw provider ids are accepted and use the shared provider credentials. Turn it on for any gateway that serves more than one team. |
max_file_size_mb | general_settings | unset, no limit | The largest upload in MB. A bigger file is refused with 413 before it reaches the provider. |
max_batch_file_size_mb | general_settings | unset | The largest batch input file, checked before the batch is checked line by line. |
allowed_file_extensions | general_settings | unset, every extension | When set, only these extensions may be uploaded, for example [".jsonl", ".pdf"]. |
blocked_file_extensions | general_settings | unset | Extensions that are always refused, checked after the allow list. |
max_file_downloads_per_minute | general_settings, key metadata, team metadata | unset, no limit | How often one key may download the content of one file in a minute. A key or team value overrides the gateway value. |
maximum_managed_file_retention_period | general_settings | unset, files are kept | Managed files uploaded longer ago than this period, for example 90d, are deleted by the cleanup job, with the bytes the spanway_db storage kept for them. Provider copies are not deleted. |
enforced_file_expires_after | team metadata | unset | Forces every upload by the team to expire at the provider, as {"anchor": "created_at", "seconds": 86400}, whatever the caller sends. |
Keep a file in your own storage
The upload field target_storage=azure_storage keeps the file in Azure Blob Storage instead of at the provider. The gateway needs AZURE_STORAGE_ACCOUNT_NAME and AZURE_STORAGE_FILE_SYSTEM, plus AZURE_STORAGE_ACCOUNT_KEY or AZURE_STORAGE_TENANT_ID, AZURE_STORAGE_CLIENT_ID and AZURE_STORAGE_CLIENT_SECRET. Download and delete with the managed id work the same way. The gateway also has its own spanway_db storage, which it picks by itself for the batch input files of models whose batches it runs, and a caller cannot choose it.
Errors
| Status | Message | What it means | Fix |
|---|---|---|---|
| 403 | names the license | The upload carries target_model_names, or a request names a managed file id, and the gateway has no license for managed files. | Load a license, or upload with custom_llm_provider and use provider file ids. |
| 403 | User <user_id> does not have access to the file <file_id> or The caller does not have access to this managed file id. | The file belongs to another team or user. | Use a key of the uploader's team or user, or a proxy admin key. |
| 422 | {"detail": [{"type": "missing", "loc": ["body", "purpose"], "msg": "Field required"}]} | The upload has no purpose or no file. | Send both form fields. |
| 400 | Invalid purpose: <purpose>. Must be one of: ... | purpose is not a value the files API knows. | Use one of the listed purposes. |
| 400 | File extension '.exe' is not in this proxy's allowed_file_extensions setting. The file was not forwarded to the provider. | The extension is not allowed. | Allow it or convert the file. |
| 400 | File extension '.exe' is blocked by this proxy's blocked_file_extensions setting. ... | The extension is blocked. | Convert the file. |
| 400 | Filename '../x' is not allowed: directory traversal sequences are not permitted in uploaded file names. ... | The file name contains .. or a NUL byte. | Rename the file. |
| 400 | target_storage=spanway_db is not a storage a caller can pick: ... | The upload asked for the gateway's own storage. | Leave target_storage out, or use azure_storage. |
| 400 | expires_after[anchor] must be 'created_at', got '...' or expires_after[seconds] must be a valid integer, ... | The expiry fields are wrong. | Send created_at and a number of seconds. |
| 400 | target_model_names is required when require_managed_files is enabled in spanway_settings. ... | require_managed_files is on and the upload named no model. | Name the target models. |
| 400 | Raw provider file ids cannot be used when require_managed_files is enabled in spanway_settings. ... | require_managed_files is on and a raw provider id was sent. | Use the managed id. |
| 400 | Cannot delete file <id>: it is referenced by 2 batch(es) that have not finished ... | A running batch still uses the file. | Wait for the batches or cancel them. |
| 400 | Invalid 'after' cursor: no file found with id '<id>'. | The after id is not one of your files. | Use the last id of the previous page. |
| 400 | Invalid 'limit': integer above maximum value. Expected a value <= 10000, but got 20000 instead. | limit is outside 1 to 10000. | Send a smaller page size. |
| 403 | Raw cloud storage file ids can only be deleted by a proxy admin key. ... | A non admin tried to delete a raw storage URI. | Delete with the managed id. |
| 404 | NotFoundError | The managed id is unknown, or the file was deleted. | Upload the file again. |
| 413 | Uploaded file exceeds the configured max_file_size_mb of 20 MB ... | The file is larger than max_file_size_mb. | Raise the limit or split the file. |
| 429 | RateLimitError on /content | More downloads in a minute than max_file_downloads_per_minute allows. | Cache the content on your side or raise the limit. |
| 500 | Managed files hook not found. Managed files need a database. | Managed files are licensed but the gateway has no database. | Set DATABASE_URL. |
| 500 | Server configuration error: team metadata field 'enforced_file_expires_after' is malformed ... | The team's forced expiry setting is broken. | Ask a proxy admin to fix the team metadata. |
Logs
| Level | Line | Meaning | Action |
|---|---|---|---|
| WARNING | batch guardrails changed <n> of <total> records in <file> | Batch guardrails rewrote some lines of an uploaded batch file before it was forwarded. | Normal when batch guardrails mask content. |
| WARNING | Ignoring invalid max_file_downloads_per_minute in <key or team> metadata; expected a positive integer | A key or team carries a bad download limit, so the gateway value applies. | Fix the metadata value. |
| WARNING | Enterprise proxy hooks are unavailable: ... | The enterprise package did not load, so managed files are off. | Check the image and the license. |
| ERROR | spanway.proxy.proxy_server.create_file(): Exception occured - ... | An upload failed. | Read the error, a 4xx is the caller's mistake. |
Related
- Batches for batch jobs over managed files.
- Vector store files for managed vector stores.
- Fine-tuning for training files.
- Enterprise for the license.