# Map your pricing model to a policy

> Turn a pricing page into a Limitr policy, line by line, for usage-based, seat-based, credit-based, flat, and hybrid pricing.

# Map your pricing to a policy

Start from your pricing page, or the one you want. Every line on it maps to a piece of a policy.

## The pricing page

| | Starter (free) | Team ($49/mo) | Enterprise |
|---|---|---|---|
| Projects | 3 | Unlimited | Unlimited |
| AI assistant | 50k tokens a month | 2M tokens a month, then $20 per million | Contract |
| Seats | 1 | 5 included, $12 per extra seat | Contract |
| API | | 100k requests a month | Contract |
| CSV export | Yes | Yes | Yes |
| PDF export | | Yes | Yes |
| SSO | | | Yes |
| Token packs | | 1M tokens for $15 | |

## Step by step

1. **List what you count.** Each countable thing is a [credit](../reference/credits): projects, AI tokens, seats,
   requests. Put the price on the credit when you charge for it past an allowance, and the cost when it costs you
   something. When a model's input and output are priced differently, give each its own credit
   (`sonnet_input`, `sonnet_output`); see [AI costs per model](./ai-token-costs).
2. **One plan per column.** The [plan](../reference/plans) customers get by default gets `default: true`.
3. **One entitlement per row.** Use the same entitlement name in every plan, so your code doesn't care which plan a
   customer is on.
   - A **Yes** (a feature) is an entitlement with no limit.
   - A **number** is a limit. Pick the [mode](../reference/entitlements#modes): `hard` when the plan stops there,
     `soft` when usage past it is billed, `observe` when it's only tracked.
   - **Unlimited** is a feature (no limit), or an `observe` limit when you still want to count it.
   - **A blank** is no entitlement in that plan: the call is denied.
4. **Monthly allowances reset.** `resets: true, reset_sch: 'monthly:1'` for calendar months, or `reset_inc: 30days`
   for 30 days from first use.
5. **The plan fee** is a `subscription` entitlement metered in a credit priced at the fee. See
   [Plan fees](../reference/plans#plan-fees).
6. **Packs** are [topups](../reference/grants-and-topups).
7. **Enterprise** is usually a plan with generous limits that you adjust per customer with
   [overrides and gives](./custom-deals), rather than a plan per customer.
8. **Protection you don't sell** (a rate limit, an abuse ceiling) can share the row's entitlement when the two limits
   are the same, or get an entitlement of its own when they differ. See [Rate limits](./rate-limits).

## The policy

```stof
policy: {
    credits: {
        project: { label: 'Project' }
        // You charge $20 per million tokens, and they cost you $8 per million.
        ai_token: { label: 'AI token', price: { amount: 0.00002 }, overhead_cost: 0.000008 }
        seat: { label: 'Seat', price: { amount: 12 } }
        request: { label: 'API request' }
        team_month: { label: 'Team plan, monthly', price: { amount: 49 } }
    }
    plans: {
        starter: {
            label: 'Starter'
            default: true
            entitlements: {
                projects: { limit: { credit: 'project', value: 3 } }
                ai_assistant: {
                    limit: {
                        credit: 'ai_token', value: 50_000
                        resets: true, reset_sch: 'monthly:1'
                    }
                }
                seats: { scope: 'org', limit: { credit: 'seat', value: 1 } }
                export_csv: {}
            }
        }
        team: {
            label: 'Team'
            entitlements: {
                subscription: {
                    limit: {
                        credit: 'team_month', mode: 'soft', value: 0
                        resets: true, reset_sch: 'monthly:1'
                    }
                }
                // unlimited, still counted
                projects: { limit: { credit: 'project', mode: 'observe', value: 0 } }
                ai_assistant: {
                    limit: {
                        credit: 'ai_token', mode: 'soft', value: 2_000_000
                        resets: true, reset_sch: 'monthly:1'
                    }
                }
                seats: { scope: 'org', limit: { credit: 'seat', mode: 'soft', value: 5 } }
                api: {
                    limit: {
                        credit: 'request', value: 100_000
                        resets: true, reset_sch: 'monthly:1'
                    }
                }
                export_csv: {}
                export_pdf: {}
            }
            topups: {
                tokens_1m: { credit: 'ai_token', value: 1_000_000, price: { amount: 15 } }
            }
        }
        enterprise: {
            label: 'Enterprise'
            hidden: true
            entitlements: {
                projects: { limit: { credit: 'project', mode: 'observe', value: 0 } }
                ai_assistant: {
                    limit: {
                        credit: 'ai_token', mode: 'soft', value: 20_000_000
                        resets: true, reset_sch: 'monthly:1'
                    }
                }
                seats: {
                    scope: 'org'
                    limit: { credit: 'seat', mode: 'soft', value: 50 }
                }
                api: {
                    limit: {
                        credit: 'request', mode: 'soft', value: 5_000_000
                        resets: true, reset_sch: 'monthly:1'
                    }
                }
                export_csv: {}
                export_pdf: {}
                sso: {}
            }
        }
    }
}
```

Your code is the same for every plan:

<Tabs groupId="lang" queryString>
<TabItem value="typescript" label="TypeScript">

```ts
await limitr.ensureCustomer(orgId, 'team', 'org');
// On their org's plan
await limitr.ensureCustomer(userId, '', 'user', name, [orgId]);

if (!(await limitr.allow(userId, 'projects', 1))) return upgrade('projects');
if (!(await limitr.allow(userId, 'export_pdf'))) return upgrade('export_pdf');
```

</TabItem>
<TabItem value="python" label="Python">

```python
limitr.ensure_customer(org_id, 'team', 'org')
# On their org's plan
limitr.ensure_customer(user_id, '', 'user', name, [org_id])

if not limitr.allow(user_id, 'projects', 1):
    return upgrade('projects')
if not limitr.allow(user_id, 'export_pdf'):
    return upgrade('export_pdf')
```

</TabItem>
</Tabs>

## Pricing models

| Model | In a policy |
|---|---|
| **Usage-based** (pay for what you use) | A soft limit with `value: 0`: every unit is billed at the credit's price. |
| **AI usage per model** | A credit per model and direction, each billed at its own price. See [AI costs per model](./ai-token-costs). |
| **Allowance plus overage** | A soft limit at the allowance, resetting monthly. Bill `meter-overage`. |
| **Hard caps per tier** | Hard limits; the upgrade is the way past them. |
| **Seats** | A seats entitlement with `scope: 'org'`, `increment` on invite and `decrement` on removal. See [Seats](./seats). |
| **Prepaid credits** | Limits at 0, priced credits, and a shared credit granted by topups. See [Prepaid credits](./prepaid-credits). |
| **Flat fee** | A `subscription` entitlement priced at the fee. |
| **Volume discounts** | A credit with `tiered`, `volume`, or `stairstep` [pricing](../reference/credits#pricing-models). |
| **Hybrid** | Any mix of the above in one plan: a fee, seats, and metered AI usage. |
| **Spend limits** | [Spend caps](./budgets), per customer or shared across an org. |
| **Free trial of a feature** | A [give](./custom-deals) with an expiry. |

## Before you ship it

- Validate it: `Limitr.new` throws on mistakes, and `valid()` checks it in CI.
- Test it: write the behavior you expect as [tests](./test-a-policy).
- Check its margin: `marginSnapshot(plan, usage)` prices hypothetical usage for a plan
  ([Cost and margin](../reference/cost-and-margin#margin-snapshots)).
