Skip to main content

Container files

Container files are the files inside a code interpreter container, inputs you upload for the model's code to read, and outputs such as charts or spreadsheets the code wrote. The gateway proxies the OpenAI container files API so these operations use virtual keys and are logged, and so applications can fetch the files a Responses API run produced.

Scenario​

A reporting assistant lets a user upload a CSV, asks the model to chart it, and shows the chart in the browser. The application uploads the CSV into the user's container, runs the Responses API request with the code interpreter bound to that container, reads the output file id from the response annotations and downloads the PNG through the gateway.

Steps​

  1. Create a container, see containers, and keep its id.

  2. Upload an input file.

    curl -X POST http://localhost:4000/v1/containers/cntr_7c2d4e1f/files \
    -H "Authorization: Bearer $SPANWAY_API_KEY" \
    -F "file=@sales.csv"

    The upload must be multipart form data with a file field. Creating a container file from a file already uploaded to /v1/files is not supported through the gateway yet, so upload the bytes directly.

  3. Run a Responses API request with the code interpreter tool bound to the container, as shown on the containers page. Read the output file ids from the container_file_citation annotations in the response.

  4. List, read and download the files.

    curl http://localhost:4000/v1/containers/cntr_7c2d4e1f/files -H "Authorization: Bearer $SPANWAY_API_KEY"
    curl http://localhost:4000/v1/containers/cntr_7c2d4e1f/files/cfile_9e0f1a2b -H "Authorization: Bearer $SPANWAY_API_KEY"
    curl http://localhost:4000/v1/containers/cntr_7c2d4e1f/files/cfile_9e0f1a2b/content -H "Authorization: Bearer $SPANWAY_API_KEY" --output chart.png
    curl -X DELETE http://localhost:4000/v1/containers/cntr_7c2d4e1f/files/cfile_9e0f1a2b -H "Authorization: Bearer $SPANWAY_API_KEY"
  5. Check the log. Open Logs (/ui/logs). Each file operation is a row under the key.

Expected result​

{"id": "cfile_9e0f1a2b", "object": "container.file", "container_id": "cntr_7c2d4e1f", "created_at": 1760441234, "path": "/mnt/data/sales.csv", "source": "user", "bytes": 48213}

Files written by the model's code have source: assistant. The /content endpoint returns their bytes as application/octet-stream, so read the file's path from the metadata route to tell a .png from a .csv.

Endpoints​

{{ops:^/v1/containers/{container_id}/files}}

Limits and access​

An upload larger than general_settings.max_file_size_mb is refused with 413 before it reaches the provider. Only a key with the same owner as the container, or a proxy admin, can touch its files, see who can use a container. Deleting a container removes its files. Container file operations do not go through the managed files mapping, because they belong to a specific container on one provider. Adding and deleting a file is written to the audit log as a container_file:<container id>/<file id> row. GET /v1/containers/{container_id}/files takes after, limit (1 to 100) and order (asc or desc) to page the list.

Errors​

StatusWhat it meansFix
400 Missing required 'file' fieldThe upload has no file form field, or was sent as JSON.Send multipart form data with a file field.
401 AuthenticationErrorThe key is missing, wrong or expired.Use a live key.
403 ForbiddenThe container belongs to another user, team or key, or the gateway has no record of its owner.Use a key with the same owner, or a proxy admin key.
404 NotFoundErrorThe container or file id is unknown, or the container expired.Create a new container and upload again.
413 Uploaded file exceeds the configured max_file_size_mb of <n> MB ...The upload is larger than general_settings.max_file_size_mb. Nothing was sent to the provider.Shrink the file or raise the limit.

Logs​

Container file calls write no lines of their own beyond the request log. Ownership problems are logged by the container routes, see containers.

Providers​

The gateway's endpoint support matrix marks 1 provider integration as supporting this endpoint:

OpenAI.