Get started
Quickstart
Connect revenue, install the SDK and see your first customer's margin in about ten minutes.
You need a Lancelot workspace. Every plan starts with a 7-day free trial.
1. Connect Stripe
Create a restricted key in Stripe with read access only:
- In Stripe, open Developers → API keys → Create restricted key.
- Set Read on Customers, Subscriptions, Invoices and Products. Leave everything else at None.
- In Lancelot, open Settings → Integrations and paste the key (it starts with
rk_live_).
Lancelot checks the key can read what it needs, then imports the last 12 months of invoices. Using RevenueCat instead? See RevenueCat.
2. Create an API key
In Lancelot, open Settings → Integrations → API keys and click Create API key. Copy it now: Lancelot only stores a hash. Set it in your server environment:
LANCELOT_API_KEY=lc_live_...Keep it on the server. It's a secret, like your OpenAI key.
3. Install the SDK
npm i @lancelotwatch/nodepip install lancelotwatch4. Wrap your client
Bind the client to the customer you're serving, per request. feature is optional, and lets you see cost by feature.
import OpenAI from "openai";
import { lancelot } from "@lancelotwatch/node";
const lc = lancelot(); // reads LANCELOT_API_KEY
const openai = lc.wrapOpenAI(new OpenAI(), { customerId: user.id, feature: "chat" });
const res = await openai.chat.completions.create({ model: "gpt-5-mini", messages });from openai import OpenAI
from lancelotwatch import lancelot
lc = lancelot() # reads LANCELOT_API_KEY
openai = lc.wrap_openai(OpenAI(), customer_id=user.id, feature="chat")
res = openai.chat.completions.create(model="gpt-5-mini", messages=messages)Anthropic works the same way with wrapAnthropic / wrap_anthropic.
Use the ID Stripe knows.
customerIdmust matchmetadata.customer_idormetadata.user_idon the Stripe customer, the Stripe customer ID, or the customer's email. See Customer IDs.
5. Flush in serverless
The SDK batches events and sends them every two seconds. In a serverless function, flush before the function ends:
import { after } from "next/server";
after(() => lc.flush()); // Next.js on Vercel; elsewhere: await lc.flush()lc.flush() # or: await lc.aflush()6. Check it worked
Make one AI call from your app. Within a minute, the setup screen in Lancelot shows Live, and the customer appears under Customers with their cost. Margins fill in once Stripe's import finishes.
Next
- Let Lancelot act: turn on
enableFlagsso approved fixes apply inside your app. - Emergency stop and budgets: stop a runaway customer within a minute.
- Notifications: approve fixes from Slack.