DocsREST API

Billing API

Read an organization's credits and allowance, start Checkout, open the Billing Portal, set auto-reload, and the Stripe webhook.

On this page

The hosted instance runs in preview mode: GET …/billing works and reports configured: false, while checkout, portal and the Stripe webhook answer 501 billing_not_configured. The Stripe code has been tested against a mocked Stripe only. Background and behavior: billing and credits.

All routes except the webhook need a session token (see authentication) and an organization role. Money is in US cents.

Get billing status

GET /v1/orgs/:orgId/billing (viewer)

{
  "configured": false,
  "plan": "preview",
  "creditsCents": 0,
  "freeAllowance": { "tokens": 100000, "usedTokens": 1840, "resetsAt": "2026-12-01T00:00:00.000Z" },
  "rates": { "batchPer1kTokensCents": 2, "runtimePer1kTokensCents": 4 },
  "autoReload": { "enabled": false, "thresholdCents": 0, "amountCents": 0, "lastError": null },
  "hasPaymentMethod": false,
  "transactions": [
    { "id": "…", "type": "usage", "amountCents": -0.37, "description": "Batch usage 2026-11-30", "createdAt": "2026-11-30T10:02:11.000Z" }
  ]
}

plan is "preview" or "usage". creditsCents and amountCents are rounded to two decimals. transaction.type is topup, usage or adjustment. transactions holds the 50 most recent. rates and freeAllowance.tokens are the values the deployment is configured with. In preview mode usedTokens is tracked but nothing is deducted.

Start Checkout

POST /v1/orgs/:orgId/billing/checkout (admin)

{ "amountCents": 2500, "returnUrl": "https://app.example.com/billing" }

amountCents is an integer from 500 to 1,000,000. returnUrl is an absolute http(s) URL; Stripe redirects there with ?checkout=success or ?checkout=cancelled. Returns { "url": "https://checkout.stripe.com/…" }. Redirect the browser to it. Credits are added by the webhook.

Open the Billing Portal

POST /v1/orgs/:orgId/billing/portal (admin)

Body { "returnUrl": "…" }. Returns { "url": "…" }. Creates the Stripe customer if the organization has none yet.

Set auto-reload

PUT /v1/orgs/:orgId/billing/auto-reload (admin)

{ "enabled": true, "thresholdCents": 500, "amountCents": 2000 }

thresholdCents is 0 to 1,000,000; amountCents is 500 to 1,000,000. Returns the three fields back. Accepted in preview mode too; the settings are stored and used once billing is on.

Stripe webhook

POST /webhooks/stripe: called by Stripe, not by you. Verifies Stripe-Signature and processes each event id once. Responds { "received": true, "result": "…" }, or { "received": true, "duplicate": true } for an event it has already seen.

Errors

Status code When
400 invalid_request A body failed validation (for example amountCents under 500).
400 invalid_signature The Stripe signature on /webhooks/stripe is wrong or stale.
402 credits_insufficient Billing is on and the organization has no allowance or credits left. Returned by translate, entries, files, retranslate; see billing.
403 permission_missing Your role is too low.
501 billing_not_configured Checkout, portal or the webhook on a deployment without Stripe secrets.

Something wrong or unclear on this page? Open an issue.

Type to search the documentation.