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.
This commit is contained in:
parent
84b6937bbf
commit
1b79a7370d
2 changed files with 1181 additions and 13 deletions
17
migrations/postgres/0022_claude_usage.sql
Normal file
17
migrations/postgres/0022_claude_usage.sql
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
-- 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);
|
||||
17
migrations/sqlite/0022_claude_usage.sql
Normal file
17
migrations/sqlite/0022_claude_usage.sql
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
-- What the calls to Claude cost: one row for each question asked of the provider, with the tokens that were billed and how
|
||||
-- it ended. Nothing of the facts that were sent is kept: no artist, no genre, no name. Rows older than a year are removed.
|
||||
|
||||
CREATE TABLE claude_usage (
|
||||
id INTEGER PRIMARY KEY,
|
||||
at INTEGER NOT NULL, -- unix seconds
|
||||
kind TEXT NOT NULL, -- playlist, mix or smart
|
||||
model TEXT NOT NULL,
|
||||
outcome TEXT NOT NULL, -- made, kept or failed
|
||||
reason TEXT NOT NULL DEFAULT '',-- for a failure
|
||||
input_tokens INTEGER NOT NULL DEFAULT 0,
|
||||
output_tokens INTEGER NOT NULL DEFAULT 0,
|
||||
cache_read_tokens INTEGER NOT NULL DEFAULT 0,
|
||||
cache_write_tokens INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
|
||||
CREATE INDEX idx_claude_usage_at ON claude_usage(at);
|
||||
Loading…
Reference in a new issue