LancelotDocs
How Lancelot works

Get started

How Lancelot works

Revenue from your billing system, cost from your AI calls, joined on one customer ID.

Revenue

Lancelot reads paid invoices and subscriptions from Stripe or RevenueCat with a read-only key. For past months it uses what each customer actually paid. For the current month it uses their plan price, so a mid-month margin isn't distorted by when the invoice landed.

Cost

Every AI call your app makes is reported as a usage event: the customer ID, provider, model, token counts and an optional feature label. Lancelot prices each call with the rates for the model that ran, including cache reads, cache writes and long-context tiers. Calls imported from a gateway (OpenRouter, Helicone) keep the cost the gateway reported.

A model Lancelot has no price for is stored with zero cost and flagged as Model with no price, so it never silently drops out of your margin. Once the price is added, totals are recalculated from the token counts.

Margin

Margin is revenue minus AI cost, for each customer, plan, feature and model, per day and per month. Lancelot learns what a typical customer on each plan costs from your own data, and flags customers well past that.

Findings and fixes

When something looks wrong, Lancelot opens a finding: a customer losing money, a sudden spike, a free tier being farmed, a model with no price. It diagnoses the cause and proposes a fix: throttle, pause, switch to a cheaper model, cap spend, or send an upgrade offer. How far it goes on its own is up to you. See Fixes and autonomy.

Enforcement

Lancelot never sits in the path of your AI calls. Approved fixes reach your app through the SDK: with enableFlags on, it checks each customer's flags, cached locally and refreshed every 60 seconds, before each wrapped call. If Lancelot is unreachable, everything is allowed.

The SDK also runs a local emergency stop that needs no network call at all.