fleet-memory/hindsight-clients/python/hindsight_client_api/models
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
..
__init__.py feat: Add per-request LLM token usage metrics (#117) 2026-01-08 10:36:58 +01:00
add_background_request.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
background_response.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
bank_list_item.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
bank_list_response.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
bank_profile_response.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
bank_stats_response.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
budget.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
cancel_operation_response.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
chunk_data.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
chunk_include_options.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
chunk_response.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
create_bank_request.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
delete_document_response.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
delete_response.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
disposition_traits.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
document_response.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
entity_detail_response.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
entity_include_options.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
entity_input.py doc: changelog for 0.2.0 (and regenerate clients) (#99) 2026-01-05 12:36:29 +01:00
entity_list_item.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
entity_list_response.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
entity_observation_response.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
entity_state_response.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
graph_data_response.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
http_validation_error.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
include_options.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
list_documents_response.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
list_memory_units_response.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
memory_item.py doc: changelog for 0.2.0 (and regenerate clients) (#99) 2026-01-05 12:36:29 +01:00
operation_response.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
operations_list_response.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
recall_request.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
recall_response.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
recall_result.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
reflect_fact.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
reflect_include_options.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
reflect_request.py feat: add max_tokens and structured output to /reflect (#74) 2026-01-01 17:09:39 +01:00
reflect_response.py feat: Add per-request LLM token usage metrics (#117) 2026-01-08 10:36:58 +01:00
retain_request.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
retain_response.py feat: Add per-request LLM token usage metrics (#117) 2026-01-08 10:36:58 +01:00
token_usage.py feat: Add per-request LLM token usage metrics (#117) 2026-01-08 10:36:58 +01:00
update_disposition_request.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
validation_error.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00
validation_error_loc_inner.py feat(misc): update clients types, test coverage, improve /health endpoint and add changelog (#70) 2025-12-23 12:49:31 +01:00