> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tensorcost.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Cost per customer

> Tag AI calls with a customer and a feature, read what each customer costs you, and set it against what they paid.

If you sell an AI product, **Spend › Customers** shows AI spend per end customer, with a per-feature breakdown under each one. On Scale and Enterprise it also shows what each customer paid you and the margin that leaves. The tab is for finance and admin roles.

## Tag your calls

Send a customer id, and optionally a feature name, with each call.

> [tab] Proxy
>
> Send headers on calls through the TensorCost proxy.
>
> ```http theme={null}
> x-tc-customer: acme
> x-tc-feature: ticket-triage
> ```

> [tab] Node.js
>
> Set a default on the wrapper, or tag one call with `withMeta()`. `withMeta()` works on OpenAI and Anthropic clients; Bedrock and Vertex take the defaults set on `wrap()`.
>
> ```ts theme={null}
> const client = wrap(new OpenAI(), { customer: "acme" });
>
> await client
>   .withMeta({ customer: "acme", feature: "ticket-triage" })
>   .chat.completions.create({ model: "gpt-4o-mini", messages });
> ```

> [tab] Python
>
> ```python theme={null}
> client = wrap(OpenAI(), customer="acme")
>
> client.with_meta(customer="acme", feature="ticket-triage").chat.completions.create(
>     model="gpt-4o-mini",
>     messages=[{"role": "user", "content": "Summarize this ticket"}],
> )
> ```

You can also set defaults with the `TENSORCOST_CUSTOMER` and `TENSORCOST_FEATURE` environment variables. More on tags, teams and agents is in [Attribution](https://docs.tensorcost.com/developers/attribution.md).

> [!WARNING]
>
> Customer ids are taken exactly as sent, so `Acme` and `acme` are two customers. Pick one casing and keep to it.

## What the page shows

* A row per customer for this month or last month, with that customer's spend and a per-feature breakdown.
* An **Untagged** row, always shown, with a line above the table saying what share of spend carries a customer tag.
* The top 500 customers. When there are more, the page says so, and the totals still count every customer.
* A month picker, in UTC calendar months. It sets the spend and the revenue together, so both cover the same days.
* On Scale and Enterprise, **Revenue**, **Margin** and **Margin %** columns. See [Revenue and margins](#revenue-and-margins).

## How the figure is counted

Each customer's figure is their calls counted once. When a provider billed a day for less than the calls were metered, and the calls name their billing account, the customer counts at the bill, so discounts and credits are included. That starts two days after the day ends and doesn't apply when an environment is selected. Otherwise the figure is the metered price. Sandbox calls count at metered cost. [How TensorCost counts AI spend](https://docs.tensorcost.com/concepts.md) has the full rule.

What providers billed beyond your calls lands in Untagged. Cloud bills and GPUs aren't split by customer.

## Revenue and margins

> [!NOTE]
>
> Margins are on the Scale and Enterprise plans. On another plan the page says customer margins aren't on your plan and shows spend only.

A customer's margin is the revenue you recorded for the month, less what their AI calls cost. Cost is the counted figure above. Revenue comes from you, by a signed push from your billing job, by a CSV, or both. TensorCost never connects to your billing, CRM or payment system and holds no credential to one. The customer ids must be the ones your calls carry.

Only USD revenue is compared with cost. TensorCost doesn't convert currencies. Revenue in another currency is shown beside the row as recorded, for example "€1,200 (not converted)", and a customer with only that is marked **Not in USD** and has no margin. A customer with no revenue at all is marked **No revenue recorded**.

Above the table, one line gives USD revenue, less the AI spend on those customers, as a margin. It adds how much more went to customers with no USD revenue.

> [!WARNING]
>
> Margins cover every environment, because revenue isn't recorded per environment. While an environment filter is on, the margin columns are hidden and the page says to clear the filter.

### Revenue pushed from your system

Your billing job sends each customer's running monthly total to `POST /v1/api/cost/revenue`, signed with a signing secret an admin makes under **Connect › API keys**. The newest `as_of` wins, so a late or repeated job can't roll a figure back, and negative values are allowed for credits and refunds. The full format, with a worked signing example, is on [Push customer revenue](https://docs.tensorcost.com/developers/revenue-push.md).

### Revenue from a CSV

For revenue you'd rather upload than push, an admin or finance user selects **Import revenue (CSV)** on the page. The columns are:

```csv theme={null}
customer,month,revenue,currency
acme,2026-11,1200.50,USD
globex,2026-11,0,USD
initech,2026-11,980,EUR
```

* `month` is `YYYY-MM`.
* `revenue` is in major units with at most two decimals.
* `currency` is a three-letter code such as USD or EUR.
* A line with `0` clears that customer's month. In the example, `globex` has no revenue for November.
* The header names are not case-sensitive. A customer, month and currency can appear once in a file.

The file is taken whole or not at all. If any line is bad, nothing is written and the page lists each bad line by number. A file is at most 5 MB and 50,000 rows; split a larger one by month.

An import replaces the CSV rows for the customers and months the file names, in any currency. Other customers and other months are untouched, so to correct one customer you can upload just that customer. Rows a push wrote for a customer and month the file names are replaced too, whatever their `as_of`.

A customer, month and currency holds one figure. A push and a CSV never add together. The figure with the later `as_of` stands, and a CSV's `as_of` is the moment you uploaded it.

The same import is available to the API as `POST /v1/api/cost/customer-revenue/import`, with the file as the body and `Content-Type: text/csv`.

### What margins feed

The monthly revenue also sets each customer's limit in a margin floor budget, and the usage can be read back out:

* [A margin floor](https://docs.tensorcost.com/spend/budgets.md#every-customer-keeps-a-margin) caps what a customer's calls can cost against their revenue. [A fixed amount](https://docs.tensorcost.com/spend/budgets.md#each-customer-a-fixed-amount) caps it without revenue at all.
* [Pull customer usage](https://docs.tensorcost.com/developers/usage-pull.md) gives your billing job each customer's daily cost and tokens.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.