End User Costs API

Get cost breakdown by provider for a specific end-user

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

GET https://api.bearlumen.com/v1/end-user-costs/{externalId}/by-provider

Returns cost aggregation grouped by AI provider for the specified end-user. 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.
start_datequerystringYesStart of date range (ISO 8601, inclusive).
end_datequerystringYesEnd of date range (ISO 8601, exclusive).

Response example

Success response (200):

JSON
{
  "end_user_id": "eb77aa11-0001-7777-9a1b-2c3d4e5f6a01",
  "providers": [
    {
      "event_count": 3,
      "percent_of_total": 60,
      "provider_name": "openai",
      "provider_slug": "openai",
      "total_cost": "1145.04"
    },
    {
      "event_count": 2,
      "percent_of_total": 30,
      "provider_name": "anthropic",
      "provider_slug": "anthropic",
      "total_cost": "572.52"
    },
    {
      "event_count": 1,
      "percent_of_total": 10,
      "provider_name": "google",
      "provider_slug": "google",
      "total_cost": "190.84"
    }
  ],
  "total_cost": "1908.4"
}

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).