Skip to main content

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​

  1. 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/license answers {"has_license": true, ...}, see enterprise. Managed files also need DATABASE_URL set.

  2. 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.

  3. 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"
  4. Reference the managed id in a chat completion. Put the id the upload returned in FILE_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."}]}]}'
  5. Check who can see the file. GET /v1/files with no provider, custom_llm_provider or target_model_names lists the managed files your user or team owns, newest first, and pages with limit (1 to 10000) and after (the last id of the previous page). The same call with another team's key does not list it. Adding target_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.

SettingWhereDefaultWhat it does
require_managed_filesspanway_settingsfalseWhen 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_mbgeneral_settingsunset, no limitThe largest upload in MB. A bigger file is refused with 413 before it reaches the provider.
max_batch_file_size_mbgeneral_settingsunsetThe largest batch input file, checked before the batch is checked line by line.
allowed_file_extensionsgeneral_settingsunset, every extensionWhen set, only these extensions may be uploaded, for example [".jsonl", ".pdf"].
blocked_file_extensionsgeneral_settingsunsetExtensions that are always refused, checked after the allow list.
max_file_downloads_per_minutegeneral_settings, key metadata, team metadataunset, no limitHow 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_periodgeneral_settingsunset, files are keptManaged 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_afterteam metadataunsetForces 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​

StatusMessageWhat it meansFix
403names the licenseThe 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.
403User <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.
400Invalid purpose: <purpose>. Must be one of: ...purpose is not a value the files API knows.Use one of the listed purposes.
400File 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.
400File extension '.exe' is blocked by this proxy's blocked_file_extensions setting. ...The extension is blocked.Convert the file.
400Filename '../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.
400target_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.
400expires_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.
400target_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.
400Raw 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.
400Cannot 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.
400Invalid '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.
400Invalid 'limit': integer above maximum value. Expected a value <= 10000, but got 20000 instead.limit is outside 1 to 10000.Send a smaller page size.
403Raw 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.
404NotFoundErrorThe managed id is unknown, or the file was deleted.Upload the file again.
413Uploaded 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.
429RateLimitError on /contentMore downloads in a minute than max_file_downloads_per_minute allows.Cache the content on your side or raise the limit.
500Managed files hook not found. Managed files need a database.Managed files are licensed but the gateway has no database.Set DATABASE_URL.
500Server 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​

LevelLineMeaningAction
WARNINGbatch 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.
WARNINGIgnoring invalid max_file_downloads_per_minute in <key or team> metadata; expected a positive integerA key or team carries a bad download limit, so the gateway value applies.Fix the metadata value.
WARNINGEnterprise proxy hooks are unavailable: ...The enterprise package did not load, so managed files are off.Check the image and the license.
ERRORspanway.proxy.proxy_server.create_file(): Exception occured - ...An upload failed.Read the error, a 4xx is the caller's mistake.