The best boilerplates for an AI SaaS
The one that already solved billing for tokens. An AI product is not a chat box; it is metered usage reported exactly once, a per-user cost cap that fires before the spend, rate limits, and retrieval that does not need a second database. Jetpack ships those tested; most kits leave the metering and the cap to you.
Why is AI billing the hard part?
Because the cost is per request and unbounded, and the failure is silent. A normal SaaS bug shows you an error; a billing bug shows you an invoice at the end of the month. Everything below exists because one of them has cost somebody real money.
What does an AI SaaS actually need?
1.Metered usage reported exactly once
Tokens become usage rows, and a batched reporter pushes them to the payment provider with an idempotency key derived from the batch. A retry after a crash sends the same key and is deduplicated — otherwise a network blip becomes a double charge.
2.A cost cap that fires before the spend
Checked before the model call, not after. A cap that reports the overspend has not capped anything; it has written it down.
3.A rate limit that survives a cold start
Serverless functions share no memory, so an in-process limiter resets on every cold start and limits nothing. The bucket has to live in the database.
4.Typed errors the UI can act on
A refused request should say which ceiling it hit. HTTP 402 for a plan limit or a credit cap and 429 for the rate limit mean different things to a customer, and to your support inbox.
5.Retrieval without a second database
pgvector on the Postgres you already run. A separate vector service is another bill, another outage, and another thing to keep in sync with your rows.
6.Deterministic tests that make no network call
A fake model and a fake embedder that stream stable output, so the whole AI path is testable in CI with no key and no spend.
Which kits ship this?
Jetpack ships all six, tested. Makerkit and Supastarter both have usage-based billing you can build on, but leave the cap, the rate limit and the retrieval wiring to you. ShipFast does not cover AI billing at all — it is a different, cheaper product for a different job.