Per-customer AI cost in a few lines of code, for OpenAI and Anthropic in Node or Python.

Wrap the official OpenAI or Anthropic client.
@lancelotwatch/node on npm
lancelotwatch on PyPI · sync and async clients
Wraps the official clients. In Python, AsyncOpenAI and AsyncAnthropic too.
Same methods, same responses.
If you pass user (OpenAI) or metadata.user_id (Anthropic), you can skip the customer ID.
Use the ID you store in Stripe (metadata.customer_id or metadata.user_id), or the customer’s email. RevenueCat app user IDs work the same way.
Token counts only, never prompts.
Costs are worked out on our side from token counts, with each model’s real rates. Cache reads, cache writes and long-context pricing are each priced separately.
Events are queued and sent in the background, every 2 seconds or every 100 events.
Delivery problems go to an error callback, or a quiet log line at most once a minute.
Call flush() before returning. On Vercel, after(() => lc.flush()).
stream: true and the .stream() helpers both work. For OpenAI chat streams, the SDK asks for usage in the final chunk for you.
Fork-safe for gunicorn and Celery workers. A disabled switch turns off all network calls for tests.
Pass an idempotency key, and duplicate events are dropped.
Turn on enableFlags. Without it, Lancelot can only suggest fixes.
A set number of calls a minute. Beyond that, calls throw LancelotBlockedError with reason throttled.
That customer’s calls throw LancelotBlockedError with reason paused.
If you approved a swap, like Sonnet to Haiku, that customer’s requests for the expensive model use the cheaper one.
A daily budget at what their plan normally costs.
If Lancelot is unreachable, every call is allowed.
Changes come from Lancelot’s agent or from you in the dashboard, and apply before each wrapped call.
An outage on our side never blocks your product.

calls a minute trips the stop, by default.
spent in 5 minutes trips it too.
cooldown before calls go through again.
Counts are kept per process, so across many servers they’re approximate. Lancelot’s own detectors catch what one server can’t see.
Under a microsecond per call. No network request.
Too many calls or spending too fast: stopped for a cooldown, with reason runaway.
Hourly or daily, per customer or for every free-plan customer. Then reason budget until the period resets.
Lancelot hears at once. You’re notified within a minute and can make the limit lasting.
Set limits in the dashboard. Override them, or turn the stop off, in code.
Live and test, kept apart for each product.
lc_live_ keys send to live data. lc_test_ keys send to the product’s test data, which never sets off alerts.
Keys belong to a product, so each product’s usage stays separate.
Members and above create keys. Owners and admins revoke them.
Revoked keys stop working within a minute. Every key created or revoked is in the audit log.
For other languages, other providers, or usage from a queue or warehouse.
600 requests
60,000
1,200 polls
120 calls
429, with when to retry.
Up to 500 events per request.
No. Events are queued and sent in the background, every 2 seconds or every 100 events. Local limits take under a microsecond and make no network request.
Every call is allowed. The SDK fails open, so an outage on our side never blocks your product.
No. The SDK sends customer ID, provider, model, token counts, an optional feature tag and the time. Never prompts or completions.
SDKs for Node 18+ and Python 3.9+, wrapping the official OpenAI and Anthropic clients. Anything else, like Gemini or Mistral, goes through the API.
Call flush() before returning. On Vercel, after(() => lc.flush()).
Only with enableFlags on, and only at the level you set for each action. Blocked calls throw LancelotBlockedError with a reason, so you decide what your users see.
Pass an idempotency key with each event. Duplicates are dropped, so retries don’t double count.
Yes. POST to /api/v1/events, up to 500 events per request, from any language, queue or warehouse.
Use an lc_test_ key. Its usage goes to the product’s test data, which never sets off alerts. In Python, a disabled switch turns off all network calls for tests.