Using Lamdy
Send usage per customer
Split cost by customer and feature when everyone shares one provider key: OpenRouter, OpenTelemetry or the usage events API.
Provider bills say which API key or project spent the money, not which of your customers it was for. When every customer shares one key, your app has to say who each AI call was for. Lamdy then splits that cost by customer, feature and team, priced at the rates on your own provider bill, and shows it on Customers and Features.
If each customer already has their own key or project, you don't need any of this: Attribution rules do it from billing alone.
1. Create an ingest key
In the dashboard, open API keys under Connect and create a key for each app or environment. Owners and admins can create keys. A key is shown once; Lamdy stores only its fingerprint.
Ingest keys can only add usage. They can't read spend, revenue or anything else in your workspace, and you can revoke one at any time, which stops it at once. Keep them on your server, never in a browser or mobile app.
2. Choose how to send usage
| Your setup | Use | Code changes |
|---|---|---|
| You call models through OpenRouter | OpenRouter Broadcast | None, beyond passing your customer's id as user |
| Vercel AI SDK, or any app with OpenTelemetry | OpenTelemetry traces | Register an exporter once |
| Anything else | Usage events API | One request per AI call |
OpenRouter Broadcast
In OpenRouter, open Settings, then Observability. Turn on Broadcast and add an OpenTelemetry Collector with the endpoint https://lamdy.ai/api/otel/v1/traces and the header {"Authorization": "Bearer YOUR_INGEST_KEY"}. Then send your customer's id as user on each request, and optionally the feature in trace:
{
"model": "openai/gpt-4o-mini",
"messages": [...],
"user": "cus_123",
"trace": { "feature": "support-chat" }
}Lamdy uses the cost OpenRouter reports for each call.
OpenTelemetry and the Vercel AI SDK
Point a trace exporter at https://lamdy.ai/api/otel/v1/traces using OTLP over HTTP, as protobuf or JSON, and send the ingest key as a bearer token. With the standard variables, which every OpenTelemetry SDK reads:
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://lamdy.ai/api/otel/v1/traces
OTEL_EXPORTER_OTLP_TRACES_HEADERS=Authorization=Bearer%20YOUR_INGEST_KEYLamdy counts each span that describes one model call and reads these attributes:
| Lamdy field | Attributes read, first match wins |
|---|---|
| Customer | lamdy.customer_id, trace.metadata.customer_id, user.id, enduser.id |
| Feature | lamdy.feature, trace.metadata.feature, the AI SDK's functionId |
| Team | lamdy.team, trace.metadata.team |
| Model and provider | gen_ai.response.model, gen_ai.request.model, gen_ai.provider.name |
| Tokens | gen_ai.usage.input_tokens, output_tokens, cache_read.input_tokens, cache_creation.input_tokens |
A model call without a customer, feature or team of its own takes them from the span that wraps it, so you can tag a whole request once, as long as the wrapping span is exported in the same batch, which the default batch exporter does. Agent and wrapper spans that add up their children's usage are not counted twice. The API keys page has a ready-made setup for Next.js.
Usage events API
After each AI call, send the model, the tokens and at least one of customer_id, feature or team to https://lamdy.ai/api/v1/events:
curl -X POST https://lamdy.ai/api/v1/events \
-H "Authorization: Bearer $LAMDY_INGEST_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-4o-mini", "customer_id": "cus_123", "feature": "support-chat",
"input_tokens": 1200, "output_tokens": 340, "request_id": "req_abc"}'Up to 1,000 events fit in one request as { "events": [...] }. Optional fields are provider, cache_read_tokens, cache_write_tokens, cost_usd and timestamp (up to 35 days back). Unknown fields are refused with a message naming them, so a typo never drops attribution silently.
Retries, limits and privacy
- A retried request is counted once: spans dedupe on their trace and span id, and events on
request_id, so send one with every event. - Each key can make 600 event requests or 3,000 trace exports a minute. Requests can be up to 1 MB for events and 4 MB for traces, gzip allowed.
- Lamdy keeps the model, token counts, cost and your customer, feature and team names. It never stores prompts or responses, even when a trace contains them.