feat(statestore): record a usage row for every model call
Task agent runs and MCP sampling record against their task (billed to the task's org); gateway chat turns, titles, sampling and curators record against the system org. Rows carry source, workflow, step, alias, provider/model and tokens for later chargeback.
This commit is contained in:
1 parent
12b9a57404
commit
e4ea2eaabc
31 files changed
+1068
-322
No files matched your search
@@ -0,0 +1,26 @@
|
||||
-- One row per model call: who made it, for what, on which model, and the
|
||||
-- tokens it used. Chargeback and usage reports aggregate these rows.
|
||||
|
||||
-- +goose Up
|
||||
|
||||
CREATE TABLE model_usage (
|
||||
id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
org_id text NOT NULL,
|
||||
source text NOT NULL CHECK (source IN ('task', 'chat', 'curator')),
|
||||
task_id bigint NOT NULL DEFAULT 0,
|
||||
attempt bigint NOT NULL DEFAULT 0,
|
||||
workflow text NOT NULL DEFAULT '',
|
||||
step text NOT NULL DEFAULT '',
|
||||
alias text NOT NULL DEFAULT '',
|
||||
provider text NOT NULL,
|
||||
model text NOT NULL,
|
||||
input_tokens bigint NOT NULL DEFAULT 0,
|
||||
output_tokens bigint NOT NULL DEFAULT 0,
|
||||
cached_tokens bigint NOT NULL DEFAULT 0,
|
||||
at timestamptz NOT NULL
|
||||
);
|
||||
CREATE INDEX idx_model_usage_org_at ON model_usage (org_id, at);
|
||||
|
||||
-- +goose Down
|
||||
|
||||
DROP TABLE model_usage;
|
||||
Reference in new issue
Block a user