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

# Plans per workspace or user

> Put each workspace, project or user inside a customer on a plan of its own, with its own credits and allowances, all billed on the customer's one invoice.

> **Workspace Pro at \$20 a month for each workspace, on the account's invoice.**

Sell plans to the workspaces, projects or users inside a customer: one workspace on Workspace Pro, another on the free tier, each with its own credits and allowances. Every entity plan is billed on the customer's one Stripe invoice, so the account pays once while each workspace gets what its plan includes.

An entity plan is an ordinary plan attached with an `entityId`. Create the [entity](https://docs.integrateledger.com/customers/entities.md) first, then attach.

## The catalog

```ts ledger.config.ts theme={"system"}
import { defineCatalog, feature, plan } from "integrateledger-cli";

export default defineCatalog({
	features: [
		feature({ id: "generate", name: "Generate", creditCost: 1 }),
		feature({ id: "exports", name: "Exports", type: "metered" }),
	],
	plans: [
		plan({
			id: "team",
			name: "Team",
			monthlyCredits: 1000,
			priceCents: 4900,
		}),
		plan({
			id: "workspace_pro",
			name: "Workspace Pro",
			monthlyCredits: 5000,
			priceCents: 2000,
			items: [{ featureId: "exports", included: 200 }],
		}),
	],
});
```

```json ledger.catalog.json theme={"system"}
{
  "schemaVersion": 1,
  "features": [
    { "id": "generate", "name": "Generate", "creditCost": 1 },
    { "id": "exports", "name": "Exports", "type": "metered" }
  ],
  "plans": [
    { "id": "team", "name": "Team", "monthlyCredits": 1000, "priceCents": 4900 },
    { "id": "workspace_pro", "name": "Workspace Pro", "monthlyCredits": 5000,
      "priceCents": 2000,
      "items": [{ "featureId": "exports", "included": 200 }] }
  ]
}
```

| Field | What it sets |
| - | - |
| `entityGrants` | `own` (the default): the plan's credits and allowances belong to the entity it's attached to. `pooled`: they join the customer's shared pool. Changing it publishes a new plan version |
| `group` | Optional. An entity holds one plan per [group](https://docs.integrateledger.com/pricing/plan-groups.md), as a customer does, apart from the customer's own plans |

## Attach a plan to an entity

The customer holds Team; attach Workspace Pro to workspace `ws-1` with `entityId` and an `Idempotency-Key`:

```typescript TypeScript theme={"system"}
await billing.upsertEntity({ customerId: "acme", entityId: "ws-1" });

const change = await billing.attach(
	{ customerId: "acme", planId: "workspace_pro", entityId: "ws-1" },
	{ headers: { "Idempotency-Key": `ws-1-pro-${purchase.id}` } }, // saved when the customer confirmed
);
if ("itemChangeId" in change && change.paymentUrl) {
	return res.redirect(303, change.paymentUrl);
}
```

```python Python theme={"system"}
billing.upsert_entity(customer_id="acme", entity_id="ws-1")

change = billing.attach(
    customer_id="acme",
    plan_id="workspace_pro",
    entity_id="ws-1",
    idempotency_key=f"ws-1-pro-{purchase.id}",  # saved when the customer confirmed
)
if "itemChangeId" in change and change.get("paymentUrl"):
    return redirect(change["paymentUrl"], code=303)
```

```bash cURL theme={"system"}
curl https://api.integrateledger.com/v1/billing/attach \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: ws-1-pro" \
  -d '{"customerId": "acme", "planId": "workspace_pro", "entityId": "ws-1"}'
```

```json Response theme={"system"}
{
  "itemChangeId": 64,
  "status": "applied",
  "paymentUrl": null,
  "item": { "planId": "workspace_pro", "quantity": 1 }
}
```

`status` reads as for an [add-on](https://docs.integrateledger.com/pricing/add-ons.md#attach-it): `applied` once the prorated invoice is paid, `pending_payment` with a `paymentUrl` when the card needs the customer, `processing` while Stripe settles, and `closed` when it was never paid. A free entity plan answers `applied` at once, with `itemChangeId: null`.

[Get an entity](https://docs.integrateledger.com/api-reference/entities/get.md) lists its `plans`, each with `planId`, `group`, `status` (`pending`, `active` or `canceling`), `startsAt` and `endsAt`.

## How it bills on the customer's bill

* **One invoice.** A paid entity plan is a prorated change on the customer's Stripe bill of the plan's interval. Entities on the same plan share one Stripe item, its quantity counting them: three workspaces on Workspace Pro are one line at quantity 3.
* **Prorated now, full at renewal.** Attaching charges for the unused share of the period. The plan's credits and allowances are prorated the same way, rounded down, then granted in full at each renewal of the customer's bill.
* **Free entity plans** change nothing in Stripe. They ride on the customer's bill and are granted with each of its periods.
* **Upgrades.** [Upgrade](https://docs.integrateledger.com/api-reference/billing/upgrade.md) with `entityId` to move one entity to a pricier plan in the same group: one prorated Stripe change, with the period kept. Other entities on the old plan stay on it.
* **The bill ends, the plans end.** When the customer's bill ends, every entity plan on it ends with it.

## Own or pooled grants

| `entityGrants` | Where the plan's credits and allowances go | Who spends them |
| - | - | - |
| `own` | To the entity | Requests with that `entityId` only. A request without `entityId` never spends them |
| `pooled` | To the customer's shared pool | Any request for the customer, with or without an `entityId`. Its items count for everyone too: metered allowances, booleans and held limits |

Use `own` when each workspace buys its own capacity, and `pooled` when each workspace plan should raise what the whole account can use.

## Spend order

With `entityId`, check, track and reservations spend:

1. **The entity's own credits**: its [allowance](https://docs.integrateledger.com/customers/entities.md) and its plans' `own` grants.
2. **The customer's shared pool**, in [spend order](https://docs.integrateledger.com/concepts/balances.md#spend-order-for-credits), within the entity's cap if it has one.
3. **Overage**, at the customer's plan's rates.

For metered features, the entity's own grants are spent first, then the customer's. Booleans combine the customer's plans with the entity's: a boolean feature on an `own` Workspace Pro is on for requests with that `entityId`, and on a `pooled` one for every request.

## Held limits by scope

A [held limit](https://docs.integrateledger.com/pricing/limits.md) follows the same split. An entity's `own` plans and add-ons give a limit only that entity uses, and past it the entity draws on the shared limit, which the customer's own plans and `pooled` entity plans give. With 10 projects on Team and 5 on an `own` Workspace Pro for `ws-1`, `ws-1` can hold 5 projects of its own, then share the 10 with everyone else. The count Ledger keeps stays the customer's total.

## Rules

* **The customer's bill comes first.** A paid entity plan joins a paid bill of its interval (`409 entity_plan_needs_paid_bill`); a free one needs the customer to hold a plan (`409 entity_plan_needs_bill`).
* **One plan per group, per entity** (`409 subscription_exists`). Change it with upgrade, passing `entityId`.
* **Entity plans recur.** Attach a monthly or yearly plan (`400 entity_plan_must_recur`).
* **A Price of its own.** An entity plan bills on a different Stripe Price from the customer's own plan (`409 entity_plan_shares_base_price`).
* **Moves are upgrades.** An entity's plan moves by upgrade (`409 downgrade_unavailable_for_item`).
* **Overage stays the customer's.** Usage past what the entity holds bills at the customer's plan's overage terms.
* **The entity stays while its plan runs.** Deleting an entity that holds a plan returns `409 entity_has_plan`, so a delete never changes what the customer pays.
* **The entity exists first** (`404 entity_not_found`).

## Related

* [Entities](https://docs.integrateledger.com/customers/entities.md): allowances and caps per user, seat or workspace.
* [Plan groups](https://docs.integrateledger.com/pricing/plan-groups.md): one plan per product line.
* [Per-seat pricing](https://docs.integrateledger.com/pricing/per-seat.md): a price per seat on the customer's own plan.


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