For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Agents API

Create isolated sessions

A common agent configuration allows you to encode the behavior and functionality all instances of the agent will share. Customer- and task-specific data lives at the session level. Two sessions can use the same saved agent and still have separate messages, tool results, files, and credentials.

To run code, the agent needs an environment. An OpenAI-hosted environment provides an isolated workspace, or sandbox, for files and commands. To let the agent access systems that require authentication, attach a vault that holds credentials such as API tokens. Your app decides which resources to attach and which application users can interact with a session.

Step 1 of 10Create a vaultHTTP request from Your app to OpenAI Agents API.
Your app
Checks the caller’s permissions and requests a vault.
HTTP request
OpenAI Agents API
Creates a vault that can hold credentials.

Create a vault

Request JSON · POST /v1/vaults

Assign resources to a session

Here are the key components of a session you can specify when you create it.

Field What it selects
agent_id The saved agent whose model, instructions, and tools the session copies.
environment Set type to openai_hosted for a new workspace. Choose its initial files and network access.
vault_ids The vaults that supply credentials. Attach only the vaults this session needs.

In your app, associate the returned session id and environment.id with the user or customer who owns the session. Use the session ID to send a task. Use the environment ID to work with files once the workspace reports connected.

Example: Isolate each customer’s integration review

Each customer has already authorized these reviews and supplied a GitHub token with read-only access to its own repository. Herringbone stores each token in a dedicated vault.

When the API changes, Herringbone creates both sessions using the same shared agent configuration. Each call to agents.sessions.create attaches the customer’s vault and copies its test data into a new workspace. The examples omit input, so both sessions start idle, with no work in progress.

To start each review, Herringbone’s app sends a message to the session describing the change and asking the agent to propose any necessary updates. It could also include that task at creation.

In the Python examples, agents is OpenAI().beta.agents and db is a SQLite database. The customer tabs show which vault and test data Herringbone selects for each session. Shared backend shows the access checks. Full program sets up both reviews and tests those checks.

Customer session examples

Herringbone gives the agent two pages of sample payments so it can check whether the export includes every payment exactly once. The app saves the session and workspace IDs in its review database. When a finance user opens the review, the app checks their access and lists its files.

Customer A: open the nightly export review
export_token = os.environ["CUSTOMER_A_GITHUB_TOKEN"]
export_vault = create_repository_vault(
    agents, cleanup, "customer-a/payments-export", export_token
)
export_session = agents.sessions.create(
    agent_id=shared_agent_id,
    vault_ids=[export_vault],
    environment={
        "type": "openai_hosted",
        "network": {
            "access": "restricted",
            "allowed_domains": ["api.github.com"],
        },
        "files": [inline_file("/workspace/export-pages.json", export_pages)],
    },
)

save_session(db, "customer-a", "payments-export", export_session)

export_review = inspect_customer_session(
    agents, db, "finance-user", "customer-a", "payments-export"
)
Ask your coding agent
Create a hosted session per integration using the shared agent ID. Attach the customer's vault and restrict network access to the repository API. Save the session and environment IDs with the customer and integration. Check access before using either ID and wait for the environment to report connected before uploading files. Read this lesson for context: https://developers.openai.com/api/training/agents-api/2-create-isolated-sessions.md