Attribution Data API
Get session call tree
Reconstructs one session's span call tree: one node per span with its own cost, its subtree cost (the span plus every descendant), and its nested children, so you can see which branch of a multi-agent run spent the money. Call it with a GET request to /attribution-data/sessions/{sessionId}/tree, authenticated with a restricted API key and the "costs:read" scope.
GET https://api.bearlumen.com/v1/attribution-data/sessions/{sessionId}/tree
Reconstructs one session's span call tree: one node per span with its own cost, its subtree cost (the span plus every descendant), and its nested children, so you can see which branch of a multi-agent run spent the money. Roots are ordered by subtree cost descending. Unlike the other attribution endpoints, the lookup spans all time; it is not bounded by a date range. Use spans (see the tracing guide) to link calls into a tree; events that carry the session_id but no span_id are reported in the untraced bucket rather than as tree nodes. The sum of the root subtree costs plus the untraced total always equals the session's flat total from the sessions endpoints. Malformed span chains never lose cost: a span whose parent id does not exist in the session is promoted to a root and flagged orphaned; a parent-pointer cycle is broken at a deterministic entry span flagged cycle; chains deeper than 32 levels are cut at a node flagged depth_capped, which keeps the pruned descendants' cost in its subtree cost. 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 |
|---|---|---|---|---|
sessionId | path | string | Yes | The session_id metadata value to look up. |
Response example
Success response (200):
{
"roots": [
{
"agent_id": null,
"children": [
{
"agent_id": null,
"children": [],
"depth": 1,
"event_count": 1,
"kind": "retrieval",
"name": "kb-search",
"orphaned": false,
"own_cost": "0.84",
"parent_span_id": "a3f81c92d4b7e615",
"span_id": "b6d24e07f9a1c382",
"subtree_cost": "0.84"
}
],
"depth": 0,
"event_count": 1,
"kind": "agent",
"name": "resolve-ticket",
"orphaned": false,
"own_cost": "1.13",
"parent_span_id": null,
"span_id": "a3f81c92d4b7e615",
"subtree_cost": "1.97"
}
],
"session_id": "sess_out_qW3nT8xA",
"untraced": {
"event_count": 1,
"total_cost": "0.28"
}
}
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. Fix the field named in error.message and retry. |
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. |
404 | No session with this sessionId exists for your organization. Verify the session_id value sent on your usage events. |
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.