Requesty
Back|OCT '26COST OPTIMIZATION / OBSERVABILITY
13 MIN READ|

How to Track LLM Costs per User, Team or Customer (2026)

Last updated

On October 29, 2026, Anthropic launched its Usage and Cost Analytics API in beta. To track LLM costs per user across providers, attach trusted user and customer IDs to each request and sum recorded costs. Requesty provides managed tracking; LiteLLM and Bifrost suit self-hosting, while Langfuse focuses on traces. We make Requesty.

What an attribution record needs

An LLM invoice tells you how much a provider charged. To answer who caused the charge, you need a record connecting the provider request to the work your application was doing.

Authenticated application context supplies user, customer, run and team identifiers to a gateway request. The gateway records usage from model provider calls for grouped reports. A separate direct provider call bypasses the gateway report.
A shared gateway key identifies the service. Server-supplied fields identify the user, customer and run. Illustrative.

Picture a support application that serves several customers. A request might carry user_123, cust_789, run_456 and the team support. The user triggered the work, the customer pays for the product, the run ties related calls together, and the team owns the service. Those are four different questions, even when all four fields are on one request.

In Requesty, User and Member are different analytics dimensions: User is the external ID supplied in request metadata; Member is the organization member who owns the API key. Grouping by Member will not split a shared service key among its end users.

RecordWhy keep it
User, customer, team, environmentAttribute the work and separate production from testing.
Run ID and request or attempt IDJoin agent steps and identify retries without counting the same event twice.
Time, provider, requested and served modelMatch the reporting period and explain fallback costs.
Usage by billing category and effective ratePrice input, output, cache and other units under the applicable terms.
Cost and key IDSum by owner and trace a total back to its source.

For an agent workflow, join each run's call costs to task outcomes using the run ID. Divide the cost of all runs, including failed runs and chargeable retries, by the number of completed tasks. Track completion rate alongside it. See cost per task, not cost per token.

Before changing models, run the same representative tasks with both options. Compare cost per completed task and completion rate, then ship the cheaper option only if it meets your quality threshold.

The general calculation is sum(nonoverlapping usage buckets * applicable rates) + billable tool or other charges. Keep the rate and service tier that applied at the time. Some providers include cached tokens inside their input total; subtract the included cache portion before applying a separate cache rate. LiteLLM's reconciliation guide explains the provider differences, and Langfuse warns against overlapping usage buckets because they double-count cost.

A per-request cost is an operating record, not an invoice. Finance still needs to reconcile it with discounts, credits, tool charges, direct traffic and gateway fees for the same period.

Choose how to attach ownership

MethodBest useWhat it gives youTrade-off
Labeled keyA team, service or customer with a stable ownerSpend grouped by key or label; a separately scoped credentialA key shared across customers cannot distinguish them on its own.
Request metadataA shared application serving many users or customersPer-request user, customer and run dimensionsThe application must attach trustworthy values on every path.
Analytics headersA tool or service that can set headersPer-request custom fields such as team or customerA header is a reporting field, not a separately scoped credential.

The console supports editing key labels. You can also group spend by API key without labels, or use request metadata and headers for per-request reporting.

For a multi-tenant SaaS product, start with a service or team key and attach user and customer IDs to each call. Give a customer a separate key when you also need independent revocation or a key-scoped spend limit. A customer tag or header alone does not create that limit.

Requesty supports key labels, request metadata and custom analytics headers. The key labeling guide explains the ownership pattern; use the endpoint reference below for the current API shape. For agents sharing a credential, see how to separate agent identity and spend.

Track LLM costs per user with Requesty

Requesty groups model costs across providers using a key and the identifiers you attach to each request. The setup below uses one application key. The fixed IDs are examples; in production, populate them from the authenticated request and your customer mapping.

  1. 1
    Send an attributed request

    Create a key in the Requesty console. For this paid model on a prepaid account, add credits in Billing settings. Export REQUESTY_API_KEY in your shell and install the OpenAI Python SDK with pip install openai. The example uses openai/gpt-6-sol; check its availability in the Requesty model library. The request metadata guide documents the body format, and the analytics header guide documents the header.

    Python
    import os
    from openai import OpenAI
     
    client = OpenAI(
        api_key=os.environ["REQUESTY_API_KEY"],
        base_url="https://router.requesty.ai/v1",
    )
     
    response = client.chat.completions.create(
        model="openai/gpt-6-sol",
        messages=[{"role": "user", "content": "Summarize this support ticket."}],
        extra_headers={"X-Requesty-Team": "support"},
        extra_body={
            "requesty": {
                "user_id": "user_123",
                "trace_id": "run_456",
                "tags": ["support", "summarization"],
                "extra": {"customer_id": "cust_789", "feature": "ticket_summary"},
            }
        },
    )
    print(response.usage.cost)

    For this non-streaming Chat Completions request, Requesty returns a USD cost in usage.cost. user_id is the built-in end-user field; customer_id is a custom field under extra; the header creates a separate Team analytics field. The X-Requesty-Team analytics header is stored with request logs and removed before forwarding to the provider. Do not put passwords, API keys or personal information in it.

  2. 2
    Group the spend and export it

    Open Analytics in the Requesty console and select Advanced. Choose Group By: User, Metric: Cost and Calculation: Sum. Set the time range and choose Time Grouping: None for one total per user. Repeat with the customer_id custom field from extra or with Team, inspect the source request logs, and export the Data Summary as CSV. See usage analytics and analytics exports.

  3. 3
    Test two customers

    Send a request for each of two customers with distinct users. Confirm that each request appears under the right customer and user, and that both appear in the expected team total. Repeat the test for each endpoint and background job your application uses.

