---
title: "Grant a plan"
description: "Define a plan as an IdentityHound bundle of entitlements, grant it to a workspace exactly once per order, and see the access checks that need it start to allow."
url: "https://agentpost.tools/docs/identityhound/guides/grants"
kind: guide
needs:
  - what: "The `identity` helper, and a config whose catalog has the `reports.export` entitlement"
    from: "https://agentpost.tools/docs/identityhound/quickstart.md"
  - what: "Ana's workspace, `acme`, and `check`, whose export check Acme's missing entitlement denies"
    from: "https://agentpost.tools/docs/identityhound/quickstart.md"
---

# Grant a plan

[Entitlements](/docs/identityhound/concepts/entitlements.md) describes bundles, grants, and who holds them.

## Before you start

-   The `identity` helper, and a config whose catalog has the `reports.export` entitlement, from [IdentityHound quickstart](/docs/identityhound/quickstart.md).
-   Ana's workspace, `acme`, and `check`, whose export check Acme's missing entitlement denies, from [IdentityHound quickstart](/docs/identityhound/quickstart.md).

This page's code continues the script of the pages above: run its blocks after theirs, in the same file. To run them as a script of their own, first copy each helper from the page that defines it, and set each other value, such as a key or an ID, to one you already have.

## 1\. Define the bundle

Your server creates the bundle once, with `POST /v1/identity/bundles`. Here `pro` holds the `reports.export` entitlement:

```ts
await identity('POST', '/bundles', {
  key: 'pro',
  name: 'Pro',
  items: [{ entitlement: 'reports.export' }],
});
```

Creating the bundle can answer [`entitlement_unknown`](/docs/identityhound/errors.md#entitlement_unknown).

## 2\. Grant it once per order

When Acme buys Pro, your server grants the `pro` bundle to the workspace with `POST /v1/identity/grants`. Send the order ID as the required `Idempotency-Key` header, so an authorized retry answers with the same grant, as [Retrying a write](/docs/platform/api-basics.md#retrying-a-write) describes:

```ts
const order = { 'idempotency-key': 'order-1001' };
const grant = {
  target: { kind: 'bundle', bundle: 'pro' },
  holder: { kind: 'workspace', id: acme.id },
  provenance: { source: 'purchase', reference: 'order-1001' },
};
const first = await identity('POST', '/grants', grant, order);
const retry = await identity('POST', '/grants', grant, order);
console.log(first.grant.id === retry.grant.id); // true
```

Use your app’s own label for `provenance.source`; [Entitlements](/docs/identityhound/concepts/entitlements.md#grants) explains the label. Use a new key for each order: the grant keeps its key with no time limit, and [Create a grant](/docs/identityhound/reference/grants.md#create-a-grant) has the rule in full. To end a plan on a date, send `expiresAt` with the grant.

## Check it worked

Run the export check again:

```ts
const afterGrant = await check('export');
console.log(afterGrant.allowed, afterGrant.reason); // true workspace_role
```

The [grants reference](/docs/identityhound/reference/grants.md) covers revoking a grant, and the [entitlements reference](/docs/identityhound/reference/entitlements.md) lists and checks what a principal holds.
