fabro/lib
Bryan Helmkamp 8f36772af3
feat(llm): add input token counting (#359)
## Summary

Adds an optional `fabro-llm` API for counting model-visible input tokens
without creating a completion, with provider-native counting where
available and deterministic local estimates when exact counting is
unavailable or intentionally avoided.

## Details

- Adds `Client::count_input_tokens` plus `InputTokenCountPreference`
modes for provider-preferred, provider-required, and estimate-only
behavior.
- Implements provider count endpoints for Anthropic, Gemini, and OpenAI
while filtering request bodies to count-supported fields.
- Adds strict fallback semantics so local estimates do not hide bad
credentials, invalid requests, unsupported models,
context-length/content-filter failures, or other deterministic provider
errors.
- Adds a deterministic local estimator with explicit warning codes for
local estimates, media heuristics, opaque provider context, and provider
options.
- Documents privacy implications: provider-native counting sends the
provider-serialized model-visible request to the upstream count
endpoint, while `EstimateOnly` keeps counting local.

## Verification

- `cargo nextest run -p fabro-llm` - 385 passed, 10 skipped
- `cargo +nightly-2026-04-14 fmt --check --all`
- `cargo +nightly-2026-04-14 clippy -p fabro-llm --all-targets -- -D
warnings`
- `cargo build --workspace`

---

[![Compound
Engineering](https://img.shields.io/badge/Compound_Engineering-6366f1)](https://github.com/EveryInc/compound-engineering-plugin)
🤖 Generated with GPT-5 (context unknown, thinking not disclosed) via
[Codex](https://openai.com/codex)
2026-05-23 05:52:54 -04:00
..
crates feat(llm): add input token counting (#359) 2026-05-23 05:52:54 -04:00
packages/fabro-api-client feat(fabro-types): promote transcript primitives and extend agent event… (#357) 2026-05-22 20:40:10 -04:00