Expand description
Local token counting (§6.3): tiktoken for gpt families, bundled/downloaded
HF tokenizers for the rest, char-estimate floor. Native-only behind
count-local except the estimate, which serves the edge build.
Structs§
- Tokenizer
Registry - Global tokenizer registry living on
AppState. - Vocab
Info - Listing entry for the admin surface.
Enums§
- Vocab
Source - Where a vocab comes from.
Traits§
Functions§
- count
- Count tokens of a provider-native request body.
map= provider settingstokenizer_map(glob → vocab name). Never fails: worst case is the chars/2 estimate. - count_
text - Count a single text buffer with the same local fallback Clove uses for Claude Web usage synthesis: cl100k when local tokenizers are enabled, otherwise the cross-target character estimate.
- harvest
- Harvest human-text from any provider-native request JSON: walks the value,
collecting strings under text-ish keys (
text,content,instructions, string-formsystem, gemini parts text) plus tool definitions serialized. Returns(texts, message_count)wheremessage_countis the length of the largestmessages/contents/inputarray found (0 if none). - is_
gpt_ family - Whether
modelbelongs to a gpt family with an exact local tiktoken vocabulary (drives the §17 counting-ladder source label).
Type Aliases§
- Registry
Handle - What
countreceives as the registry: a real handle undercount-local, a unit on builds without it (edge) so call sites stay uniform.