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

Vaults

Store MCP credentials and attach them to agent sessions.

A vault stores credentials for MCP connections from OpenAI. Attach it to a session so the agent can use authenticated tools without receiving the secret values.

Vaults support bearer tokens and existing OAuth grants. For connections from your environment, use the other MCP authentication options.

Permissions

For a restricted application key, grant:

  • api.vaults.read to list and retrieve vaults and credentials.
  • api.vaults.write to create, update, or delete them.

Create and use a vault

Use your API client, the MCP server URL (mcp_url), and an access token for that server (access_token). The examples use GitHub tools.

First, create a vault:

Create a vault
const vault = await client.beta.agents.vaults.create({
  name: "GitHub credentials",
  metadata: {
    external_user_id: "user_123",
  },
});

Save its ID as vault_id, then add the token. mcp_server_url binds the credential to that server:

Store a bearer token
const credential = await client.beta.agents.vaults.credentials.create(vaultId, {
  name: "GitHub access token",
  auth: {
    type: "static_bearer",
    mcp_server_url: mcpUrl,
    token: accessToken,
  },
});

Save the credential ID as credential_id for later updates.

Pass the saved ID in vault_ids when creating a session. Use the same server URL in the MCP configuration:

Attach the vault to a session
const session = await client.beta.agents.sessions.create({
  agent: {
    model: "gpt-6-astra",
    tools: [
      {
        type: "mcp",
        server_label: "github",
        transport: {
          type: "http",
          server_url: mcpUrl,
        },
        allowed_tools: ["search_issues", "issue_read"],
        required: true,
        connection_origin: "service",
      },
    ],
  },
  environment: {
    type: "none",
  },
  input: "Find open bugs reported in the last week.",
  vault_ids: [vaultId],
});

The Agents API selects a credential that matches the server URL. If several attached credentials match, set the MCP tool’s credential_id to select one. Retrieving a vault or credential does not return its secret values.

Use OAuth credentials

Your application handles the provider’s authorization and consent flow. Store the resulting grant with auth.type: "mcp_oauth". Set expires_at to the access token’s expiry as an RFC 3339 timestamp, if known.

The following example uses values from your provider’s OAuth flow. Include refresh to let the Agents API refresh the token:

Store an OAuth grant
const credential = await client.beta.agents.vaults.credentials.create(vaultId, {
  name: "Example MCP OAuth credential",
  auth: {
    type: "mcp_oauth",
    mcp_server_url: mcpUrl,
    access_token: accessToken,
    expires_at: expiresAt,
    refresh: {
      token_endpoint: tokenEndpoint,
      client_id: clientId,
      refresh_token: refreshToken,
      token_endpoint_auth: {
        type: "none",
      },
    },
  },
});

Use the token endpoint authentication method required by your provider. The example uses none; client_secret_basic and client_secret_post are also supported. See the credential creation reference for the fields.

If an expired token cannot be refreshed, supply a valid replacement. Token expiry does not delete the credential or its vault.

Rotate or remove credentials

Update a credential to replace its token without changing its ID, authentication type, or server URL. For OAuth, use the saved vault_id and credential_id with the replacement token and expiry:

Rotate an OAuth token
const credential = await client.beta.agents.vaults.credentials.update(
  credentialId,
  {
    vault_id: vaultId,
    ...{
      auth: {
        type: "mcp_oauth",
        access_token: accessToken,
        expires_at: expiresAt,
      },
    },
  }
);

Include expires_at when the replacement token expires. Supplying a new access token without an expiry clears the stored expiry; an explicit null also clears it.

Delete a credential when you no longer need it. Delete a vault to remove the vault and all its credentials.

Deleting stored credentials does not revoke the original tokens with their providers or stop a running session. Your application handles provider-side revocation and session cancellation.