# Billing API

STACK has two plans: the platform subscription ($19 a month) and controls on top ($4 a month). The platform subscription includes 2,000 actions a month, and the Wallet pays for everything else at provider cost, such as further actions, sealed execution, identity verification and paid skills. A tier subscription that already exists keeps running until its period ends. This API reports both.

The included actions reset on the first of each month at 00:00 UTC. Subscriptions renew monthly from the purchase date. Wallet balance is non-expiring and non-transferable between operators.

## GET /v1/billing/balance

Returns the current Wallet balance in cents and formatted US dollars.

```json
{
  "balance_cents": 12400,
  "balance_usd": "$124.00"
}
```

## GET /v1/billing/transactions

Keyset-paginated wallet transaction history. Each entry is a real credit or debit in the STACK wallet. The response does not include operator IDs, wallet hold IDs, payment IDs, prompts, responses, credentials, or audit payloads.

### Query parameters

- view - timeline to include standalone LLM calls beside wallet movements (optional)
- entry_kind - all | wallet | llm for timeline rows (optional, default: all)
- limit - integer 1-200 (default: 50)
- cursor - next_cursor from the previous page (optional)
- type - topup | refund | invocation | compute | identity | overage | adjustment (optional)
- direction - in for credits or out for debits (optional)
- since - inclusive ISO 8601 timestamp (optional)
- until - exclusive ISO 8601 timestamp (optional)

```json
{
  "total": 51,
  "next_cursor": "wtxn_9fA2...",
  "has_more": true,
  "transactions": [
    {
      "id": "wtxn_9fA2...",
      "type": "compute",
      "amount_cents": -3,
      "meter": "sealed_execution",
      "description": "Compute charge",
      "created_at": "2026-07-15T10:14:00Z",
      "details": {
        "skill_id": "skl_7p...",
        "invocation_id": "inv_4m...",
        "mission_id": "mis_3x...",
        "skill": { "id": "skl_7p...", "name": "Invoice review" },
        "invocation": { "id": "inv_4m...", "status": "completed" },
        "mission": { "id": "mis_3x...", "declared_intent": "Review supplier invoices" },
        "llm_sources": [
          {
            "id": "usg_1a...",
            "created_at": "2026-07-15T10:13:58Z",
            "operation": "Sealed skill execution",
            "declared_purpose": "Review supplier invoices",
            "provider": "openrouter",
            "model": "provider/model",
            "prompt_tokens": 1200,
            "completion_tokens": 300,
            "total_tokens": 1500,
            "cached_prompt_tokens": 800,
            "streaming": false,
            "allocated_microcents": 1200000,
            "agent": { "id": "agt_2k...", "name": "Support agent" },
            "mission": { "id": "mis_3x...", "declared_intent": "Review supplier invoices" },
            "skill": { "id": "skl_7p...", "name": "Invoice review" },
            "invocation": { "id": "inv_4m...", "status": "completed" },
            "sealed_step_index": 0
          },
          {
            "id": "usg_1b...",
            "created_at": "2026-07-15T10:13:59Z",
            "operation": "Sealed skill execution",
            "declared_purpose": "Review supplier invoices",
            "provider": "openrouter",
            "model": "provider/model",
            "prompt_tokens": 700,
            "completion_tokens": 200,
            "total_tokens": 900,
            "cached_prompt_tokens": null,
            "streaming": false,
            "allocated_microcents": 1400000,
            "agent": { "id": "agt_2k...", "name": "Support agent" },
            "mission": { "id": "mis_3x...", "declared_intent": "Review supplier invoices" },
            "skill": { "id": "skl_7p...", "name": "Invoice review" },
            "invocation": { "id": "inv_4m...", "status": "completed" },
            "sealed_step_index": 1
          }
        ],
        "machine_sources": [
          {
            "id": "smu_8q...",
            "created_at": "2026-07-15T10:13:59Z",
            "duration_ms": 12,
            "allocated_microcents": 400000,
            "skill": { "id": "skl_7p...", "name": "Invoice review" },
            "invocation": { "id": "inv_4m...", "status": "completed" },
            "sealed_step_index": 2
          }
        ],
        "machine_cost_microcents": 400000,
        "source_status": "recorded"
      }
    }
  ]
}
```

Use `next_cursor` unchanged on the next request. STACK returns HTTP 400 when a cursor is malformed, missing, owned by another operator, or outside the active filter window. `llm_sources` lists every model call that contributed to the debit. `allocated_microcents` gives the exact share from that call. Sealed machine cost stays separate in`machine_cost_microcents`.`machine_sources` keeps the exact sealed invocation and script step, including a failed invocation whose remainder crosses a later wallet cent. STACK does not store prompt or response text. Older model and sealed compute charges can return`source_status: "not_recorded"`. STACK does not infer a source for those rows.`declared_purpose` comes from the exact mission or passport. It never contains prompt or response text.

### Unified Wallet timeline

Set `view=timeline` to return wallet movements and model calls in one stable list. The default response above does not change. The first timeline page fixes one snapshot, and each opaque cursor keeps that snapshot for the next page. Transaction `type` and `direction`filters return wallet rows only because standalone calls are not balance movements.

