TokenUsage
The tokens one call to a model used: what it read, what it wrote, and how many of those it read its provider's cache served, where it says.
AI; not ordered; since Jadpo 0.1.0.
Make one
Build one from its fields, TokenUsage { input: ... output: ... }.
Its parts keep these rules; a value that breaks one fails with the rule's name:
cached_within_input:cached <= input, where it is given
Fields
| Field | Type |
|---|---|
input |
TokenCount |
output |
TokenCount |
cached |
TokenCount? |
Text, JSON and storage
It has no single text form, so text.from and text.parse don't take it. JSON sends an object of its parts.
| JSON |
|---|
{"input":1200,"output":350,"cached":null} |
{"input":1200,"output":350,"cached":800} |
{"input":0,"output":0,"cached":0} |
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 |
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 has the contract's own operations: text.format, json.read, json.write and ==. It isn't ordered, so < and sorting don't take it. Every standard type meets one contract says how they work.
Markdown for agents: /docs/types/type-token-usage.md.Built from Jadpo main at e00e61f.