LanguageValues and typesStandard typesAI
TokenUsage
On this page
The tokens one call to a model used: what it read, what it wrote and what its cache served.
Use it to track what model calls cost. For one number alone, use TokenCount.
Shape
| Field | Type | Required? |
|---|---|---|
input |
TokenCount |
Yes |
output |
TokenCount |
Yes |
cached |
TokenCount |
No |
Write every field when you build one, and give a field that isn't required as none.
Its parts keep these rules, and a value that breaks one fails with the rule's name:
cached_within_input: cached <= input, where it is given
Example
TokenUsage { input: 1200 output: 350 cached: none }Good to know
cachedisnonewhere a provider doesn't say. It can't be aboveinput.==tells you whether two are the same.<andlist.sort_bydon't take it, so sort by one of its parts instead.
In JSON
An object of its parts, in a request, a response or json.write:
{"input":1200,"output":350,"cached":null}{"input":1200,"output":350,"cached":800}{"input":0,"output":0,"cached":0}
When you read one, a field that isn't required may be left out, or sent as null.
Details
Text form, storage, how it is shown, and operations
TokenUsage is in the group AI, and has been in Jadpo since 0.1.0.
Text form
It has no single text form, so text.from and text.parse don't take it.
How it is stored
It is stored in 3 columns, each named for the field, _ and its suffix. This is {"input":1200,"output":350,"cached":800}:
| Column | Type | Holds |
|---|---|---|
<field>_input |
bigint |
1200 |
<field>_output |
bigint |
350 |
<field>_cached |
bigint |
800 |
How it is shown to people
text.format(value, locale:) shows it to people in their locale.
With locale: Locale.en_gb:
| Value | Shown |
|---|---|
{"input":1200,"output":350,"cached":null} |
input 1,200, output 350 |
{"input":1200,"output":350,"cached":800} |
input 1,200, output 350, cached 800 |
{"input":0,"output":0,"cached":0} |
input 0, output 0, cached 0 |
Operations
It also takes text.format, json.read, json.write and ==. How every standard type behaves says how they work.
Markdown for agents: /docs/types/type-token-usage.md.Built from Jadpo main at aee2e8f.