g1t/services/billing/migrations/0030_token_usage.sql
| 1 | -- Model tokens, added up per day and run, for usage views: the model proxy |
| 2 | -- reports what each answer used. Billing still prices runs from AI |
| 3 | -- Gateway, never from these. |
| 4 | CREATE TABLE token_usage ( |
| 5 | -- YYYY-MM-DD, UTC. |
| 6 | day TEXT NOT NULL, |
| 7 | workspace TEXT NOT NULL, |
| 8 | -- The person the run was for, by username; empty when nobody asked. |
| 9 | person TEXT NOT NULL DEFAULT '', |
| 10 | -- The model session's id, one per run (runs.session_id). |
| 11 | session TEXT NOT NULL, |
| 12 | model TEXT NOT NULL, |
| 13 | -- On g1t's hosted models: small or large. |
| 14 | tier TEXT, |
| 15 | input INTEGER NOT NULL DEFAULT 0, |
| 16 | output INTEGER NOT NULL DEFAULT 0, |
| 17 | cache_read INTEGER NOT NULL DEFAULT 0, |
| 18 | cache_write INTEGER NOT NULL DEFAULT 0, |
| 19 | requests INTEGER NOT NULL DEFAULT 0, |
| 20 | PRIMARY KEY (day, workspace, person, session, model) |
| 21 | ); |
| 22 | CREATE INDEX token_usage_by_workspace_day ON token_usage (workspace, day); |
| 23 | CREATE INDEX token_usage_by_person_day ON token_usage (workspace, person, day); |