For streamed Chat Completions, pass stream=True and stream_options={"include_usage": True}, then consume the stream and read chunk.usage when present. The final usage chunk has an empty choices array. If the stream ends early, use gateway logs and provider data to reconcile the incomplete client record. See Requesty's streaming documentation.

Label a key and query team spend

In the API Keys console, edit an existing key's labels. For example, set team to support and environment to production. Use a separate key for a different stable owner, then group by the key or its labels.

To automate the same setup, export API_KEY_ID as the UUID of an existing key and REQUESTY_MANAGEMENT_KEY as a separate management credential with write-manage permission. Keep that credential on your server. This label update endpoint sets the labels on the existing key:

Shell
curl -X POST "https://api-v2.requesty.ai/v1/manage/apikey/$API_KEY_ID/label" \
  -H "Authorization: Bearer $REQUESTY_MANAGEMENT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"labels":{"team":"support","environment":"production"}}'

The documented success response is HTTP 204. An empty labels object removes all labels. To read daily organization spend grouped by the team label, use a management credential with read permission and the organization usage endpoint:

Shell
curl -G "https://api-v2.requesty.ai/v1/manage/org/usage" \
  -H "Authorization: Bearer $REQUESTY_MANAGEMENT_KEY" \
  --data-urlencode "start=2026-10-01T00:00:00Z" \
  --data-urlencode "end=2026-10-29T00:00:00Z" \
  --data-urlencode "resolution=day" \
  --data-urlencode "group_by=api_key_label.team"

The response includes daily grouped_data with group values and spend; sum the relevant daily rows for a period total. Keys missing the label appear under Unknown. Keep a time-versioned ownership mapping outside the gateway if historical chargeback must survive key relabeling.

Requesty key limits can reject requests when a key reaches its limit. A team label is a reporting dimension. Requesty also has Enterprise groups for team management. Test concurrent requests near any limit and leave a buffer for in-flight work.

Compare LLM cost tracking tools in 2026

Pick Requesty for managed multi-provider attribution, LiteLLM or Bifrost when you want to run your own gateway, and Langfuse when the agent trace is your starting point. Portkey is worth choosing for its grouped Analytics API and metadata-based usage policies. Native provider APIs are useful for reconciling their own bills.

The comparison reflects documentation checked October 2026. Requesty makes one of the products compared.

Tool and layerAttributionBest fitDecision point
Requesty, gatewayKey labels, user IDs, custom fields and headersManaged multi-provider attributionGroups are an Enterprise feature.
LiteLLM, gatewayKeys, users, teams and customersSelf-hosting with customer budget controlsIts spend-by-tag example and spend reports include Enterprise features; you operate the gateway.
Bifrost, gatewayKey metadata, teams and customersSelf-hosting with key and customer budgetsA key belongs directly to a team or a customer, not both.
Langfuse, observabilityUsers, tags and generation costs within tracesAgent traces and evaluation; self-hosted optionTracing alone does not enforce a gateway budget.
Helicone, observabilityUser ID and custom propertiesSegmenting logged requestsCost-based limits use a time window and can be segmented by user or property.
Portkey, gatewayUser and custom metadata groupsGrouped Analytics API and per-user or per-customer usage policiesDeveloper records 10,000 logs per month; requests continue without additional recorded logs after that limit.
OpenAI, native APICost by project, organization user, API key and line itemReconciling OpenAI usage and costsOrganization users are distinct from arbitrary app customers; the report covers OpenAI.
Anthropic, native APIBeta cost and usage by actor, workspace, API key and model, where applicableReconciling Claude usage and costsPer-profile reporting requires registered profiles and an eligible Developer Platform organization.

OpenAI's Costs API supports organization-user and key grouping; some combinations of user and project filters depend on the organization and time range. Anthropic's beta cost reference also lists user_profile_id as a cost dimension for Claude Developer Platform organizations. Its actor is the user, service account, cloud identity or key behind a request, not the downstream customer represented by a profile.

For direct Claude API traffic, Anthropic's profile guide says to register an end customer, store the returned profile ID and send it with each request. The profile type depends on whether it represents a signed-up application user or a company buying resold API access. Join the profile ID to your own customer record; profile attribution is configured, not automatic. Anthropic's report covers Claude. A combined multi-provider ledger requires joining additional data.

