# Pricing & billing

SubEtha is **prepaid**. You top up a balance, every action is priced above what it costs to run,
and every action is checked against your balance *before* it runs. There's no subscription, no
free tier, and no bill after the fact. Edge transports (BLE, audio, QR, LAN) never touch the relay
and are free.

## The rules

1. **Prepaid only.** Top up with Stripe Checkout (minimum $5). Each top-up carries a fee of 4.5% +
   $0.35, which covers card processing and fixed costs; the rest becomes credit.
2. **Reserve before acting.** Each action reserves its worst-case cost first, then settles to the
   actual cost (an SMS's real segment count, for example) and releases the rest. If the balance
   can't cover the reservation, the request fails with **HTTP 402** and nothing happens.
3. **Every SKU has a positive margin**, at every volume tier. Prices are generated from measured
   costs in [`pricing/costs.yaml`](https://github.com/curtcox/subetha/blob/main/pricing/costs.yaml),
   and CI fails if any margin drops below 15%. The live table is at `GET /v1/prices`.
4. **State costs rent.** Retained messages, attachments, enrolled devices, verified endpoints, and
   open connections are metered by time.
5. **Live prices where providers' prices vary.** SMS and voice outside the US are priced per
   country every day from Twilio's current prices (`GET /v1/prices/destinations`); a destination
   without a current price is rejected. See [Transports](transports.md#numbers-outside-the-us).
6. **Volume tiers** lower prices as trailing-12-month top-ups grow (`standard`, `bulk` from $500,
   `volume` from $5,000), without ever crossing the margin floor.

## Prices

Money in the API is integer **micro-dollars** (µ$): 1,000,000 µ$ = $1. The table below is
generated from the price list at build time, so it always matches what the relay charges.

## SubEtha pricing invariant report

Generated from `pricing/costs.yaml`. Every SKU at every tier must have a margin ≥ 15% — this report only exists if that held.

| SKU | Unit | Cost | Price (standard) | Price (bulk) | Price (volume) | Margin (standard) | Margin (bulk) | Margin (volume) |
|---|---|---:|---:|---:|---:|---:|---:|---:|
| `publish` | message | $0.0000015 | $0.000006 | $0.000006 | $0.000006 | 75.0% | 75.0% | 75.0% |
| `deliver_live` | delivery | $0.0000003 | $0.000002 | $0.000002 | $0.000001 | 85.0% | 85.0% | 70.0% |
| `deliver_push` | delivery | $0.000002 | $0.000006 | $0.000006 | $0.000005 | 66.7% | 66.7% | 60.0% |
| `deliver_webhook` | delivery | $0.0000023 | $0.00001 | $0.00001 | $0.000009 | 77.0% | 77.0% | 74.4% |
| `deliver_slack` | delivery | $0.0000023 | $0.00001 | $0.00001 | $0.000009 | 77.0% | 77.0% | 74.4% |
| `deliver_mcp` | delivery | $0.00000085 | $0.000007 | $0.000007 | $0.000007 | 87.9% | 87.9% | 87.9% |
| `deliver_email` | email | $0.0001212 | $0.000443 | $0.000413 | $0.000382 | 72.6% | 70.7% | 68.3% |
| `inbound_email` | email | $0.00001 | $0.00007 | $0.000068 | $0.000065 | 85.7% | 85.3% | 84.6% |
| `deliver_sms_us` | segment | $0.0115 | $0.0166 | $0.0155 | $0.0143 | 30.7% | 25.6% | 19.6% |
| `deliver_mms_us` | message | $0.0323 | $0.0462 | $0.0430 | $0.0398 | 30.1% | 24.9% | 18.8% |
| `inbound_sms_us` | segment | $0.0110 | $0.0159 | $0.0148 | $0.0137 | 30.8% | 25.7% | 19.7% |
| `inbound_mms_us` | message | $0.0268 | $0.0385 | $0.0358 | $0.0332 | 30.4% | 25.2% | 19.2% |
| `deliver_voice_us` | minute | $0.0169 | $0.0247 | $0.0230 | $0.0213 | 31.5% | 26.4% | 20.6% |
| `deliver_sms_intl` | segment | $0.0505 | $0.0717 | $0.0667 | $0.0616 | 29.6% | 24.2% | 18.0% |
| `deliver_voice_intl` | minute | $0.0534 | $0.0768 | $0.0714 | $0.0661 | 30.4% | 25.2% | 19.2% |
| `deliver_whatsapp` | message | $0.0205 | $0.0297 | $0.0277 | $0.0256 | 31.0% | 25.9% | 19.9% |
| `inbound_whatsapp` | message | $0.005302 | $0.007923 | $0.007393 | $0.006863 | 33.1% | 28.3% | 22.8% |
| `deliver_lxmf` | delivery | $0.0000152 | $0.000051 | $0.000047 | $0.000043 | 70.2% | 67.7% | 64.6% |
| `api_request` | request | $0.000001 | $0.000003 | $0.000003 | $0.000003 | 66.7% | 66.7% | 66.7% |
| `attachment_upload` | upload | $0.0000068 | $0.000017 | $0.000015 | $0.000014 | 60.0% | 54.7% | 51.4% |
| `retention_message_day` | message-day | $0.00000004 | $0.0000001 | $0.00000009 | $0.00000008 | 60.0% | 55.6% | 50.0% |
| `attachment_mb_day` | MB-day | $0.0000006 | $0.0000016 | $0.00000145 | $0.0000013 | 62.5% | 58.6% | 53.8% |
| `device_day` | device-day | $0.0000005 | $0.000002 | $0.000001875 | $0.00000175 | 75.0% | 73.3% | 71.4% |
| `endpoint_day` | endpoint-day | $0.0000021 | $0.0000092 | $0.000008675 | $0.00000815 | 77.2% | 75.8% | 74.2% |
| `connection_hour` | connection-hour | $0.000001 | $0.000003 | $0.00000275 | $0.0000025 | 66.7% | 63.6% | 60.0% |

Edge transports (BLE, audio, QR, LAN) never touch the relay and are free.

### Fixed costs and break-even

| Item | USD / month |
|---|---:|
| cloudflare_workers_paid | $5.00 |
| cloudflare_containers_base | $5.00 |
| domain_subetha_us | $1.25 |
| clerk_pro | $25.00 |
| twilio_number | $1.15 |
| twilio_10dlc_campaign | $10.00 |
| apple_developer | $8.25 |
| google_play | $0.00 |
| github | $0.00 |
| monitoring_status_page | $0.00 |
| **Total** | **$55.65** |

- Top-up fee: 4.5% + $0.35. On an average $20 top-up (domestic card) it contributes $0.370 to fixed costs.
- Break-even on top-up fees alone: **151 top-ups / month**.
- Margin per published message with 2 live deliveries: $0.0000079; break-even on messages alone: **7,044,304 messages / month**.
- Profit = Σ(volume × unit margin) − fixed costs, so it only rises with volume.


## Who pays for what

| Action | Paid by |
|---|---|
| Publish (and dry runs, and uploads) | the publisher's token or account |
| Live delivery, push, webhook, email, Slack, SMS, voice, LXMF | the topic owner |
| Reading: polls, stream connections and connection time, attachment downloads | the topic owner |
| Message retention and attachment storage | the topic owner (retention), the publisher (attachment storage) |
| Anonymous publishes (when the topic allows them) | the topic owner, within the topic's anonymous caps |
| Endpoint verification codes | the account adding the endpoint |
| Inbound email and SMS | the owner of the receiving topic |

## Balance, ledger, and top-ups

```bash title="samples/curl/billing.sh"
#!/usr/bin/env bash
# Balance, ledger, prices, and a Stripe Checkout top-up.
set -euo pipefail
SUBETHA_URL="${SUBETHA_URL:-https://subetha.us}"
AUTH=(-H "Authorization: Bearer $SUBETHA_TOKEN")

curl -sS "${AUTH[@]}" "$SUBETHA_URL/v1/balance"
# {"available_usd_micros":4981234,"reserved_usd_micros":15000}

curl -sS "${AUTH[@]}" "$SUBETHA_URL/v1/ledger?limit=20"
curl -sS "$SUBETHA_URL/v1/prices" | jq '.skus.publish'

# Top up $20: open the returned URL to pay.
curl -sS "${AUTH[@]}" -H "Content-Type: application/json" -d '{"amount_usd": 20}' \
  "$SUBETHA_URL/v1/billing/checkout" | jq -r .url

# A 402 looks like this:
#   {"error":"insufficient_balance","http":402,"message":"…","shortfall_usd_micros":1234}
```

### Auto-recharge

Optional, and not a subscription: top up once with `"save_card": true` in the checkout request (or
tick **Save card for optional auto-recharge** in the console's Billing tab), then turn it on in the
console or with `PATCH /v1/account`:

```json
{ "auto_recharge": { "threshold_usd": 2, "amount_usd": 20 } }
```

When the balance drops below the threshold, the saved card is charged `amount_usd` (same fee as
any top-up). A declined charge turns auto-recharge off. `{"auto_recharge": null}` turns it off.

### Payments and receipts

`GET /v1/payments` (admin) lists the card payments credited to the account: amount paid, top-up
fee, credit added, and any refund or dispute. `GET /v1/payments/{id}/receipt` returns a printable
HTML receipt for one of them, and the console's Billing tab links to each. Stripe also emails its
own receipt to the account's address.

### Ledger

The ledger is append-only: `topup`, `reserve`, `settle`, `release`, `refund`, and `adjust`
entries, journaled and reconciled nightly against Stripe. Refunds and chargebacks are deducted
from the balance (a chargeback also recovers the dispute fee where possible).

### Usage

`GET /v1/usage?days=30` (admin) breaks spend down by category and day, computed from the
ledger: publishing, paid deliveries, live delivery and storage (with the top topics), device and
endpoint rent, and API requests and other charges. In-flight deliveries and credit that topics
still hold are reported as `pending_micros`, so counted plus pending equals what left the
balance. The console's Billing tab charts it. To estimate future spend, use the
[pricing calculator](/tools/pricing.html).

## 402 Payment Required

```json
{ "error": "insufficient_balance", "http": 402, "message": "…", "shortfall_usd_micros": 1234 }
```

- `insufficient_balance`: the payer can't cover the worst-case cost. `shortfall_usd_micros` says
  how much more is needed. `"payer": "topic_owner"` means the *topic owner's* balance is short
  (for delivery), not yours.
- `no_funded_owner`: an anonymous publish to a topic whose owner can't pay.

Clients should treat 402 as permanent until someone tops up; retrying won't help.

## Caps and holds

Several independent limits stop spending before it surprises anyone. Each returns
`403 spend_cap_exceeded` when it would be crossed:

| Limit | Set with |
|---|---|
| Per token, per day and in total | `daily_cap_usd`, `total_cap_usd` on [`POST /v1/tokens`](tokens.md) |
| Per topic, per day and per month (owner-side spend, including reads) | topic policy `daily_cap_micros`, `monthly_cap_micros` |
| Per message | topic policy `max_cost_per_message_micros`; per publish `X-Max-Cost` |
| Anonymous publishing, per topic per day | topic policy `anon_daily_cap_micros` (default $1) |
| Per account, per day and per month | `PATCH /v1/account {"daily_cap_micros": …, "monthly_cap_micros": …}` |
| **New-funds hold** | automatic: until your first top-up is 7 days old, SMS and voice spend is capped at $5 in total |

Plus a kill switch at every level: `paused` on a topic policy, on a device (`PATCH /v1/devices/{id}`), or on the account.

## Running out

With a zero balance, every paid action fails with 402 before it runs. Rent for devices and
endpoints is charged daily; when it can't be paid the account is marked **frozen** (records are
kept). After 30 days frozen, its endpoints and subscriptions are deleted and its devices revoked.
A top-up before then unfreezes it immediately. If the account has an email address,
it gets a notice when it's frozen, a warning 7 days before the deletion date, and a notice when
the deletion happens (each one is also in the audit log as `account.notice`).

## Traces

Every message has a trace, visible only to the topic owner: the route plan, what was dropped and
why, each delivery attempt and its result, acks, and the µ$ charged for each step.

```ts title="samples/ts/trace.ts"
const trace = await se.trace(topic, msg.id!);
console.log(JSON.stringify(trace, null, 2)); // plan, deliveries, acks, µ$ per step
```

## Estimating before you spend

`X-Dry-Run: 1` on any publish returns the plan and a worst-case price without sending anything
([Dry runs](publishing.md#dry-runs)). `subetha cost <topic>` does the same from the CLI, and the
MCP tool `estimate_cost` does it for agents.
