Guide
OpenRouter cost tracking by customer, feature and team
Published
OpenRouter tells you what your account spent. It doesn't tell you which customer, product feature or team the spend served. This guide shows how to tag each OpenRouter call at that level, check the figures against OpenRouter's own account report, and get warned before the spend surprises you.
What does OpenRouter's own spend data show, and what's missing?
OpenRouter reports your account's spend in US dollars, so you can see the total. What it can't show is your own business: which of your customers a call served, which feature made it, or which team owns it. Provider invoices and usage exports have no customer field, so no report can add that split later.
A provider knows that a key spent $4.02 today, not whether that was one customer running a heavy report or a thousand customers sending one message each. The only moment you know the customer and the feature is when your code makes the call, so that is where tracking has to start.
How do you track OpenRouter costs per customer, feature and team?
Wrap the OpenAI client you point at OpenRouter with Token Meter's OpenAI-compatible wrapper, passing openrouter as the provider, and tag each call with an action() scope. The call is then recorded, and priced, under OpenRouter, the provider you actually pay, with the customer, feature and team attached.
- In the Token Meter dashboard, open Governance › API keys and choose Create key. This ingest key starts with
tl_live_and is shown once. Owners, Admins and Team leads can create one. - Get an API key from your OpenRouter dashboard. Save it as
OPENROUTER_API_KEY, next toTOKEN_METER_KEY. - Install the packages:
pip install "tokenmeter-sdk[openai]"ornpm install @tokenmeter/sdk openai. - Point the OpenAI client at
https://openrouter.ai/api/v1, wrap it, and open anaction()scope around the calls it covers:
import OpenAI from "openai";
import { TokenMeterClient, wrapOpenAICompatible, action } from "@tokenmeter/sdk";
const tl = new TokenMeterClient({ apiKey: process.env.TOKEN_METER_KEY ?? "" });
const openrouter = wrapOpenAICompatible(
new OpenAI({ apiKey: process.env.OPENROUTER_API_KEY, baseURL: "https://openrouter.ai/api/v1" }),
tl,
"openrouter",
);
const reply = await action("generate-report", { customerRef: "acme", feature: "reports", team: "growth" }, () =>
openrouter.chat.completions.create({
model: "openai/gpt-4o-mini",
messages: [{ role: "user", content: "Say hello in five words." }],
}),
);
console.log(reply.choices[0].message.content);
await tl.flush(); // a short script sends its usage before it exitsOpen Requests in the dashboard sidebar. Within a few seconds the top row shows your call, with its model, tokens and cost, and the tags in the Customer and Team columns. Customer cost feeds the Customers page.
- No proxy. The SDK reads usage from the reply after OpenRouter has answered. It adds no network hop, can't slow down or block a call, and never throws into your code. The call runs on your own OpenRouter key, so OpenRouter bills it to you as usual.
- The provider value is checked. In Python, a value other than the allowed ones (
openrouter,xai,mistral,fireworks,together,deepinfra,vercel_gateway) raises an error that lists them. In TypeScript the type checks it, not the run time. - Fixed tags per client (TypeScript). Tags that never change for a client, such as its team, can go in the fourth argument of
wrapOpenAICompatible, after the provider. They override the same tag set by anyaction(). In Python,wrap_openai_compatible(client, provider)takes no tags; useaction(). - Customer ids, not emails. Email addresses in
customer_refare replaced with[REDACTED:email], so those customers merge into one row. Use ids such ascus_123. - Untagged calls still count. They show as Unattributed in the Customer column; they just can't be split by customer.
A long-running app sends usage every 2 seconds or every 500 calls, whichever comes first. Serverless functions need the flush pattern in Frameworks. Details: Providers and Attribution. To turn per-customer cost into margin, see LLM cost per customer.
How do you check the figures against OpenRouter's account report?
Connect your OpenRouter account with a Management key. Token Meter then imports OpenRouter's account report, which gives spend in US dollars, and shows it next to the cost it metered from your calls. On Analytics › Bill, the report's spend is what counts toward your total AI spend.
- Create a Management key at
openrouter.ai/settings/management-keys. A normal API key is refused. - In Token Meter, open Settings › Connections and choose Connect an account. You need to be an Owner or Admin.
- Pick OpenRouter as the Provider. Fill in OpenRouter account / organization ID with your OpenRouter organization ID (or any stable name for a personal account), and paste the key into Management key.
- Choose Connect and sync. Token Meter fetches a small report first, so a wrong key is refused straight away. It then stores the key encrypted and starts the first import. The card shows Syncing…, then Synced.
The key only reads billing and usage data; Token Meter never uses it to make AI calls. The first sync imports the last 7 days, and the rest follows in the background. OpenRouter only serves 30 completed days, so that is as far back as the history goes, and Backfill history re-imports up to 30 days. The connection syncs about once an hour and re-reads the last 3 days each time, so OpenRouter's corrections replace older figures. Days are UTC, today is never requested, and the newest days can lag.
On Analytics › Bill, each provider counts once: its invoice, else its account report, else its metered estimate. OpenRouter falls on the account report line:
| Line | Used for OpenRouter when | What it adds |
|---|---|---|
| Provider account reports | OpenRouter is connected and has no invoice lines in the range. | The report's spend, plus metered spend on days the report doesn't reach yet (shown as "of which tracked, on days the reports do not cover yet"). Only report periods that lie fully inside the range are added. |
| Tracked, no invoice or report | OpenRouter has no invoice lines and no US dollar account report in the range. | The metered estimate from your wrapped calls, priced at your model rates. |
A report is not an invoice
Token Meter reconciles metered spend against invoices, and account reports are not suitable for that. With only an account report, OpenRouter's Reconciliation status reads Not comparable, not Matched or Drift detected. To compare, read the Tracked spend and Account report columns side by side in the By provider table. They are never added together.
The report rows themselves, with period, tokens, requests, spending and currency, are under Data health › Provider usage, in the Imported reports view. See AI Bill and billing imports, and tracking AI spend across providers if OpenRouter is one of several bills.
How are OpenRouter tokens and models recorded?
Every call through the wrapped client is recorded under the provider openrouter, including a model such as openai/gpt-4o-mini in the example above. Usage is read with the same rules as OpenAI. Cache and reasoning tokens are recorded when OpenRouter reports them; a count it didn't report stays empty rather than guessed.
| What | OpenAI-compatible providers, OpenRouter included |
|---|---|
| APIs recorded | Chat Completions and the Responses API. |
| Streaming | Yes, both. |
| Cache tokens | When the provider reports them. |
| Reasoning tokens | When the provider reports them. |
The OpenAI rule treats cached tokens as part of the prompt total and reasoning tokens as part of the completion total, so both are subtracted before pricing and no token is counted twice. Each call ends up as five separate counts: input, output, cache read, cache write and reasoning tokens.
- Streams. A streamed Chat Completions call only reports tokens if the request asks for them, so the wrapper adds
stream_options.include_usagefor you. In Python, if you pass your ownstream_options, include"include_usage": Trueyourself. A stream that stops before its final chunk is recorded as incomplete, with no token counts. - Vercel AI SDK. With Token Meter's middleware, calls through OpenRouter's AI SDK provider are recorded under OpenRouter. AI SDK 3 and 4 give the middleware only a prompt and a completion total, so cache and reasoning counts stay empty there; version 5 and later report them when the provider does.
- Unpriced calls. The By provider table on Analytics › Bill shows OpenRouter's metered requests and how many had no price.
How do you cap OpenRouter spend?
Set a budget and alert rules, and route the alerts to email, Slack or Discord. For OpenRouter calls made with the SDK, these warn you; they can't stop a call. A budget can only stop traffic sent through Token Meter's router. Direct provider calls, SDK-reported usage and imported bills still count toward the budget and its alerts.
- Budgets. A monthly spend limit on the whole workspace, or on one customer, feature, action, team, environment, provider or model. Owners and admins create them under Governance › Budgets. Thresholds default to 50, 80 and 100%, each firing once a month, and a projection alert warns when the month's linear burn will go over.
- When they are checked. Every 60 seconds, against spend so far this calendar month (UTC), from every connected usage source.
- Threshold rule. Fires when spend for a scope, optionally limited to one provider and model, reaches an amount within the UTC day or month.
- Provider spike rule. Fires when today's spend so far, for one provider or all, reaches a set multiple of yesterday's total, scaled to the part of the day that has passed.
On the Free plan you can set one advisory, workspace-wide budget. Scoped budgets, alert rules and notification channels need a paid plan. See Governance and alerts.
What doesn't this cover?
- The Token Meter router. It doesn't send calls to OpenRouter, and the provider keys a workspace can add there are for OpenAI, Anthropic and Google AI Studio only, so this guide uses the SDK wrapper only.
- OpenRouter calls that aren't made with a wrapped client appear only in the imported account report, with no customer or feature. A framework that creates its own client hides its calls from the SDK unless it lets you pass in a wrapped one.
- Invoice reconciliation: an account report is shown as Not comparable, not Matched or Drift detected.
- History older than the 30 completed days OpenRouter serves, and today, which is never imported.
Start tracking OpenRouter costs
Create a workspace, add an ingest key, wrap your OpenRouter client and tag one call with a customer and feature. Then connect an OpenRouter Management key to see the account report next to your metered cost.