fleet-memory/hindsight-docs/docs/developer
Alexander Pinsker 29a542dc23
feat: Add per-request LLM token usage metrics (#117)
* feat: Record LLM token metrics via Prometheus

Wire up the existing token metrics infrastructure to actually record
token usage from LLM calls. The MetricsCollector already had
record_tokens() method and Prometheus counters (hindsight.tokens.input,
hindsight.tokens.output), but they were never being populated.

Changes:
- Import get_metrics_collector in llm_wrapper.py
- Call record_tokens() after successful LLM calls for:
  - OpenAI/Groq (using response.usage.prompt_tokens, completion_tokens)
  - Anthropic (using response.usage.input_tokens, output_tokens)
  - Gemini (using response.usage_metadata.prompt_token_count, candidates_token_count)
- Add test file to verify token metrics are recorded

Note: Ollama's native API doesn't return token usage, so metrics
are not recorded for that provider.

The token metrics will now be available via /metrics endpoint:
- hindsight_tokens_input_total
- hindsight_tokens_output_total

* feat: add per-request token usage tracking to retain and reflect endpoints

- Add TokenUsage model with input_tokens, output_tokens, total_tokens
- Return usage metrics in retain response (sync operations only)
- Return usage metrics in reflect response
- Update Python, TypeScript, and Rust clients
- Add API documentation for usage fields
- Add changelog entry
2026-01-08 10:36:58 +01:00
..
api feat: Add per-request LLM token usage metrics (#117) 2026-01-08 10:36:58 +01:00
admin-cli.md feat: run db migrations offline (optionally) (#114) 2026-01-07 15:49:51 +01:00
configuration.md feat: run db migrations offline (optionally) (#114) 2026-01-07 15:49:51 +01:00
development.md rename to hindsight (#2) 2025-11-25 19:28:26 +01:00
extensions.md doc: add documentation for extensions (#62) 2025-12-22 11:58:05 +01:00
index.md fix: make sure openai provider works + docs updates (#23) 2025-12-10 16:10:10 +01:00
installation.md feat: simplify mcp installation + ui standalone (#41) 2025-12-18 10:24:56 +01:00
mcp-server.md fix docs build 2025-12-11 12:54:36 +01:00
metrics.md improve docs 2025-12-10 16:47:41 +01:00
models.md feat(doc): add new config options and supported providers (#84) 2026-01-01 17:09:05 +01:00
performance.md bump pg0 0.11.x and improve documentation (#33) 2025-12-16 13:33:01 +01:00
rag-vs-hindsight.md fix: make sure openai provider works + docs updates (#23) 2025-12-10 16:10:10 +01:00
reflect.md brandind and misc fixes 2025-12-11 12:46:48 +01:00
retain.md bump pg0 0.11.x and improve documentation (#33) 2025-12-16 13:33:01 +01:00
retrieval.md bump pg0 0.11.x and improve documentation (#33) 2025-12-16 13:33:01 +01:00
services.md feat: simplify mcp installation + ui standalone (#41) 2025-12-18 10:24:56 +01:00
storage.md bump pg0 0.11.x and improve documentation (#33) 2025-12-16 13:33:01 +01:00