End User Costs API

Get cost breakdown by dimension for a specific end-user

Returns cost aggregation grouped by a metadata dimension key for the specified end-user. Call it with a GET request to /end-user-costs/{externalId}/by-dimension, authenticated with a restricted API key and the "costs:read" scope.

Returns cost aggregation grouped by a metadata dimension key for the specified end-user. Events that do not carry the requested key are grouped under the literal value "Unassigned". A key that no events carry does not return an error; it returns the full cost in a single "Unassigned" row, so verify the key name if you see 100% Unassigned. Requests count toward your per-API-key rate limit; sustained overruns return 429 with the standard error envelope.

Authentication and scopes

Authenticate with a restricted API key in the Authorization: Bearer <key> header. This endpoint requires the costs:read scope.

Parameters

NameInTypeRequiredDescription
externalIdpathstringYesEnd-user identifier you assigned when sending usage events (the user_id field on POST /usage-events). An end user exists only after at least one event referencing this identifier has been ingested; unknown identifiers return 404.
dimensionquerystringYesMetadata dimension key to group by (e.g., 'feature', 'team', 'agent_id'). Only 'feature' reads a typed event field; every other key is looked up in event metadata. For per-model or per-provider breakdowns use the dedicated /by-model and /by-provider endpoints instead of a metadata key.
start_datequerystringYesStart of date range (ISO 8601, inclusive).
end_datequerystringYesEnd of date range (ISO 8601, exclusive).

Response fields

Fields returned in the 200 response body. Nested objects are listed under their parent. A field marked optional may be absent from the body; one marked nullable is always present but its value may be null.

FieldTypeDescription
end_user_idstringBear Lumen internal end-user ID (UUID). Use the externalId path parameter for lookups, not this value.
itemsobject[]Cost breakdown by dimension value.
attribution_valuestringDimension value; events missing the requested metadata key are grouped under the literal value 'Unassigned'.
total_coststringTotal cost for this dimension value (decimal string).
input_tokensnumber (double)Input tokens used.
output_tokensnumber (double)Output tokens used.
cache_creation_input_tokensnumber (double) nullableCache-creation input tokens; null = provider did not report.
cache_read_input_tokensnumber (double) nullableCache-read input tokens; null = provider did not report.
reasoning_tokensnumber (double) nullableReasoning tokens; null = not reported.
input_coststringInput cost (USD, decimal string).
output_coststringOutput cost (USD, decimal string).
cache_creation_coststring nullableCache-creation cost (USD string); null = not reported.
cache_read_coststring nullableCache-read cost (USD string); null = not reported.
reasoning_coststring nullableReasoning cost (USD string); null = not reported.
event_countnumber (double)Number of events.
percent_of_totalnumber (double)Percentage of end-user's total cost for this dimension.
total_coststringTotal cost across all dimension values (decimal string).

Error codes

Errors return the standard error envelope with a code, message, and a correlationId you can quote to support.

StatusWhen it happens
400Invalid request data. Check that required query parameters are present and that start_date and end_date are valid ISO 8601 dates.
401Missing or invalid API key. Send your key as Authorization: Bearer YOUR_API_KEY.
403API key lacks the costs:read scope. Create or update a key with the costs:read scope, then retry.
404End user not found. The identifier must match the user_id value sent on at least one ingested usage event.
429Rate limit exceeded. Retry after the time indicated by the Retry-After header (rate-limit state is also reported in the standard RateLimit-* headers, e.g. RateLimit-Reset).

Rate limits and retries

Rate limit exceeded. Retry after the time indicated by the Retry-After header (rate-limit state is also reported in the standard RateLimit-* headers, e.g. RateLimit-Reset).