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.

GET https://api.bearlumen.com/v1/attribution-data/by-dimension

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

NameInTypeRequiredDescription
dimensionquerystringYesMetadata dimension key to group by (e.g., "model", "provider", "agent_id").
start_datequerystringYesStart of date range (ISO 8601, inclusive).
end_datequerystringYesEnd of date range (ISO 8601, exclusive).
filter_keyquerystringNoOptional 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_valuequerystringNoOptional cross-dimension filter value (exact match). Applied only when filter_key is also provided; a request with filter_value alone returns the unfiltered breakdown.
formatqueryjson | csvNoResponse format: json (default) or csv.

Response example

Success response (200):

JSON
{
  "items": [
    {
      "attribution_value": "gpt-4o",
      "cache_creation_cost": "0.5",
      "cache_creation_input_tokens": 133400,
      "cache_read_cost": "0.11",
      "cache_read_input_tokens": 220150,
      "event_count": 3,
      "input_cost": "5.39",
      "input_tokens": 2155500,
      "output_cost": "2.5",
      "output_tokens": 249300,
      "percent_of_total": 50,
      "reasoning_cost": null,
      "reasoning_tokens": null,
      "total_cost": "8.5"
    },
    {
      "attribution_value": "claude-sonnet-4-5",
      "cache_creation_cost": null,
      "cache_creation_input_tokens": null,
      "cache_read_cost": "0.09",
      "cache_read_input_tokens": 181400,
      "event_count": 2,
      "input_cost": "3.37",
      "input_tokens": 1348000,
      "output_cost": "1.64",
      "output_tokens": 163450,
      "percent_of_total": 30,
      "reasoning_cost": null,
      "reasoning_tokens": null,
      "total_cost": "5.1"
    },
    {
      "attribution_value": "gpt-4o-mini",
      "cache_creation_cost": null,
      "cache_creation_input_tokens": null,
      "cache_read_cost": "0.07",
      "cache_read_input_tokens": 140600,
      "event_count": 2,
      "input_cost": "2.23",
      "input_tokens": 891850,
      "output_cost": "1.1",
      "output_tokens": 109700,
      "percent_of_total": 20,
      "reasoning_cost": null,
      "reasoning_tokens": null,
      "total_cost": "3.4"
    }
  ],
  "total_cost": "17"
}

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 start_date and end_date are valid ISO 8601 dates and fix the field named in error.message.
401Missing or invalid API key. Send your key as Authorization: Bearer YOUR_API_KEY.
403API key lacks the costs:read scope. Create or update an API key with the costs:read scope, then retry.
429Rate 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.