# Monthly credits

> Learn how Shaw meters template pages in credits, grants lifetime updates per unlocked page, supports Auto Top-Up, and handles 402 errors.

Shaw meters per-page code unlocks (`POST /api/templates/use` / `use_template`)
and direct library email imports to Klaviyo
(`POST /api/email-studio/klaviyo/publish-template` /
`publish_template_to_klaviyo`) based on each page's HTML and linked CSS bundle.
Browsing the catalog, inspecting Brand DNA, and checking per-page credit costs
are always **free (0 credits)**.

## Interactive credit estimator [#interactive-credit-estimator]

Estimate how many credits a template page consumes on Free vs. Shaw Pro:

<CreditCalculator />

## How per-page credit pricing works [#how-per-page-credit-pricing-works]

Shaw calculates each page's credit cost from the single-page HTML + linked CSS
bundle returned to your app or MCP client:

- **Website & app pages:** `5,000` to `15,000` credits per pulled page (`5,000
credits` minimum and `15,000 credits` maximum cap per page). Multi-page
  subpages are unlocked individually only when pulled.
- **Email templates:** starting at **`2,500 credits`** (`2,500 credits` minimum
  for nearly every email, scaling up for larger HTML/CSS emails).
- **Measured code:** The requested page HTML plus up to 6 linked local `.css`
  stylesheets (capped at `120 KiB` bundle size).
- **Binary assets excluded:** Images (`.png`, `.jpg`, `.webp`), `.woff2` fonts,
  and media files add `0` credits.
- **Pre-flight cost preview:** `GET /api/templates/detail/{id}` (`get_template`,
  with optional `path` query parameter) returns `codeMetrics` (`credits`,
  `codeBytes`, `fileCount`, `estimated`) at `0` credit cost before you spend
  anything.

## Monthly plans, credit packs, & lifetime updates [#monthly-plans-credit-packs--lifetime-updates]

Monthly credit allowances reset at **00:00 UTC** on the first day of each
calendar month (`YYYY-MM` period key, such as `2026-11`) and offer a discounted
per-credit rate compared to one-time packs. Purchased one-time credit packs
never expire and are spent FIFO only after your monthly allowance is exhausted.

