> ## 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.

# Set a delegation

> Set who a machine identity can create Agent Vault sessions for with the Node.js SDK.

`client.agentVault().delegations.set()` sets which users a machine identity can create sessions on behalf of. The new delegation replaces any delegation that the machine identity has. The client must log in as a user or machine identity with the **Admin** role in the [Agent Vault project](https://infisical.com/docs/documentation/platform/agent-vault/access-control#product-membership).

With `AgentVaultDelegationScope.Selected`, pass at least one user or group. With `AgentVaultDelegationScope.AllMembers`, pass no users or groups. To stop the machine identity from acting on behalf of anyone, [delete the delegation](https://infisical.com/docs/sdks/languages/node/agent-vault/delete-delegation.md).

Each user and group must be a member of the Agent Vault project. If a user is in the Agent Vault project only through a group, pass the group instead.

## Parameters

**machineIdentityId** `string` *required*

The ID of the machine identity, which must be a member of the Agent Vault project.

**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 set the delegation in.

**scope** `AgentVaultDelegationScope` *required*

Either `AgentVaultDelegationScope.Selected` (`"selected"`) for only the users and groups that you pass, or `AgentVaultDelegationScope.AllMembers` (`"all-members"`) for every member of the Agent Vault project, admins included.

**userIds** `string[]`

With `AgentVaultDelegationScope.Selected`, the IDs of the users that the machine identity can act on behalf of (up to 100).

**groupIds** `string[]`

With `AgentVaultDelegationScope.Selected`, the IDs of the groups whose members the machine identity can act on behalf of (up to 100).

## Returns

**delegation** `AgentVaultDelegationDetail`

The delegation, with `missingAccessBundles`.

```typescript Selected users and groups theme={"dark"}
import { AgentVaultDelegationScope } from "@infisical/sdk";

const delegation = await client.agentVault().delegations.set("<machine-identity-id>", {
  projectId: "<project-id>",
  scope: AgentVaultDelegationScope.Selected,
  userIds: ["<user-id>"], // Optional
  groupIds: ["<group-id>"] // Optional
});
```

```typescript All members theme={"dark"}
import { AgentVaultDelegationScope } from "@infisical/sdk";

const delegation = await client.agentVault().delegations.set("<machine-identity-id>", {
  projectId: "<project-id>",
  scope: AgentVaultDelegationScope.AllMembers
});
```

```json Response theme={"dark"}
{
  "machineIdentity": {
    "id": "c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f",
    "name": "deploy-bot"
  },
  "scope": "selected",
  "users": [
    {
      "id": "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d",
      "username": "jsmith@example.com",
      "email": "jsmith@example.com",
      "firstName": "Jo",
      "lastName": "Smith",
      "addedAt": "2026-12-02T13:00:00.000Z",
      "missingAccessBundles": []
    }
  ],
  "groups": [
    {
      "id": "9f8e7d6c-5b4a-4392-8170-6f5e4d3c2b1a",
      "name": "platform-team",
      "addedAt": "2026-12-02T13:00:00.000Z",
      "missingAccessBundles": []
    }
  ],
  "missingAccessBundles": [],
  "createdAt": "2026-12-02T13:00:00.000Z",
  "updatedAt": "2026-12-02T13:00:00.000Z"
}
```


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