yoniebans
18e6cd9938
fix: include cache tokens in dashboard analytics input totals
...
The /api/analytics/usage endpoint summed only the raw input_tokens
column, which for Anthropic-direct sessions holds only the uncached
portion of the prompt. cache_read_tokens and cache_write_tokens
(which complete the total prompt) were ignored.
This caused the dashboard to massively undercount token usage —
showing ~117M instead of ~345M over 30 days — since Anthropic
sessions with high cache hit rates stored almost all prompt tokens
in the cache columns.
Fix: fold COALESCE(cache_read_tokens, 0) + COALESCE(cache_write_tokens, 0)
into the input_tokens sum across all three SQL queries (daily, by-model,
totals). This is correct for every provider because normalize_usage()
guarantees input_tokens + cache_read + cache_write = total prompt tokens
regardless of API shape (Anthropic / OpenAI / Codex).
Add a regression test that creates a session with Anthropic-style token
splits and asserts the endpoint returns the combined total.
2026-04-27 21:48:41 +02:00
..
2026-02-26 03:20:08 +03:00
2026-04-20 22:21:21 -07:00
2026-04-24 07:14:00 -07:00
2026-04-07 17:19:07 -07:00
2026-04-07 17:19:07 -07:00
2026-04-22 02:59:58 -07:00
2026-04-26 05:43:31 -07:00
2026-04-20 23:20:33 -07:00
2026-04-20 20:53:51 -07:00
2026-04-21 14:31:48 -05:00
2026-04-07 17:19:07 -07:00
2026-04-07 17:19:07 -07:00
2026-04-24 04:53:32 -07:00
2026-04-24 05:20:05 -07:00
2026-04-24 05:20:05 -07:00
2026-04-14 01:43:45 -07:00
2026-04-08 13:46:30 -07:00
2026-04-24 03:00:33 -07:00
2026-04-20 00:47:39 -07:00
2026-04-25 18:48:43 -07:00
2026-04-27 06:43:52 -07:00
2026-04-07 17:59:42 -07:00
2026-03-18 03:17:37 -07:00
2026-04-23 23:28:34 -07:00
2026-04-09 16:24:53 -07:00
2026-04-12 16:40:37 -07:00
2026-04-11 01:52:58 -07:00
2026-04-17 21:35:30 -07:00
2026-03-09 21:36:29 -07:00
2026-04-19 12:39:58 -07:00
2026-04-24 04:53:32 -07:00
2026-04-26 11:38:32 -07:00
2026-04-14 10:45:42 -07:00
2026-04-21 14:23:45 -07:00
2026-04-07 17:19:07 -07:00
2026-04-17 19:03:26 -07:00
2026-04-19 12:40:08 -07:00
2026-04-20 23:20:33 -07:00
2026-04-12 16:36:11 -07:00
2026-04-10 03:44:43 -07:00
2026-04-24 05:09:08 -07:00
2026-04-24 03:33:29 -07:00
2026-04-24 05:09:08 -07:00
2026-04-19 05:19:22 -07:00
2026-04-25 18:47:53 -07:00
2026-04-26 21:52:12 -07:00
2026-04-22 15:27:54 -05:00
2026-04-16 06:48:33 -07:00
2026-04-20 22:14:29 -07:00
2026-04-20 22:14:29 -07:00
2026-04-17 05:08:07 -07:00
2026-04-14 23:13:11 -07:00
2026-04-25 18:01:36 -07:00
2026-04-22 05:51:44 -07:00
2026-04-13 04:35:37 -07:00
2026-04-26 06:19:04 -07:00
2026-04-09 16:24:53 -07:00
2026-03-14 12:11:23 -07:00
2026-04-23 13:59:29 -07:00
2026-04-10 21:15:47 -07:00
2026-04-22 16:33:46 -07:00
2026-04-24 04:46:17 -07:00
2026-04-20 23:20:33 -07:00
2026-04-20 20:53:51 -07:00
2026-04-22 19:58:42 -07:00
2026-04-23 01:56:09 -07:00
2026-03-29 21:54:36 -07:00
2026-04-11 17:23:36 -07:00
2026-03-30 17:34:43 -07:00
2026-04-16 21:57:10 -07:00
2026-03-17 03:48:44 -07:00
2026-04-16 06:48:33 -07:00
2026-04-26 05:46:43 -07:00
2026-04-24 05:24:54 -07:00
2026-04-17 06:33:21 -07:00
2026-04-22 02:59:58 -07:00
2026-04-25 18:47:53 -07:00
2026-04-16 01:16:14 -07:00
2026-04-24 04:58:46 -07:00
2026-04-24 04:58:46 -07:00
2026-04-08 19:58:16 -07:00
2026-04-26 21:33:31 -07:00
2026-04-22 17:33:42 -07:00
2026-04-25 14:13:02 -05:00
2026-04-20 22:14:03 -07:00
2026-04-13 04:33:52 -07:00
2026-04-26 19:02:55 -07:00
2026-04-24 04:58:46 -07:00
2026-04-16 07:17:45 -07:00
2026-04-22 17:33:42 -07:00
2026-04-21 05:19:43 -07:00
2026-04-24 05:20:05 -07:00
2026-03-16 06:07:45 -07:00
2026-03-14 10:35:14 -07:00
2026-04-17 01:05:09 -07:00
2026-04-21 21:30:10 -07:00
2026-04-17 01:05:09 -07:00
2026-04-24 07:06:11 -07:00
2026-04-01 11:20:33 -07:00
2026-04-23 03:02:34 -07:00
2026-04-23 02:37:07 -07:00
2026-04-24 10:51:49 -04:00
2026-04-09 14:20:16 -07:00
2026-04-24 05:03:26 -07:00
2026-04-27 08:52:12 -07:00
2026-04-26 21:33:31 -07:00
2026-04-26 18:49:48 -07:00
2026-04-26 18:31:07 -07:00
2026-03-31 11:41:12 -07:00
2026-04-19 00:28:25 -07:00
2026-04-09 16:24:53 -07:00
2026-04-10 21:15:59 -07:00
2026-04-10 03:44:43 -07:00
2026-04-25 22:02:02 -07:00
2026-04-26 18:49:48 -07:00
2026-04-20 14:56:04 -07:00
2026-04-16 20:43:41 -07:00
2026-04-25 22:02:02 -07:00
2026-04-24 04:48:56 -07:00
2026-04-24 03:46:46 -07:00
2026-04-26 20:57:10 -07:00
2026-03-17 01:59:07 -07:00
2026-03-28 14:32:23 -07:00
2026-03-11 00:50:39 -07:00
2026-04-22 13:20:02 -07:00
2026-04-24 05:30:05 -07:00
2026-04-16 12:36:49 -07:00
2026-04-24 05:20:05 -07:00
2026-04-17 01:05:09 -07:00
2026-03-30 11:17:15 -07:00
2026-04-25 18:25:13 -07:00
2026-04-10 02:57:39 -07:00
2026-04-20 00:52:50 -07:00
2026-04-13 16:32:04 -07:00
2026-03-29 20:05:59 -07:00
2026-04-26 12:55:58 -07:00
2026-03-26 13:39:41 -07:00
2026-04-24 15:51:38 -06:00
2026-04-27 08:52:12 -07:00
2026-04-10 00:32:20 -07:00
2026-04-19 19:38:02 -07:00
2026-04-19 22:43:09 -07:00
2026-04-23 14:01:57 -07:00
2026-04-17 21:29:24 -07:00
2026-04-24 05:48:15 -07:00
2026-04-23 16:18:15 -07:00
2026-04-21 06:26:35 -07:00
2026-04-27 21:48:41 +02:00
2026-04-26 18:43:57 -07:00
2026-03-28 14:33:35 -07:00
2026-04-24 03:33:05 -07:00