Attribution Data API
Get cost breakdown by dimension
Returns cost aggregation grouped by any metadata dimension key. Call it with a GET request to /attribution-data/by-dimension, authenticated with a restricted API key and the "costs:read" scope.
Returns cost aggregation grouped by any metadata dimension key. Supports any key: model, provider, feature, agent_id, workflow_id, or custom keys. Events without the specified dimension key are bucketed as "Unassigned". When `format=csv`, the response is a `text/csv` attachment (`Content-Disposition: attachment; filename="bear-lumen-attribution-<dimension>-<start>-to-<end>.csv"`) whose columns mirror the JSON item fields; null token counts and costs render as empty cells, never 0. The JSON schema below applies only to `format=json` (the default). 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
| Name | In | Type | Required | Description |
|---|---|---|---|---|
dimension | query | string | Yes | Metadata dimension key to group by (e.g., "model", "provider", "agent_id"). |
start_date | query | string | Yes | Start of date range (ISO 8601, inclusive). |
end_date | query | string | Yes | End of date range (ISO 8601, exclusive). |
filter_key | query | string | No | Optional cross-dimension filter key (e.g., "environment"). Applied only when filter_value is also provided; a request with filter_key alone returns the unfiltered breakdown. |
filter_value | query | string | No | Optional cross-dimension filter value (exact match). Applied only when filter_key is also provided; a request with filter_value alone returns the unfiltered breakdown. |
format | query | json | csv | No | Response format: json (default) or csv. |
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.
| Field | Type | Description |
|---|---|---|
items | object[] | Cost breakdown items. |
attribution_value | string | Attribution value (e.g., agent name or workflow name). |
total_cost | string | Total cost for this attribution value. |
input_tokens | number (double) | Input tokens used. |
output_tokens | number (double) | Output tokens used. |
cache_creation_input_tokens | number (double) nullable | Cache-creation input tokens; null = provider did not report. |
cache_read_input_tokens | number (double) nullable | Cache-read input tokens; null = provider did not report. |
reasoning_tokens | number (double) nullable | Reasoning tokens; null = not reported. |
input_cost | string | Input cost (USD, decimal string). |
output_cost | string | Output cost (USD, decimal string). |
cache_creation_cost | string nullable | Cache-creation cost (USD string); null = not reported. |
cache_read_cost | string nullable | Cache-read cost (USD string); null = not reported. |
reasoning_cost | string nullable | Reasoning cost (USD string); null = not reported. |
event_count | number (double) | Number of events. |
percent_of_total | number (double) | Percentage of the total cost within this query scope (date range plus any filter_key/filter_value filter). Values across items sum to 100. |
total_cost | string | Total cost across all items. |
Error codes
Errors return the standard error envelope with a code, message, and a correlationId you can quote to support.
| Status | When it happens |
|---|---|
400 | Invalid request data. Check that start_date and end_date are valid ISO 8601 dates and fix the field named in error.message. |
401 | Missing or invalid API key. Send your key as Authorization: Bearer YOUR_API_KEY. |
403 | API key lacks the costs:read scope. Create or update an API key with the costs:read scope, then retry. |
429 | Rate limit or plan quota exceeded. Slow down and retry after the current window resets. |
Rate limits and retries
Rate limit or plan quota exceeded. Slow down and retry after the current window resets.