sonda/migrations/postgres/0022_claude_usage.sql
tgiachi 1b79a7370d feat(naming): an admin section that shows what Claude costs
- Every question asked of Claude is recorded: when, the kind of list, the model, the tokens read and written (also for an answer that was no name but was billed) and how it ended: a name made, a name taken from the kept ones, or a failure and why. Nothing of the facts that were sent is recorded. Records older than a year are removed (migration 0022).
- GET /providers/anthropic/usage (admin) gives the totals of the last days (1 to 365, 30 by default), a row for each day with calls and an estimate of the cost in dollars, worked out from the tokens and the price of the model. It says it is an estimate and flags calls to a model whose price is not known.
- A Costs section in the admin area shows the last 7, 30 or 90 days.
2026-11-13 11:14:45 +01:00

17 lines
737 B
SQL

-- What the calls to Claude cost: one row for each question asked of the provider. PostgreSQL flavour of
-- sqlite/0022_claude_usage.sql.
CREATE TABLE claude_usage (
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
at BIGINT NOT NULL, -- unix seconds
kind TEXT NOT NULL,
model TEXT NOT NULL,
outcome TEXT NOT NULL,
reason TEXT NOT NULL DEFAULT '',
input_tokens BIGINT NOT NULL DEFAULT 0,
output_tokens BIGINT NOT NULL DEFAULT 0,
cache_read_tokens BIGINT NOT NULL DEFAULT 0,
cache_write_tokens BIGINT NOT NULL DEFAULT 0
);
CREATE INDEX idx_claude_usage_at ON claude_usage(at);