```json
{
  "snapshot_at": "2026-08-16T10:00:00Z",
  "next_cursor": "eyJ2IjoxLCJzIjoiLi4uIn0",
  "has_more": true,
  "rows": [
    {
      "kind": "wallet_transaction",
      "transaction": { "id": "wtxn_9fA2...", "type": "compute", "amount_cents": -3 }
    },
    {
      "kind": "llm_call",
      "call": {
        "id": "usg_1c...",
        "operation": "Gateway model call",
        "provider": "openrouter",
        "model": "provider/model",
        "total_tokens": 900,
        "price": { "state": "wallet_price", "amount_microcents": 375000 }
      }
    }
  ]
}
```

Calls with an exact allocation stay under their wallet transaction. A standalone call had no captured debit at the page snapshot. STACK does not link old calls by time, model, token count, or price. A standalone price is `wallet_price`, `included`, `covered`, or `unavailable`. Use microcents for display so a real sub-cent amount does not appear as zero.

## POST /v1/billing/topup

Opens a Stripe Checkout session and returns the redirect URL. On successful payment, the webhook credits the wallet; poll `/v1/billing/balance` until the new balance appears (typically within a few seconds). Checkout shows two lines: the top-up and a `Card fee` of 5.5% of it, at least $0.50, rounded up to the cent. The card is charged both; the wallet is credited the top-up amount alone. Starting a top-up needs no approval: you pay on Stripe's own page.

### Request

```json
{ "amount_cents": 5000 }
```

- Minimum: 500 ($5)
- No maximum of its own: Stripe takes at most $999,999.99 in one payment, the top-up and its card fee together

### Response

```json
{
  "checkout_url": "https://checkout.stripe.com/c/pay/cs_…",
  "session_id": "cs_test_a1…"
}
```

## POST /v1/billing/subscribe

Retired. The Developer, Pro and Business plans are no longer sold, and this route answers `410 TIER_SUBSCRIPTIONS_RETIRED`. Start the platform subscription with `POST /v1/billing/platform/subscribe`.

## POST /v1/billing/cancel-subscription

Cancel a tier subscription that already exists. It stays active until the end of the billing period.

## POST /v1/billing/refund/:transactionId

Refund the unspent part of a top-up transaction back to the original payment method. STACK sets no time limit; Stripe's own refusal of a charge it will no longer refund is passed back as `REFUND_REFUSED_BY_STRIPE`. The unspent part is what is left of the top-up's credit, as far as your own money in the wallet reaches (credit STACK granted is never refunded). The card fee the payment carried is not refunded. A refund that was started and not finished is resumed by calling again. The response carries `refunded_cents` (the unspent part, taken from the wallet and returned to the card).

## POST /v1/billing/seats

Retired. Every account may have any number of team members, so seats are no longer sold, and this route answers `410 SEATS_RETIRED`. Seats bought on an old plan were removed from it, and the unused part of the period credited.

## POST /v1/billing/portal

Open the Stripe customer portal for invoices and payment methods. Opening it needs no approval.

```json
{ "url": "https://billing.stripe.com/p/session/..." }
```

## GET /v1/billing/usage

Returns the plan the account is on (`plan`: platform, internal, contract or none), the billing-period dates and usage counts for passports, agents, drop-offs, skill invocations, and published skills.

## Plans

Platform subscription, $19 a month, the first 14 days free:

- 2,000 metered actions included each month
- agents, connections, published skills, webhooks and team members: unlimited
- the audit record, security events and signed records kept 365 days
- text and webhook owner alerts, texts charged at cost
- SPIFFE and WIMSE workload passports
- single sign-on, single sign-on domains and the identity provider configuration
- company sign-in for approvals
- customer-managed encryption keys (AWS bills your own account)

Controls, $4 a month on top, the first 14 days free:

- reading the audit record and signed records, including everything from before controls were on (the list of flagged events is open to every account)
- evidence packs, Mission dossiers and signed record export
- intent deviation, graded on every checkout
- behavioural baseline and drift
- detector settings

## Pricing beyond the included actions (wallet-billed)

Customer-key LLM gateway calls create one bill: your LLM provider bills the model cost directly, and STACK takes no fee on it. The provider-cost figure in STACK covers only calls routed through STACK, not every call made with that provider key.

- metered action - past the included 2,000 each month, $20 per 10,000, less at volume
- L3 LLM injection classification - model cost beyond the included amount
- notification text - each segment at the destination's price, none included
- notification email - send cost beyond the included amount

Paid-skill invocations are always wallet-billed at the publisher's list price, on every plan. Sealed-execution compute and identity verifications are wallet-billed at the upstream cost.

## Errors

- INSUFFICIENT_CREDITS (402) - wallet empty on a debit path; caller should prompt a top-up
- TIER_LIMIT_EXCEEDED (403) - a count limit a negotiated deal sets was reached
- REFUND_BALANCE_CONSUMED (409) - nothing of the top-up is unspent, so there is nothing to refund
- REFUND_REFUSED_BY_STRIPE (409) - Stripe refused the refund (for example a charge too old to refund); its own message and code come back
- 409, message only - a private offer link was used on an account that already has a subscription
- SEATS_RETIRED (410) - seats are no longer sold; team members are unlimited
- TENANT_BILLED_BY_PARTNER (403) - a partner-managed account cannot change plan or wallet; its partner is billed
- BILLING_NOT_CONFIGURED (503) - billing is not configured on this deployment
