Token accounting. Every model response carries a usage block; the agent adds them up across the run so you can see what a task cost.
Token accounting. Every model response carries a usage block; the agent adds them up across the run so you can see what a task cost.
(add a b)Sums two usage maps field by field.
Sums two usage maps field by field.
(cache-hit-rate {:keys [prompt-tokens cache-hit-tokens]})The share of prompt tokens the provider served from its cache, 0.0 to 1.0. nil when nothing has been sent yet.
The share of prompt tokens the provider served from its cache, 0.0 to 1.0. nil when nothing has been sent yet.
(cost usage prices)What a run cost, given prices in currency per million tokens:
{:input 0.28 :output 0.42} ; flat {:input 0.28 :output 0.42 :cache-hit 0.028} ; cheaper cached prompt tokens
Prices change and differ per model, so the harness holds none - pass your provider's current numbers. Returns nil when no prices are given.
What a run cost, given prices in currency per million tokens:
{:input 0.28 :output 0.42} ; flat
{:input 0.28 :output 0.42 :cache-hit 0.028} ; cheaper cached prompt tokens
Prices change and differ per model, so the harness holds none - pass your
provider's current numbers. Returns nil when no prices are given.(normalize usage)Turns an API usage block into our keys. DeepSeek reports cache hits and misses separately (a hit is billed cheaper); other OpenAI-compatible providers omit them, and missing fields simply stay zero.
Turns an API usage block into our keys. DeepSeek reports cache hits and misses separately (a hit is billed cheaper); other OpenAI-compatible providers omit them, and missing fields simply stay zero.
(of-message message)The usage jj.bettong.llm/chat stashed on the message it returned. A stubbed
chat-fn carries none, which still counts as one request.
The usage `jj.bettong.llm/chat` stashed on the message it returned. A stubbed chat-fn carries none, which still counts as one request.
(summary {:keys [requests prompt-tokens completion-tokens total-tokens
cache-hit-tokens]
:as usage})One line worth printing at the end of a run.
One line worth printing at the end of a run.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |