| llm_usage | R Documentation |
Reads the diagnostic columns produced by call_llm_par() (and
call_llm_broadcast() / llm_fn() with .return = "columns") or by
llm_mutate(), and returns a one-row tibble of counts and token totals. It
reports tokens, not money: sent, received, total, and reasoning tokens
are summed with na.rm = TRUE (correct under row batching, which attributes a
batch's tokens to its first row and leaves the rest NA). To estimate cost,
multiply these by your provider's current per-token prices yourself.
llm_usage(x, prefix = NULL, price_table = NULL)
x |
A data frame from |
prefix |
For an |
price_table |
Optional data frame you supply with your provider's
current prices, holding columns |
A one-row tibble: n, n_ok, n_failed, ok_rate, n_truncated
(finish "length"), n_filtered (finish "filter"), sent_tokens,
rec_tokens, total_tokens, reasoning_tokens, cached_tokens
(prompt tokens served from the provider's cache, when reported),
n_unknown_tokens
(successful rows for which the provider reported no token usage, so the
token sums above understate the truth), duration_s, (when a batch id
column is present) rowpack_calls and rows_per_rowpack, and (when
price_table is supplied) cost_estimate in the table's currency.
llm_failures(), llm_preview(), llm_par_resume().
res <- tibble::tibble(
success = c(TRUE, TRUE, FALSE),
finish_reason = c("stop", "length", "error:rate_limit"),
sent_tokens = c(10L, 12L, NA_integer_),
rec_tokens = c(5L, 7L, NA_integer_),
total_tokens = c(15L, 19L, NA_integer_),
reasoning_tokens = c(NA_integer_, NA_integer_, NA_integer_),
duration = c(0.4, 0.5, 0.1)
)
llm_usage(res)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.