Skip to content

Containers

Last updated: 2026-11-21T09:07:48-03:00 (UTC-3)

Containers are the sandboxes where the Responses code interpreter (and the hosted shell) runs code. They live at OpenAI and are billed by OpenAI per session. Through the gateway, each container belongs to a team: a key never sees, uses, or deletes another team’s container, not even by its raw ID. Interactive reference at /docs/swagger/, tag Containers.

  1. Turn on the openai_responses and containers flags. containers requires PostgreSQL, where the owner of each container is stored.
  2. Have an alias with the responses capability whose target is protocol: openai.
  3. The key needs the route:responses scope and the alias on its allowlist. To copy files from the gateway into a container, it also needs batches:write (Files API, flag batches) and a team.
features:
openai_responses: true
containers: true
models:
- id: coder
capabilities: [responses]
targets:
- {provider: openai, model: gpt-4.1-mini}
client = openai.OpenAI(api_key=KEY, base_url="https://gateway.example.com/v1")
f = client.files.create(file=open("sales.csv", "rb"), purpose="user_data")
box = client.containers.create(name="analysis", file_ids=[f.id],
expires_after={"anchor": "last_active_at", "minutes": 5},
extra_body={"model": "coder"}) # model is only needed with several providers
r = client.responses.create(model="coder", input="Sum the total column in the CSV.",
tools=[{"type": "code_interpreter", "container": box.id}])
client.containers.files.list(box.id)
client.containers.files.content.retrieve(file_id, container_id=box.id)
client.containers.delete(box.id)
Aspect Behavior
Target POST /v1/containers accepts model (a gateway field, removed before sending): the container is created on that alias’s first OpenAI target. Without model, the single OpenAI provider the key reaches through its Responses aliases is used; with more than one, 422 model_required
Owner The key’s team, or the key itself when it has no team (the same rule as conversations). Teammates use the container; another team gets 404 with no call to the provider
IDs The provider’s (cntr_…, cfile_…), not rewritten. Ownership is checked in the gateway’s table before every call
Listing GET /v1/containers pages through the gateway’s table (after, limit 1–100, order, name), never the account’s list. Containers that can still change are refreshed from the provider, four at a time; a container the provider no longer has appears once with status: deleted and then leaves the list
Files at creation file_ids are the team’s gateway files (/v1/files). The gateway creates the container and sends each file to it. If an upload fails, the container is deleted and the provider’s error goes back to the client
Container files POST /v1/containers/{id}/files accepts multipart with a single file part (up to 50 MiB) or JSON {"file_id": "<gateway file>"}. A provider file ID returns 404
Download …/files/{file_id}/content passes the bytes through with the provider’s Content-Type and Content-Disposition: this is how you download what the code interpreter generated (container_file_citation)
Responses Every container cited in the request must belong to the key’s owner: container of a code_interpreter tool, container_reference of a shell tool, and container_id of code_interpreter_call/shell_call items in input. The request goes to those containers’ provider, even on a multi-target alias
Auto mode container: {"type": "auto"} keeps working. The container the provider creates becomes owned by the key’s owner, in JSON and in the stream, before the event reaches the client. file_ids in auto mode is refused (400 invalid_container): those IDs would be provider files
Refused skills with skill_reference at creation (the provider’s skill belongs to the whole account); unknown query parameters
Usage Each call goes into the ledger as containers, with no tokens. The session is billed by the provider, outside budget and TPM
Console Containers screen: containers by team, origin (API or Responses), last state, memory, expiration, and deletion for the team admin
Situation Response
Flag off 404 feature_disabled
Container of another owner, unknown, or deleted 404 container_not_found, with no call to the provider
Containers from two providers in the same request, or a container and previous_response_id/conversation on different providers 422 conflicting_state
Alias with no target on the container’s provider 404 container_not_found
Database unavailable 503 storage_unavailable. At creation, the provider’s container is deleted
Provider refusal The provider’s status and body, as received
  • Containers created before the flag, or outside the gateway, return 404. With the flag off, Responses passes containers through without checking the owner.
  • The gateway checks the containers in the request, not the history stored at the provider. To isolate the history too, turn on responses_lifecycle and conversations.
  • network_policy passes through as received: to block network egress from the container, configure the policy at the provider.
  • Expiration is the provider’s (20 minutes without activity, by default); the console shows the last reported state.
  • Uploads up to 50 MiB.
  • Deleting a team does not delete its containers at the provider; they expire on their own.
  • The session cost does not go into budget, TPM, or valuation: the provider does not report usage per container.

Every route below needs a console session or an admin Bearer token, the role’s permission and, for writes, the X-CSRF-Token header; the full contract is in the API reference.

Route What it does
GET /api/v1/admin/containers Lists the containers the gateway owns, with owner, team, key, provider, status, last activity and expiry
DELETE /api/v1/admin/containers/{id} Deletes the container at its provider and retires it

m7gtw[email protected]