LancelotDocs
Quickstart

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:

  1. In Stripe, open Developers → API keys → Create restricted key.
  2. Set Read on Customers, Subscriptions, Invoices and Products. Leave everything else at None.
  3. 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/node

4. 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 });

Anthropic works the same way with wrapAnthropic / wrap_anthropic.

Use the ID Stripe knows. customerId must match metadata.customer_id or metadata.user_id on 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()

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