# Grants

A grant is a person's standing, bounded authority for an agent, with amount limits, a budget, allowed counterparties and an expiry, enforced at every verify.

A grant is a person's standing, bounded authority for an agent, such as "pay these suppliers, within a per-payment limit and a daily budget, until December", that lets the agent act without asking each time. The agent authorizes each action under the grant, and every verify enforces its limits on top of your account policy.

## When to use it

- An agent pays recurring or routine bills within limits the person set once.
- A purchasing agent buys from approved suppliers up to a budget.
- A scheduled payment, such as monthly rent, runs once per cycle without a new approval.

For one-off actions that need a person each time, use [step-up approval](https://provenanceauth.com/docs/mandate/guides/step-up-approval.md) instead.

## How it works

1. **The person grants the grant.** [`POST /v1/mandate/grants`](https://provenanceauth.com/docs/api/grants.md#post-v1-mandate-grants) returns a signed `mandate_token` (ES256, verifiable with the same [published keys](https://provenanceauth.com/docs/authorize/guides/verify-tokens.md) as intent tokens).
2. **The agent authorizes under it.** Each authorize sends the `mandate_token`, and the intent token is tied to the grant.
3. **Verify enforces it.** Each verify checks the grant and its limits, then your policy, then debits the budget.

1. **Grant**: limits, budget, expiry
2. **Authorize**: intent token under the grant
3. **Verify**: limits → policy → budget debit

Verify runs its checks in this order, and stops at the first failure:

| Check | Fails with |
| --- | --- |
| The token's signature, expiry, description and payload | The usual token reasons, such as `payload_hash_mismatch` |
| The grant is active and not expired | `grant_revoked`, `grant_expired` |
| The action fits the grant's limits | `grant_constraint_violated`, with `grant_detail` |
| The amount is in the grant's `currency`, when it states one | `grant_currency_mismatch` |
| The grant has purchases left (`max_uses`, `max_purchases`) | `grant_uses_exhausted`, `grant_purchase_limit_reached` |
| Your account [policy](https://provenanceauth.com/docs/concepts/policies.md) | The policy's reason; no budget is spent |
| The window's budget covers `transaction_amount` | `grant_budget_exceeded`, with `budget_spent` and `budget_limit` |

A grant never bypasses your policy. The budget is debited atomically, so concurrent verifies can't spend the same budget twice. Each valid verify debits, so verify once, right before the action runs.

A store on Authorize spends from the same budget. When the agent shows the grant (or a token minted under it) at a store's [checkout assessment](https://provenanceauth.com/docs/authorize/guides/assess-checkouts.md) and the cart goes through, the cart's total is debited from the window. A cart the budget can't take is challenged. One cart spends once, whether the store, your verify call or both see it.

Each debit also writes a spend entry: its kind (`verify` or `checkout`), amount, currency and what caused it (the decision, the assessment, the token). [`GET /v1/mandate/grants/{id}/spend`](https://provenanceauth.com/docs/api/grants.md#get-v1-mandate-grants-id-spend) lists them, newest first. A verify pass and a store-covered cart are each one purchase for `max_uses` and `max_purchases`; a cart counted at the store and verified later is still one.

## Key fields

- `max_amount` (number | null): The most a single action may be. Compared with `context.transaction_amount` at verify.
- `budget_amount` (number | null): The total allowed per `budget_window`.
- `budget_window` (string | null): `day`, `week` or `month`, counted in UTC.
- `allowed_action_types` (string[]): The allowed `context.action_type` values. Empty allows any.
- `allowed_counterparties` (string[] | null): The allowed `context.counterparty` values. `null` allows any.
- `schedule` (object | null): A standing schedule: one payment per `cadence` (`weekly`, `monthly` or `quarterly`) to one `counterparty`, of `amount_fixed` or up to `amount_max`. A second payment in the same cycle fails with `schedule_already_executed`.
- `heartbeat` (object): Optional check-ins that keep the grant alive; see [heartbeats](#heartbeats).
- `currency` (string): The ISO 4217 code the amounts are in, such as `USD`. An amount in another currency isn't covered: verify needs a matching `context.currency`, and a store's cart must be in it. There is no conversion. Leave it out to compare amounts as plain numbers.
- `max_uses` (integer): Purchases allowed over the grant's whole life. `1` makes it single use. A spent grant stays spent.
- `max_purchases` (integer): Purchases allowed per `purchase_window`: `day`, `week` or `month` in UTC, or `lifetime`. Independent of the budget window.
- `allowed_mcc` (array): Kinds of store by merchant category code: groups such as `{ "group": "lodging" }` or ranges. Checked against the MCC the store declares with the cart. `blocked_mcc` refuses kinds of store; a block wins over every allow list ([kinds of merchant and countries](https://provenanceauth.com/docs/mandate/guides/give-subagents-their-own-limits.md#kinds-of-merchant-and-countries)).
- `blocked_counterparties` (array): Stores refused, matched as `allowed_counterparties` is.
- `allowed_countries` (array): Merchant countries allowed, as `PT` or `620`; `blocked_countries` refuses countries. Checked against the country the store declares.
- `service_window` (object): The dates of what is bought, `{ "from": "2027-03-12", "to": "2027-03-16" }` (both included; for lodging `to` is the check-out date). Separate from `expires_at`. Checked against each cart line's `service_period` ([service dates](https://provenanceauth.com/docs/mandate/guides/give-subagents-their-own-limits.md#service-dates)).
- `over_limit` (object): What each limit does when a cart at a store goes past it: `ask` a person or `refuse`, per lock (`amount`, `budget`, `counterparty`, `currency`, `uses`, `purchases`, `category`, `country`, `block`, `dates`). The amount and budget locks ask up to a margin, `refuse_over: { "percent": 20 }` by default (or a fixed `{ "amount": 300 }` in the grant's currency), and refuse past it. Leave a lock out to follow the grant above, then your [account's settings](https://provenanceauth.com/docs/mandate/guides/give-subagents-their-own-limits.md#over-the-limit).
- `expires_at` (string): When the grant ends. Required.

Beside the constraints, a grant can carry a `purpose` (one line of plain text the person sees with the limits, such as "Restock printer paper for the office"), the `agent_id` of the [registered agent](https://provenanceauth.com/help/personal/concepts/your-agents) that holds it, and `max_depth`, how many levels of subagents may sit below it (default 4). The token then carries `purpose_hash`, the sha256 of the purpose. A grant without them keeps its exact token.

## Budgets

A subagent's budget has two settings, the same on a company grant's child (`budget` on a delegate or a proposal) and on a helper in a person's plan (`budget` beside its `amount`):

| Setting | Field | Value | Label | What it does |
| --- | --- | --- | --- | --- |
| Share | `allocation` | `reserved` | Reserved | Set aside from the parent. Other subagents can't spend it. |
|  |  | `shared` | Flexible share | Drawn from what the parent has left. Nothing is set aside. |
| At the limit | `at_limit` | `stop` | Stop | Anything past the amount is refused. |
|  |  | `ask` | Ask me | The person is asked, up to `ask_up_to` past the amount. Past that, refused. |
|  |  | `continue` | Keep going | Goes past the amount without asking while every budget above has room. |

`ask_up_to` goes with `ask` only: `{ "percent": 20 }` by default, or a fixed `{ "amount": 50 }` in the grant's currency; `null` asks at any amount the parent has room for. Any share works with any limit behaviour. On a company grant, `stop` and `ask` set the budget lock's over-limit setting (`constraints.over_limit.budget`).

Read more in [share the parent's budget](https://provenanceauth.com/docs/mandate/guides/give-subagents-their-own-limits.md#share-the-parents-budget).

The `currency`, the purchase counts, the kinds of store, countries and block lists, the service window and the over-limit settings stay on the server: the token never carries them.

With `max_uses`, the grant shows `uses` and `remaining_uses`; with `max_purchases`, `purchases` in the current window.

A grant token travels to every counterparty, so its `sub` is a per-token subject (`anon_…`), never the device id. Provenance resolves the device from the grant itself, so revoking the device still stops it. Grants given before October 2026 carry the device's UUID until they expire; grant a new one and revoke the old one to replace it.

## Give and use a grant

Give a grant, authorize under it, and verify with the facts the grant checks. Export the sandbox account key first:

**curl**

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5

curl -s $PROVENANCE_API/v1/mandate/grants \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "device_id": "dev_00000000000000000000000000000001",
    "agent_session_id": "sess_ap_1",
    "constraints": {
      "max_amount": 400, "budget_amount": 500, "budget_window": "day",
      "allowed_action_types": ["payment"], "allowed_counterparties": ["acct_brindlecote_supplies"],
      "expires_at": "2027-12-31T23:59:59Z"
    }
  }' | tee mandate.json
export MANDATE_ID=$(jq -r .id mandate.json)
export MANDATE_TOKEN=$(jq -r .mandate_token mandate.json)
```

**Node**

```ts
import { Provenance } from "@provenanceauth/sdk";

const prov = new Provenance({ apiKey: process.env.PROVENANCE_KEY!, baseUrl: process.env.PROVENANCE_API });
const mandate = await prov.mandate.grants.create({
  deviceId: "dev_00000000000000000000000000000001",
  agentSessionId: "sess_ap_1",
  constraints: {
    maxAmount: 400, budgetAmount: 500, budgetWindow: "day",
    allowedActionTypes: ["payment"], allowedCounterparties: ["acct_brindlecote_supplies"],
    expiresAt: "2027-12-31T23:59:59Z",
  },
});
```

**Python**

```python
import os
from provenanceauth import Provenance

prov = Provenance(os.environ["PROVENANCE_KEY"], base_url=os.environ["PROVENANCE_API"])
mandate = prov.mandate.grants.create(
    device_id="dev_00000000000000000000000000000001",
    agent_session_id="sess_ap_1",
    constraints={
        "max_amount": 400, "budget_amount": 500, "budget_window": "day",
        "allowed_action_types": ["payment"], "allowed_counterparties": ["acct_brindlecote_supplies"],
        "expires_at": "2027-12-31T23:59:59Z",
    },
)
```

The response, trimmed:

```json
{
  "id": "grt_01M5Q33ZKY22JZP271J6VF93B0",
  "object": "grant",
  "status": "active",
  "agent_session_id": "sess_ap_1",
  "approval_context": null,
  "remaining_budget": 500,
  "mandate_token": "eyJhbGciOiJFUzI1NiIsInR5cCI6Im1hbmRhdGUrand0In0.eyJpc3MiOiJwcm92ZW5hbmNlLWF1dGhvcml6ZSJ9.HBZ1gq7tZyq7p7KhKbGDj3Rrcn9DRckwHHvkF7B-L7plT84vCNY1BVBAKlAv5Y8LywQwU0I3rxTBG3qQCk0bCQ"
}
```

The agent authorizes a payment under the grant:

**curl**

```bash
curl -s $PROVENANCE_API/v1/mandate/intents \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "action_description": "Pay invoice INV-2041: $300.00 to Brindlecote Supplies",
    "agent_session_id": "sess_ap_1",
    "device_id": "dev_00000000000000000000000000000001",
    "mandate_token": "'"$MANDATE_TOKEN"'"
  }' | tee authorization.json
export INTENT_TOKEN=$(jq -r .intent_token authorization.json)
```

**Node**

```ts
const auth = await prov.mandate.intents.create({
  actionDescription: "Pay invoice INV-2041: $300.00 to Brindlecote Supplies",
  agentSessionId: "sess_ap_1",
  deviceId: "dev_00000000000000000000000000000001",
  mandateToken: mandate.mandateToken,
});
```

**Python**

```python
auth = prov.mandate.intents.create(
    action_description="Pay invoice INV-2041: $300.00 to Brindlecote Supplies",
    agent_session_id="sess_ap_1",
    device_id="dev_00000000000000000000000000000001",
    mandate_token=mandate["mandate_token"],
)
```

```json
{
  "object": "intent_authorization",
  "intent_token": "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJwcm92ZW5hbmNlLWF1dGhvcml6ZSJ9.mnIslW_8ZGoSLdXzXXOBtTAEpAQ1Ht05ruMPMJAwMdPnFwyggE1iabNZHTC4_9yYhhPu62ijzHhPqhyZ09wfdw",
  "expires_at": "2026-10-24T17:55:32.000Z",
  "biometric_bound": false
}
```

The executor verifies with the amount, action type and counterparty in `context`. A counterparty outside the grant fails before anything is spent:

**curl**

```bash
curl $PROVENANCE_API/v1/mandate/assessments \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "intent_token": "'"$INTENT_TOKEN"'",
    "action_description": "Pay invoice INV-2041: $300.00 to Brindlecote Supplies",
    "context": { "transaction_amount": 300, "action_type": "payment", "counterparty": "acct_unknown_vendor" }
  }'
```

**Node**

```ts
const check = await prov.mandate.assessments.create({
  intentToken: auth.intentToken,
  actionDescription: "Pay invoice INV-2041: $300.00 to Brindlecote Supplies",
  context: { transactionAmount: 300, actionType: "payment", counterparty: "acct_unknown_vendor" },
});
```

**Python**

```python
check = prov.mandate.assessments.create(
    intent_token=auth["intent_token"],
    action_description="Pay invoice INV-2041: $300.00 to Brindlecote Supplies",
    context={"transaction_amount": 300, "action_type": "payment", "counterparty": "acct_unknown_vendor"},
)
```

```json
{
  "object": "mandate_assessment",
  "valid": false,
  "reason": "grant_constraint_violated",
  "grant_detail": "counterparty not permitted by mandate"
}
```

With `"counterparty": "acct_brindlecote_supplies"` the verify is valid and the day's remaining budget drops to 200. Read it with [`GET /v1/mandate/grants/{id}`](https://provenanceauth.com/docs/api/grants.md#get-v1-mandate-grants-id).

## Allow it in your product

Instead of building the "allow this agent" screen and the passkey prompt yourself, create a draft and show it in [`<provenance-grant>`](https://provenanceauth.com/docs/embeds.md#8-agents-and-appeals-in-your-product):

1. [`POST /v1/mandate/grant_drafts`](https://provenanceauth.com/docs/api/grants.md#post-v1-mandate-grant-drafts) with the device, the agent's name and the constraints. The draft lasts up to 15 minutes (`expires_in`) and creates nothing until it's allowed.
2. Mint a `mandate` embed token for the draft's `id`. The component shows each limit in plain words, such as "Only at quillstack.example", "Check in every month" and "Until Dec 31", with amounts in the draft's `currency`.
3. The person taps **Allow** and their passkey signs a challenge bound to this draft and its exact limits. Provenance grants the same grant `POST /v1/mandate/grants` would, with an `approval_context` that records how the person allowed it ([approval context](https://provenanceauth.com/docs/concepts/approval-context.md)).
4. [`GET /v1/mandate/grant_drafts/{id}`](https://provenanceauth.com/docs/api/grants.md#get-v1-mandate-grant-drafts-id) returns `status: granted`, the `grant_id` and the `mandate_token` for your agent.

**Not now** closes the draft (`declined`) and nothing is set up. A draft that's already allowed, declined or past its 15 minutes answers `409 grant_draft_closed`. The same component with `mode="checkin"` runs the check-in below, and [`<provenance-agent-access>`](https://provenanceauth.com/docs/embeds.md#8-agents-and-appeals-in-your-product) lists a person's grants on your account with a Turn off button for each.

## Heartbeats

A heartbeat keeps a long-lived grant tied to the person's attention: they check in each period with a passkey, or the grant suspends. Add it at grant time as `"heartbeat": { "interval": "weekly", "grace_hours": 72 }`. The interval can be weekly, every two weeks (`biweekly`) or monthly. A grant confirmed with a passkey counts as the first check-in, so the next one is due at the start of the next period plus `grace_hours`; a grant without a passkey needs a check-in in its first period.

In your product, `<provenance-grant mode="checkin">` does the whole check-in: it shows the spend this window and the limits, and **Keep it on** signs the period's challenge with the person's passkey. To check in through the API, get the period's challenge from [`GET /v1/mandate/grants/{id}/heartbeat/challenge`](https://provenanceauth.com/docs/api/grants.md#get-v1-mandate-grants-id-heartbeat-challenge), sign it with a passkey as in [biometric approval](https://provenanceauth.com/docs/mandate/guides/biometric-approval.md), and post the assertion to [`POST /v1/mandate/grants/{id}/heartbeat`](https://provenanceauth.com/docs/api/grants.md#post-v1-mandate-grants-id-heartbeat). The challenge changes every period, so an old check-in can't be replayed.

| State | What happens |
| --- | --- |
| Checked in this period | The grant works as usual. |
| Missed, past `grace_hours` | The grant suspends: verify fails with `grant_heartbeat_lapsed`, the `mandate.grant.heartbeat_lapsed` [webhook](https://provenanceauth.com/docs/integrate/webhooks.md) fires, and the person is notified. |
| Checked in within 7 days of suspending | The grant is active again. |
| No check-in after that | The grant expires for good. |

## Revoke a grant

Revoke with [`POST /v1/mandate/grants/{id}/revoke`](https://provenanceauth.com/docs/api/grants.md#post-v1-mandate-grants-id-revoke). Every token minted under it then fails verify with `grant_revoked`. Revoking again returns the same result.

When the person turns a grant off themselves in your product, with [`<provenance-agent-access>`](https://provenanceauth.com/docs/embeds.md#8-agents-and-appeals-in-your-product) (one agent or Turn off all) or a check-in's Turn it off, you get a `mandate.grant.revoked` [webhook](https://provenanceauth.com/docs/integrate/webhooks.md) for each one.

**curl**

```bash
curl $PROVENANCE_API/v1/mandate/grants/$MANDATE_ID/revoke \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "reason": "supplier contract ended" }'
```

**Node**

```ts
await prov.mandate.grants.revoke(mandate.id);
```

**Python**

```python
prov.mandate.grants.revoke(mandate["id"], reason="supplier contract ended")
```

```json
{
  "id": "grt_01M5Q33ZKY22JZP271J6VF93B0",
  "object": "grant",
  "status": "revoked"
}
```

## Delegate to subagents

An agent that starts subagents gives each one its own child grant with [`POST /v1/mandate/grants/{id}/delegate`](https://provenanceauth.com/docs/api/grants.md#post-v1-mandate-grants-id-delegate): narrower limits, its own session and its own purpose, with no passkey. Every spend under a child counts against its own budget and every budget above it, and revoking a grant revokes everything delegated below it. See [delegate to subagents](https://provenanceauth.com/docs/mandate/guides/give-subagents-their-own-limits.md). An agent asked by another agent checks the asker's grant with `verifyMandate`; see [check an agent's grant](https://provenanceauth.com/docs/mandate/guides/check-another-agents-authority.md).

## Offline checks and the budget

A verifier checking a grant-bound token [offline](https://provenanceauth.com/docs/authorize/guides/verify-tokens.md) sees the grant's ID and fixed limits in the token, but not how much budget is left: the budget lives on the server and is debited at verify. For anything that spends, call [`POST /v1/mandate/assessments`](https://provenanceauth.com/docs/api/intent-tokens.md#post-v1-mandate-assessments).

## Related

- [Agent payments](https://provenanceauth.com/docs/authorize/guides/agent-payments.md), for grants as AP2 open Payment Mandates
- [Policies](https://provenanceauth.com/docs/concepts/policies.md)
- [Delegate to subagents](https://provenanceauth.com/docs/mandate/guides/give-subagents-their-own-limits.md)
- [Decision ledger](https://provenanceauth.com/docs/mandate/concepts/decision-ledger.md), which records each decision with its grant
