End User Costs API
Get cost breakdown by model for a specific end-user
Returns cost aggregation grouped by AI model for the specified end-user. Call it with a GET request to /end-user-costs/{externalId}/by-model, authenticated with a restricted API key and the "costs:read" scope.
GET https://api.bearlumen.com/v1/end-user-costs/{externalId}/by-model
Returns cost aggregation grouped by AI model 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
| Name | In | Type | Required | Description |
|---|---|---|---|---|
externalId | path | string | Yes | End-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_date | query | string | Yes | Start of date range (ISO 8601, inclusive). |
end_date | query | string | Yes | End of date range (ISO 8601, exclusive). |
Response example
Success response (200):
{
"end_user_id": "eb77aa11-0001-7777-9a1b-2c3d4e5f6a01",
"models": [
{
"cache_creation_cost": "1.86",
"cache_creation_input_tokens": 88400,
"cache_read_cost": "1.21",
"cache_read_input_tokens": 403200,
"event_count": 2,
"input_cost": "507.03",
"input_tokens": 729100,
"model_slug": "gpt-4o",
"output_cost": "253.26",
"output_tokens": 182700,
"percent_of_total": 40,
"provider_slug": "unknown",
"reasoning_cost": null,
"reasoning_tokens": null,
"total_cost": "763.36"
},
{
"cache_creation_cost": null,
"cache_creation_input_tokens": null,
"cache_read_cost": null,
"cache_read_input_tokens": null,
"event_count": 2,
"input_cost": "381.68",
"input_tokens": 555300,
"model_slug": "claude-3-5-sonnet",
"output_cost": "190.84",
"output_tokens": 138800,
"percent_of_total": 30,
"provider_slug": "unknown",
"reasoning_cost": null,
"reasoning_tokens": null,
"total_cost": "572.52"
},
{
"cache_creation_cost": null,
"cache_creation_input_tokens": null,
"cache_read_cost": null,
"cache_read_input_tokens": null,
"event_count": 1,
"input_cost": "254.45",
"input_tokens": 1183100,
"model_slug": "gpt-4o-mini",
"output_cost": "127.23",
"output_tokens": 295800,
"percent_of_total": 20,
"provider_slug": "unknown",
"reasoning_cost": null,
"reasoning_tokens": null,
"total_cost": "381.68"
},
{
"cache_creation_cost": null,
"cache_creation_input_tokens": null,
"cache_read_cost": null,
"cache_read_input_tokens": null,
"event_count": 1,
"input_cost": "127.23",
"input_tokens": 883100,
"model_slug": "gemini-2.0-flash",
"output_cost": "63.61",
"output_tokens": 220800,
"percent_of_total": 10,
"provider_slug": "unknown",
"reasoning_cost": null,
"reasoning_tokens": null,
"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.
| Status | When it happens |
|---|---|
400 | Invalid request data. Check that required query parameters are present and that start_date and end_date are valid ISO 8601 dates. |
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 a key with the costs:read scope, then retry. |
404 | End user not found. The identifier must match the user_id value sent on at least one ingested usage event. |
429 | 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). |
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).