Use case

How to track AI cost per customer

Provider reports group usage by model, project or API key. Your application supplies the customer and workflow context needed to see cost per account.

Send an x-customer-id header with each request you route through Spendline, set on your server from authenticated request context. Spendline prices the call and records it against that customer ID in an append-only ledger as the call completes.

How it works

Each routed call already carries the provider, model and token counts needed to price it. Your application adds the customer. Spendline records the supplied customer ID and server time with the priced call; the server time decides which day and month the cost lands in. A server timestamp fixes the time, not the customer: Spendline cannot tell a wrong customer ID from a right one, so the ID has to come from your own authenticated context, set per request and never in a shared client's default headers.

Sample request headers (illustrative)
x-spendline-key: $SPENDLINE_API_KEY
x-customer-id: cust_4f21a
x-agent-id: support-bot

What to know before relying on it

A routed call with no customer ID is still priced and recorded, but it lands in an unattributed bucket rather than against any customer, so missing labels show up as a gap in customer reporting. Calls sent directly to a provider, and unsupported API shapes such as embeddings, are not recorded at all.

Why it matters

Without per-call attribution, cost per customer is a spreadsheet exercise rebuilt by hand from provider logs, usually late and often wrong. With it, the figure for the traffic you route exists as the calls happen.

Frequently asked questions

What if a call cannot be tied to one customer, a background job, for example?

Give it a stable synthetic ID such as internal:nightly-reindex, and tag it with a cost centre in x-spendline-tags. Do not invent a random ID per call: every call would look like a new customer.

Does this work across more than one AI provider?

Yes, for supported routes: chat completions for OpenAI-compatible providers, Anthropic Messages and non-streaming OpenAI Responses. The same x-customer-id header works on each, so per-customer cost is in one ledger.

See what this would look like in your product.

Start with a guided 30-day free pilot on live production traffic. The 30 days start when your traffic flows through Spendline, not at sign-up. We agree the scope, success criteria and paid terms before you start. There is no Spendline subscription fee during the pilot; your model-provider charges still apply.

Prefer email? fida@spendline.ai