| Tier / Pack      | Credits                           | Details                                                               | Purchase / Upgrade path                    |
| ---------------- | --------------------------------- | --------------------------------------------------------------------- | ------------------------------------------ |
| **Free**         | `5,000` credits (one-time)        | 2 emails or 1 light page ($0)                                         | [shaw.ai/credits](https://shaw.ai/credits) |
| **Shaw Plus**    | `30,000` credits / month          | $20/month (33% off the $1.00/1,000 base rate at $0.667/1,000 credits) | Stripe Checkout on Credits                 |
| **Shaw Pro**     | `100,000` credits / month         | $50/month (50% off the $1.00/1,000 base rate at $0.50/1,000 credits)  | Stripe Checkout on Credits                 |
| **Shaw Ultra**   | `500,000` credits / month         | $200/month (60% off the $1.00/1,000 base rate at $0.40/1,000 credits) | Stripe Checkout on Credits                 |
| **Operator**     | `1,000,000` credits / month       | Managed operator workspace                                            | Managed operator workspace                 |
| **15,000 Pack**  | `15,000` one-time credits ($15)   | Never expires ($1.00 per 1,000 credits)                               | Account / Credits pack checkout            |
| **60,000 Pack**  | `60,000` one-time credits ($50)   | Never expires ($0.833 per 1,000 credits — Save 17%)                   | Account / Credits pack checkout            |
| **150,000 Pack** | `150,000` one-time credits ($100) | Never expires ($0.667 per 1,000 credits — Save 33%)                   | Account / Credits pack checkout            |

### Lifetime updates per unlocked page [#lifetime-updates-per-unlocked-page]

Credits are charged **once permanently per
`(organizationId, templateSlug, pagePath)`** (with emails normalized to `"/"`),
independent of template version:

- **Lifetime updates across future versions:** Unlocking `v1` of a template page
  grants lifetime updates on that page for your organization. When `v2` ships,
  re-fetching `v2` HTML and CSS with `POST /api/templates/use` (`use_template`)
  costs **`0` extra credits forever** (`alreadyUnlocked: true`,
  `chargedCredits: 0`) across billing months—even when remaining credits reach
  `0`.
- **Per-path & per-organization boundaries:** Subpages (such as `/` vs.
  `/pricing`) and organizations remain independently unlocked.
- **Atomic FIFO ledger:** Credits are spent from monthly allowance first, then
  oldest credit packs FIFO, and enforced atomically in D1 so concurrent requests
  cannot overspend.

## Opt-in Auto Top-Up & passive Stripe metering [#opt-in-auto-top-up--passive-stripe-metering]

Organizations can opt into **Auto Top-Up** in
[shaw.ai/app/account](https://shaw.ai/app/account) so unlocks never stall on
`402 INSUFFICIENT_CREDITS` when monthly credits run low:

- **Saved payment method required:** Save a card off-session via `POST`
  `/api/billing/payment-method/setup` before enabling Auto Top-Up. Turning on
  Auto Top-Up without a saved card is rejected (`400 PAYMENT_METHOD_REQUIRED`).
- **Threshold & monthly dollar cap:** Configure the refill pack (`pack_50000`,
  `pack_200000`, or `pack_500000`), trigger threshold (`thresholdCredits`), and
  hard monthly spend cap (`monthlyCapCents`) via `GET` / `PUT`
  `/api/billing/auto-topup`.
- **Transparent refill & safe fallback:** When an unlock exceeds available
  credits (or leaves remaining credits below `thresholdCredits`), Shaw charges
  the saved card off-session, grants a non-expiring `stripe_auto_topup` credit
  pack, and completes the unlock cleanly (`autoTopUpTriggered: true`). If the
  card declines or the monthly dollar cap is reached, Shaw returns `402` with
  `autoTopUpError` or `autoTopUpCapReached: true`.
- **Optional passive Stripe Billing Metering:** Deployments that configure
  `STRIPE_BILLING_METER_EVENT_NAME` also emit passive credit usage meter events
  to Stripe Billing in the background for usage analytics and reconciliation
  without changing the D1 ledger or charging twice.

## Checking balance & handling 402 errors [#checking-balance--handling-402-errors]

<EndpointCard
  method="GET"
  path="/api/credits"
  scope="org:read"
  href="/api-reference/credits"
>
  Return the organization plan, UTC period key, monthly credit allowance,
  remaining monthly and pack credits, Auto Top-Up status, and permanently
  unlocked template pages.
</EndpointCard>

<EndpointCard
  method="POST"
  path="/api/templates/use"
  scope="pages:read"
  href="/api-reference/templates"
>
  Spend credits for a page (if not yet permanently unlocked) and return the page
  HTML plus up to 6 linked stylesheets (120 KiB response bundle). Future
  versions of unlocked pages re-fetch at 0 credits.
</EndpointCard>

<SplitSection>
  <SplitProse>

### Balance & insufficient credit responses [#balance--insufficient-credit-responses]

Poll `GET /api/credits` (`org:read`) before triggering batch workflows:

- **Balance check** <StatusBadge code={200} label="OK" /> — returns `plan`,
  `periodKey` (`YYYY-MM`), `planCredits`, `monthlyUsedCredits`,
  `monthlyRemainingCredits`, `packCreditsRemaining`, `remainingCredits`,
  `packs`, `autoTopUp`, and permanently `unlockedTemplates`.
- **Credit limit reached** <StatusBadge code={402} label="Payment Required" /> —
  returned by `POST /api/templates/use` or
  `POST /api/email-studio/klaviyo/publish-template` with
  `code: "INSUFFICIENT_CREDITS"` and `error: "You need more credits"` when
  `requiredCredits > remainingCredits` and Auto Top-Up is disabled, fails, or
  reaches its monthly dollar cap.

**Recommended agent & client behavior on `402`:**

1. Do **not** retry automatically—the ledger will continue rejecting the spend
   until a credit pack is purchased, Auto Top-Up cap/card is updated, the plan
   is upgraded, or the UTC month rolls over.
2. Surface `requiredCredits`, `remainingCredits`, and any `autoTopUpError` or
   `autoTopUpCapReached` fields to the user.
3. Direct the user to `upgradeUrl`
   ([shaw.ai/credits](https://shaw.ai/credits)) to subscribe to **Plus**
   (`30,000 credits/month` at `$20/month`), **Pro** (`100,000 credits/month`
   at `$50/month`), or **Ultra** (`500,000 credits/month` at `$200/month`),
   buy a one-time credit pack (`15,000`, `60,000`, or `150,000 credits`), or
   enable **Auto Top-Up**.

  </SplitProse>
  <SplitCode title="Credits balance (200) & INSUFFICIENT_CREDITS (402)">

<Tabs items={["200 Balance", "402 Insufficient"]}>
  <Tab value="200 Balance">

```json
{
  "ok": true,
  "data": {
    "organizationId": "org_01j9x2m4p7q8w2ab",
    "plan": "free",
    "periodKey": "2026-11",
    "planCredits": 5000,
    "monthlyUsedCredits": 2500,
    "monthlyRemainingCredits": 2500,
    "packCreditsRemaining": 50000,
    "usedCredits": 2500,
    "remainingCredits": 52500,
    "locPerCredit": 1,
    "approxRemainingLoc": 52500,
    "unlockedTemplates": [
      {
        "templateSlug": "aura/landing",
        "templateVersion": "2026-11-01",
        "slug": "aura/landing",
        "version": "2026-11-01",
        "pagePath": "/",
        "loc": 4200,
        "creditsSpent": 5000,
        "unlockedAt": "2026-11-21T14:20:00.000Z"
      }
    ],
    "packs": [
      {
        "id": "pack_01j9x2m4p7q8w2ab",
        "packId": "pack_50000",
        "creditsTotal": 50000,
        "creditsRemaining": 50000,
        "priceCents": 1500,
        "source": "stripe_checkout",
        "createdAt": "2026-11-20T09:00:00.000Z"
      }
    ],
    "autoTopUp": {
      "enabled": true,
      "packId": "pack_50000",
      "thresholdCredits": 5000,
      "monthlyCapCents": 10000,
      "hasPaymentMethod": true,
      "cardBrand": "visa",
      "cardLast4": "4242",
      "monthlySpendCents": 0,
      "monthlyRemainingCapCents": 10000,
      "lastError": null,
      "lastRefilledAt": null
    },
    "upgradeUrl": "https://shaw.ai/app/account"
  }
}
```

  </Tab>
  <Tab value="402 Insufficient">

```json
{
  "ok": false,
  "error": "You need more credits",
  "code": "INSUFFICIENT_CREDITS",
  "message": "You need more credits",
  "requiredCredits": 8500,
  "remainingCredits": 2500,
  "monthlyRemainingCredits": 2500,
  "packCreditsRemaining": 0,
  "planCredits": 5000,
  "usedCredits": 2500,
  "loc": 8500,
  "plan": "free",
  "upgradeAvailable": true,
  "upgradeUrl": "https://shaw.ai/app/account",
  "autoTopUpTriggered": false,
  "autoTopUpCapReached": false
}
```

  </Tab>
</Tabs>

  </SplitCode>
</SplitSection>

## Next steps [#next-steps]

- Connect Claude, ChatGPT, Codex, or Cursor in
  [Claude, ChatGPT & MCP Plugin](/developers/mcp).
- Check OAuth scopes and error handling in
  [Authentication & API keys](/developers/authentication).
- Explore the [Credits API Reference](/api-reference/credits) and
  [Templates API Reference](/api-reference/templates).

