Skip to main content

Containers

Containers are sandboxed environments that the code interpreter tool uses to run code and keep files between model calls. The gateway proxies the OpenAI containers API, so applications create containers with virtual keys, attach them to Responses API requests, and manage their files, with every operation logged and attributed to the key that made it.

Scenario​

A data analyst's assistant lets users upload a spreadsheet and ask for charts. The application creates one container per user session, uploads the spreadsheet into it, and runs Responses API requests with the code interpreter tool bound to that container. Charts the code produces are read back from the container, and the container expires twenty minutes after the last use.

Steps​

  1. Register an OpenAI chat model in Models + Endpoints (/ui/models-and-endpoints) if you have not already, and create a key in Virtual Keys (/ui/api-keys) that may use it.

  2. Create a container.

    curl -X POST http://localhost:4000/v1/containers \
    -H "Authorization: Bearer $SPANWAY_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"name": "analysis-session", "expires_after": {"anchor": "last_active_at", "minutes": 20}}'
  3. Use the container in a Responses API request.

    curl -X POST http://localhost:4000/v1/responses \
    -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{
    "model": "gpt-6.1-sol",
    "input": "Plot the monthly totals in sales.csv",
    "tools": [{"type": "code_interpreter", "container": "cntr_7c2d4e1f"}]
    }'
  4. List, read and delete containers with GET /v1/containers, GET /v1/containers/{container_id} and DELETE /v1/containers/{container_id}.

  5. Try it in the browser. Open Playground (/ui/playground), set Endpoint Type to /v1/responses, pick an OpenAI model, turn on Code Interpreter and ask for a calculation. The Playground creates the container automatically. Then open Logs (/ui/logs) to see the request.

Expected result​

{"id": "cntr_7c2d4e1f", "object": "container", "name": "analysis-session", "status": "running", "created_at": 1760441234, "expires_after": {"anchor": "last_active_at", "minutes": 20}}

The Responses API call returns code_interpreter_call items in its output and, for files the code wrote, container_file_citation annotations with the container id and file id to fetch through the container files endpoints.

Endpoints​

{{ops:^/v1/containers(/{container_id})?$}}

expires_after sets how long an idle container lives. Without an explicit container, the code interpreter tool creates one automatically with "container": {"type": "auto"}.

Provider selection​

Containers run at OpenAI unless the request says otherwise. Name another provider, such as azure, with the custom-llm-provider header, the custom_llm_provider query parameter or the custom_llm_provider field in the body. When several accounts of a provider are registered, send model with a model from model_list, in the body on create and as a query parameter on list, and the gateway uses that deployment. A container id the gateway returned carries its deployment, so later calls with that id reach the same account without naming it again. The x-spanway-model header is not read by the container routes.

Who can use a container​

The gateway records who created each container. A container belongs to the user of the key that created it when the key has a user, otherwise to the key's team, then its organization, then the key itself. Any key with the same owner can read, use and delete it, and a proxy admin can reach every container. Everyone else gets 403, including a /v1/responses request whose code interpreter tool names a container it does not own, which is refused before the request reaches the provider.

Requirements​

Non-admin keys need the gateway database (DATABASE_URL), because the owner of each container is stored in Spanway_ManagedObjectTable. Without a database, or for a container created before the gateway tracked owners, only a proxy admin can reach it, and GET /v1/containers shows non-admin keys an empty list. Creating and deleting a container is written to the audit log as a container:<id> row.

Cost and access​

Code interpreter sessions are priced per session in the price map, and container operations are authenticated and logged like any other request. See Responses API for the tool definitions and code interpreter interception for running the tool in a gateway sandbox for models without a native code interpreter.

Errors​

StatusWhat it meansFix
400 BadRequestErrorexpires_after is malformed, or the provider is not supported for containers.Send anchor and minutes, and name openai or azure.
400 data policyThis containers request goes to the provider directly without a configured deployment, so the data policy ... cannot be verifiedThe key has a data policy. Send model with a deployment whose data terms meet it.
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, see who can use a container.
403 This key cannot use container <id>. ... on /v1/responsesThe code interpreter tool named a container this key does not own.Use the owner's key, or let the tool create one with {"type": "auto"}.
403 Unable to record container ownership: caller has no identity scope.The key has no user, team, organization or key id to record as owner.Use a virtual key.
404 NotFoundErrorThe container id is unknown or has expired.Create a new container.
429 RateLimitErrorBudget or rate limit reached.Raise the limit.

Logs​

LevelLineMeaningAction
WARNINGSkipping container ownership tracking because prisma_client is NoneThe gateway has no database, so the new container has no owner and only proxy admins can reach it.Set DATABASE_URL.
ERRORContainer ownership recording failed after upstream create; returning response with untracked ownership: <error>The container was created but its owner could not be stored. The caller got the container, and only proxy admins can reach it.Check the database, then delete or reassign the container.
ERRORFailed to record container ownership from responses output for container_id=<id>: <error>A container the code interpreter created during /v1/responses could not be recorded.Check the database.

Providers​

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

OpenAI.