Skip to contents

Aggregates the usage rows of sessions (children included, each request counted once) and, for x = NULL, of every live session of this process plus the process System 1 log. Reads only.

Usage

gptr_usage(
  x = NULL,
  by = c("session", "agent", "model", "route"),
  detail = FALSE
)

Arguments

x

A gptr_session, a list of sessions, or NULL (every live session of this process and the System 1 log).

by

Grouping of the summary: "session", "agent", "model" or "route".

detail

FALSE: a gptr_usage data frame (group, requests, input, output, cache_read, cache_write, cost) with attribute totals; TRUE: the gptr_ledger per request and context component (request_id, component, tokens, cached) of the sessions' own requests, session by session in request order (a child's requests are in the child's ledger).

Value

A gptr_usage or gptr_ledger data frame.

Details

Unknown usage stays unknown: a token count or cost that a provider did not report is NA, never zero, so a group or total that includes it is NA. The footer adds the known tokens and the known cost to a count of the requests whose tokens or cost are unknown (1.2k tokens in + 1 request of unknown tokens, $1.2000 + 1 request of unknown cost). A known zero, such as the metered charge of a local model, stays zero. Rows without a session, agent, model or route (process-level System 1 calls) form the NA group. On claude-cli models, billed to a Claude plan, the dollar figures are the CLI's API-equivalent estimate, not a charge; cost limits use them.

The detailed component ledger contains estimates; its sum can differ from provider-reported usage. A run's token budget checks estimated next-input tokens and recorded usage before requests; cost limits check recorded cost. The next output or an unknown final charge can exceed a remaining allowance, so these stopping policies are not billing reservations. Teams and fan-outs count child requests against their shared root budget.

Examples

gptr_usage()
#>    group        requests  input  output  cache_read  cache_write  cost
#>  1 s0e1f4b1996  1         1580   2       0           0            0
#>  2 s17de12fb3e  1         1583   3       0           0            0
#>  3 sdb8aa7fa98  1         1581   1       0           0            0
#>  4 s9ed925771f  1         1581   1       0           0            0
#>  5 s44f6546a78  1         1580   1       0           0            0
#>  6 s560a32d0a8  2         3301   9       0           0            0
#>  7 sa1b0845a68  4         6354   14      0           0            0
#>  8 sf032e10a3f  1         1582   1       0           0            0
#>  9 s41c7255c4a  2         3165   10      0           0            0
#> 10 s91220586f5  1         1344   26      0           0            0
#> 11 sf33d6d0c07  1         1332   26      0           0            0
#> 12 s2291f4ce74  2         3276   13      0           0            0
#> 13 s40a07e8041  2         3276   13      0           0            0
#> 14 s5c2772b2a1  1         2229   26      0           0            0
#> 15 sb2fc4ea4f1  2         3276   13      0           0            0
#> 16 NA           1         91     20      0           0            0
#> 
#> # 16 rows
#> 24 requests, 37.1k tokens in, $0.0000
session = peter("hi", model = gptr_fake_provider(list("hello")))
#> gptr: thinking
#> gptr: done · fake-1 · 1 request · 1.6k tokens · 99% context left
gptr_usage(session)
#>   group        requests  input  output  cache_read  cache_write  cost
#> 1 se251def66e  1         1580   2       0           0            0
#> 
#> # 1 row
#> 1 request, 1.6k tokens in, $0.0000