Files
chat_backend/llm_be
westfarnandCursor d4bc3fa71f
CI / test (pull_request) Successful in 10s
Unit Tests / test (pull_request) Successful in 9s
Track token in/out per prompt on PromptMetric
Closes #15

Add nullable tokens_in / tokens_out IntegerFields to PromptMetric so we
record real prompt/completion token counts per turn. Values come from the
LLM provider usage payload via a new extract_token_usage helper; when a
provider does not report usage the fields stay null (never estimated).

- consumers/consumers_graph create_prompt_metric + finish_prompt_metric
  now accept and persist optional tokens_in / tokens_out.
- Admin: PromptMetric lists tokens_in/tokens_out (+ event/model filters);
  Conversation admin shows summed tokens_in/out/total per conversation.
- Tests cover the model fields, extract_token_usage parsing, metric
  lifecycle token persistence, and admin aggregation.

Follow-ups: #16 (frontend token display) and #17 (billing/quotas).
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-26 08:00:57 -05:00
..
2025-03-07 12:23:00 -06:00
2025-12-08 13:52:30 -06:00
2025-03-07 12:23:00 -06:00