DocsPlatform
Billing and credits
How prepaid credits, the free monthly allowance, usage rates and auto-reload work, and what the hosted instance does today.
On this page
The hosted instance is in preview mode: billing is switched off. Nothing is charged and nothing is blocked. Usage is still counted against the free allowance so you can see it. The Stripe path (Checkout, the Billing Portal, webhooks, auto-reload) has been tested against a mocked Stripe only; it has not been run against a real Stripe account. The rates below are the values the software is configured with. They apply only once an operator switches billing on, and no price is being charged today. See pricing.
The model
- Prepaid credits. Each organization has a credit balance. You top it up in advance; usage draws it down.
- A free monthly allowance. Every organization gets a number of source tokens per calendar month (UTC) before any credit is used. The configured value is 100,000 tokens.
- Two rates, per 1,000 source tokens. Batch work (entries, files, glossary re-translation, GitHub runs) is configured at 2 cents. Runtime
POST /translateis configured at 4 cents. - Source tokens are the same metric as on the usage page: the characters of the source text, divided by four and rounded up, for strings that were translated successfully. Cached strings cost nothing.
Usage first consumes the allowance, then credits. Credits are tracked with sub-cent precision, so a balance can show hundredths of a cent.
The deduction is written in the same database batch as the translation itself, so a translation and its charge are recorded together or not at all.
Preview mode and billing mode
| Preview (hosted instance today) | Billing on | |
|---|---|---|
GET …/billing |
configured: false, plan: "preview" |
configured: true, plan: "usage" |
| Allowance usage | Counted | Counted |
| Credits | Not deducted | Deducted after the allowance |
| Out of allowance and credits | Nothing happens | 402 credits_insufficient on work that needs the model |
| Checkout and portal | 501 billing_not_configured |
Work |
When billing is on and an organization has neither allowance nor credits left, these fail with 402 credits_insufficient: uncached runtime translation, batch entries, file uploads, retranslating a string, and GitHub runs (a run that hits the gate ends failed). A runtime call whose strings are all cached is still served, because it does not call the model.
Buying credits
An admin or owner opens Checkout from the dashboard (or POST /v1/orgs/:orgId/billing/checkout). The minimum is $5.00. Stripe Checkout takes the payment and sends the browser back to the returnUrl you gave, with ?checkout=success or ?checkout=cancelled appended. Credits are added by Stripe’s webhook, not by the redirect, so they can appear a moment after you return.
Checkout saves the card for later off-session use, which is what auto-reload needs. The Billing Portal (POST …/billing/portal) lets you update the saved card.
Auto-reload
With auto-reload on, the every-minute scheduler charges the saved card for amountCents when the balance falls below thresholdCents. It tries at most once per 10 minutes per organization. The credits arrive when Stripe confirms the payment. If a charge fails, the reason is shown as lastError until the next success or the next settings change.
You can store auto-reload settings in preview mode too; they take effect once billing is on. The amount must be at least $5.00.
The ledger
The billing response lists the 50 most recent transactions. Top-ups are positive. Usage is negative and aggregated into one row per organization, per UTC day, per kind (“Batch usage 2026-11-30”, “Runtime usage 2026-11-30”).
Webhook handling
For self-hosters: Stripe events are verified with the Stripe-Signature header (5-minute tolerance) and each event id is processed once. Credits are also unique per Checkout Session or payment intent, so a replay cannot credit twice. Handled events: checkout.session.completed, checkout.session.async_payment_succeeded, payment_intent.succeeded (auto-reload only) and payment_intent.payment_failed.
Turning billing on (self-hosting)
Billing turns on when both STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET are set as Worker secrets. Rates and the allowance are the vars BILLING_FREE_TOKENS, BILLING_BATCH_RATE_CENTS and BILLING_RUNTIME_RATE_CENTS. No Stripe products are needed; Checkout uses inline prices. Create a webhook endpoint at /webhooks/stripe on your API with the four events above, and activate the Stripe customer portal once. See self-hosting and the billing API.
Something wrong or unclear on this page? Open an issue.