> ## Documentation Index
> Fetch the complete documentation index at: https://infisical.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a session

> Create an Agent Vault session with the Node.js SDK.

`client.agentVault().sessions.create()` creates a [session](https://infisical.com/docs/documentation/platform/agent-vault/sessions), which lets an AI agent use the services in an access bundle, the inline services sent with the session, or both. Admins can create sessions with any access bundle, and members with the access bundles [granted](https://infisical.com/docs/documentation/platform/agent-vault/access-bundles.md#grant-access) to them.

## Parameters

**options** `object` *required*

**properties**

**projectId** `string` *required*

The ID of the [Agent Vault project](https://infisical.com/docs/documentation/platform/agent-vault/projects.md#find-the-project-id) to create the session in.

**accessBundle** `string`

The name of the access bundle that the agent can use during the session (pass `accessBundle`, `services`, or both).

**services** `AgentVaultInlineServiceInput[]`

[Inline services](#create-a-session-with-inline-services) to send with the session (Agent Vault admins only, up to 30).

**ttl** `string`

How long the session lasts, as a duration of at least one minute such as `30m`, `8h`, or `7d`, or as `never` for a session that doesn't expire (defaults to `7d`, or to `1h` for a session on behalf of a user).

**label** `string`

A short description of what the session is for, such as `nightly deploy` (up to 128 characters, without line breaks, tabs, or invisible characters).

**metadata** `object`

Key/value pairs that say who or what the session is for, such as a run ID or ticket (up to 20 keys, each key up to 255 characters and each value 1 to 1020, without line breaks, tabs, or invisible characters, and no `=` in a key).

**onBehalfOfUserEmail** `string`

The email address of the user that the session is [created on behalf of](#create-a-session-on-behalf-of-a-user) (throws an `InfisicalSDKError` if you also pass `onBehalfOfUserId`).

**onBehalfOfUserId** `string`

The ID of the user that the session is created on behalf of (throws an `InfisicalSDKError` if you also pass `onBehalfOfUserEmail`).

## Returns

**session** `CreatedAgentVaultSession`

The new session, with the session token in `token` (Infisical returns the token only once).

To pass `session.token` to the agent, follow the steps in [Start the agent](https://infisical.com/docs/documentation/platform/agent-vault/create-a-session.md#start-the-agent).

## Create a session on behalf of a user

If the client logs in as a machine identity with a [delegation](https://infisical.com/docs/documentation/platform/agent-vault/sessions-on-behalf-of-users.md#set-up-a-delegation), the client can create sessions on behalf of the users that the delegation covers. For each of those sessions, the proxy uses the user's [personal values](https://infisical.com/docs/documentation/platform/agent-vault/http-apis.md#member-provided-values) instead of the machine identity's.

* The session can use an access bundle only if both the user and the machine identity [can use the bundle](https://infisical.com/docs/documentation/platform/agent-vault/sessions-on-behalf-of-users.md#access-bundles-and-personal-values)
* The session belongs to the machine identity, so the user can't see the session unless they're an Agent Vault admin
* In each session that the `get`, `list`, `update`, and `revoke` methods return, `onBehalfOf` is the user, or `null` if the session is the machine identity's own

To find the access bundles that a session on behalf of the user can use, pass the user's email address or ID to [`accessBundles.list`](https://infisical.com/docs/sdks/languages/node/agent-vault/list-access-bundles). The proxy refuses a session's requests to services that still need the user's personal values, so also pass `requiresSetup: false` to leave out the access bundles with those services.

## Create a session with inline services

If the client logs in as a user or machine identity with the **Admin** role in the Agent Vault project, the client can send inline services with a session, instead of or beside an access bundle. Inline services let you pass along credentials that your code already holds, without setting anything up in Agent Vault in advance.

* Each service is an HTTP API (`type: "http"`), an MCP server (`type: "mcp"`), or a [database or SSH server](https://infisical.com/docs/documentation/platform/agent-vault/databases-and-ssh) (`type: "postgres"`, `"mysql"`, or `"ssh"`)
* Credentials, custom header values, and substitution values can't contain text in double braces, such as `{{GITHUB_TOKEN}}`, because inline services can't use [variables](https://infisical.com/docs/documentation/platform/agent-vault/variables)
* A session can have up to 30 inline services, and no two of its services can have the same name or host pattern, including the services in its access bundle
* If a machine identity creates the session on behalf of a user, the machine identity needs the **Admin** role and the user doesn't, and the inline services don't use the user's personal values
* In each session that the `create`, `get`, `list`, and `update` methods return, `services` lists the inline services without their secrets

For the fields that each type of service takes, and for when Infisical deletes the services' secrets, see [Inline services](https://infisical.com/docs/documentation/platform/agent-vault/inline-services.md).

```typescript Access bundle theme={"dark"}
const session = await client.agentVault().sessions.create({
  projectId: "<project-id>",
  accessBundle: "<access-bundle-name>",
  ttl: "1h", // Optional
  label: "nightly deploy", // Optional
  metadata: { runId: "8812" } // Optional
});
```

```typescript On behalf of a user theme={"dark"}
const session = await client.agentVault().sessions.create({
  projectId: "<project-id>",
  accessBundle: "<access-bundle-name>",
  onBehalfOfUserEmail: "<user-email>"
});
```

```typescript Inline services theme={"dark"}
const session = await client.agentVault().sessions.create({
  projectId: "<project-id>",
  ttl: "1h",
  services: [
    {
      type: "http",
      name: "github",
      hostPattern: "api.github.com",
      allowedMethods: ["GET"],
      credential: { type: "bearer", value: "<github-token>" }
    }
  ]
});
```

```json Response theme={"dark"}
{
  "id": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
  "projectId": "<project-id>",
  "label": "nightly deploy",
  "token": "<session-token>",
  "expiresAt": "2026-12-02T13:00:00.000Z",
  "createdAt": "2026-12-02T12:00:00.000Z",
  "accessBundle": {
    "id": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b",
    "name": "release"
  },
  "services": [],
  "metadata": { "runId": "8812" }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.