Files
sam e4ea2eaabc 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.
2026-10-10 18:32:43 +11:00

27 lines
898 B
SQL

-- 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;