For Requesty pay as you go, Billing adds a 5% fee on top of credit top-ups, with no seat fees or minimums. Use billing history or the top-up invoice for the fee amount. Ask finance how to allocate the fee and prepaid balance to the reporting period, and check exported costs against billing records before adding a fee. For BYOK traffic, join the direct provider bill with any applicable gateway charges without counting provider spend twice.

Calculate gross margin per customer

Suppose a SaaS company wants to know whether its AI feature is profitable at each plan level. Export cost by customer_id, reconcile that spend, and join it to the billing system's recognized revenue and finance's other direct costs for the same customer and month.

Assume the following monthly amounts for one customer on each plan. LLM and gateway cost includes any applicable fee once. Other direct COGS includes the support, hosting and tool costs finance assigns to the customer. Revenue excludes sales tax.

Customer planRevenueLLM and gateway costOther direct COGSTotal COGSGross profitGross margin
Starter$29$8$5$13$1655.17%
Growth$99$40$20$60$3939.39%
Enterprise$499$210$80$290$20941.88%
Illustrative gross margins for one customer per plan: Starter 55.17% on $29 revenue and $13 COGS, Growth 39.39% on $99 revenue and $60 COGS, Enterprise 41.88% on $499 revenue and $290 COGS.
Assumed monthly revenue and direct costs per customer. Margins use the calculation in the table.

For Growth, gross margin is ($99 - $40 - $20) / $99 * 100 = 39.39%. If its LLM and gateway cost doubles to $80 while revenue and other direct COGS stay fixed, margin falls to ($99 - $80 - $20) / $99 * 100 = -1.01%. The same subscription now loses money before overhead.

The weak assumption is the allocation of direct costs. Agree on a finance-approved rule for shared costs and keep any unallocated pool visible. To report margin across a plan, divide the sum of gross profit by the sum of revenue; an unweighted average of customer percentages can give a different result. Subtracting inference alone gives an inference-only margin, not full gross margin.

Reconcile before using the numbers for billing

A dashboard can show a precise total for an incomplete dataset. Assume a $100 provider bill for the same period as the gateway report, with no credits or gateway fees. Of that bill, $80 is captured and assigned to customers, $10 is captured without a customer ID, and $10 bypassed the gateway.

The gateway records $90: $80 + $10. The $10 bypass explains the gap to the provider bill. Customer allocations total $80, leaving $20 to investigate or allocate under finance's rule: $10 unassigned + $10 bypassed. Keep both amounts visible until you know their owners.

LLM cost attribution checks

0 of 8 done

Identity
Coverage
Pricing
Finance
Controls

A request can succeed while its metadata is missing: a LiteLLM issue reported that behavior on one endpoint in specific versions. A fix was merged; test every path in your deployment, including those outside Chat Completions. A zero cost is also worth investigating: check model price coverage and compare the logged amount with provider billing.

Separate uncaptured and unallocated amounts from contract discounts or credits so finance can see why the totals differ. LiteLLM's cost discrepancy guide provides a reconciliation checklist.

What to do this week

If a customer needs its own revocable credential and spending cap, assign it a separate key. Attach user metadata to calls within that customer account. If reporting is all you need, a shared service key with trusted customer metadata is a good starting point.

This week, instrument one production workflow for two customers and compare the request records with the grouped totals. Reconcile the result against provider invoices each month. Start free with Requesty or add the fields using the request metadata guide.

Frequently asked questions
What is the best tool to track LLM costs per user?
Requesty is a managed option for grouping multi-provider spend by user, customer and team. LiteLLM and Bifrost suit self-hosted gateways, while Langfuse is a good fit for tracing costs through agent workflows. We make Requesty.
How do I track LLM spend per customer with one shared API key?
Attach a customer ID from authenticated server-side context to every request and aggregate the recorded cost by that ID. Requesty supports customer IDs in request metadata or custom analytics headers; a shared key alone cannot distinguish customers.
Can OpenAI and Anthropic report costs per user?
OpenAI's Costs API groups spend by organization user and API key. Anthropic's beta groups by actor and supports registered user profiles for per-profile costs in eligible Developer Platform organizations. Anthropic profiles must be created and attached to requests; they are separate from organization users.
How do I track LLM costs per team?
Assign a key to each team and group spend by key or label, or attach a trusted team field to each request. Requesty also has Enterprise groups for team management.
Why is my streaming LLM cost missing?
For Requesty Chat Completions, set stream_options to include usage and consume the final usage chunk. An interrupted stream can miss that chunk, so compare the client record with gateway logs and provider billing.
How do I calculate gross margin for an AI customer?
Subtract attributed model and gateway costs and other direct cost of goods sold from recognized revenue, then divide by revenue. Join the customer-level spend report to billing and finance records for the same period.
Related reading

Start building with Requesty

One line of code. 600+ models. Full control.

Speak to founders