API essentials

Authentication

Authenticate with a bearer API key per organization, scoped to test mode or live mode, and learn what the mode check refuses and why that protects your data.

Send your API key as a bearer token on every request:

curl $TMBILLING_URL/v1/me \
  -H "Authorization: Bearer sk_live_…"

A key identifies one organization. Everything it reaches — businesses, customers, invoices — belongs to that organization, and tmbilling enforces the boundary in the database rather than in whichever query happens to run. You cannot read another organization's data by guessing an id.

Select a key mode

Every business has a live mode and a test mode, each with its own business id. You create each key for one of the two modes:

ModePrefixReachesUse it for
testsk_test_Test mode onlyDevelopment, CI, anything that must never charge a card
livesk_live_Live mode onlyProduction

Point a test key at a live business id, or the reverse, and you get 404 No such business. That refusal is what stops a staging deployment with the wrong key from billing your real customers.

Time Travel and configuration transfer cross the two modes, so they run from the dashboard, which signs in with its own credential. An integration key gets 403 on them. See Test and live mode.

Create and revoke keys

Create keys in the dashboard under Settings → Developer → API keys, or through the API:

POST/v1/api_keys

Pass livemode (test or live, default test), an optional name, and an optional scope (write, the default, or read). A read key cannot change anything. tmbilling returns the secret exactly once, when you create the key. GET /v1/api_keys lists your keys with a non-secret fragment so you can identify them, and never returns a secret again. If you lose a key, revoke it and create another.

POST/v1/api_keys/{id}/revoke

Revocation takes effect immediately.

An API key reads every customer and charges every card in your organization. Never put one in a browser, a mobile app or a repository.For buyer-facing flows, create a hosted checkout session or a customer portal session instead. Each gives you a short-lived, single-use credential scoped to one buyer. See Hosted checkout and portal.

Check which organization a key resolves to

GET/v1/me

Use this as a deployment smoke test. If it returns the wrong organization or the wrong mode, stop before anything else runs.

Recognise an authentication failure

StatusErrorCause
401authentication_errorThe key is missing, malformed or revoked.
403permission_errorThe key is valid but may not do this, for example a read key on a write.
403permission_error, code live_access_requiredHosted only: our team turned live mode off for the organization. Test mode and reads still work. Contact us to turn live mode on.
403permission_error, code account_restrictedHosted only: the organization is read-only. Its plan is unpaid (pay the open invoice), or it stayed above its plan's limit and our team made it read-only (change to a plan that covers its billing).
404invalid_request_errorThe business id belongs to the other mode, or does not exist.

See Errors.

Copyright © 2026