Model usage was recorded per call and never read, so an org could not see what it spent. Add the read side: - model_usage carries identity_id. Task calls take it from the task row, chat and curator calls from the calling principal carried in the usage record, so an outbox replay keeps its attribution. Existing task rows are backfilled from tasks. - StatsService.UsageTotals sums the caller org's rows by UTC day, source, provider, model and identity. The org comes from the principal, with no org parameter, so cross-org reads do not exist. - GET /api/usage prices tokens at the catalog's list rate, netting cache hits, and reports calls to unpriced models as tokens only. The published catalog view now carries each model's cost. - A new org Usage page behind a read_usage grant: admin and owner only, with a 7, 30 or 90 day range, totals, the daily series, and model, source and identity breakdowns. The org shell keeps it on the caller's own org.
70 lines
2.3 KiB
Protocol Buffer
70 lines
2.3 KiB
Protocol Buffer
syntax = "proto3";
|
|
|
|
package state.v1;
|
|
|
|
service StatsService {
|
|
rpc StatusCounts(StatusCountsRequest) returns (StatusCountsResponse);
|
|
rpc WorkflowStats(WorkflowStatsRequest) returns (WorkflowStatsResponse);
|
|
rpc StageStats(StageStatsRequest) returns (StageStatsResponse);
|
|
rpc TokensByDay(TokensByDayRequest) returns (TokensByDayResponse);
|
|
rpc UsageTotals(UsageTotalsRequest) returns (UsageTotalsResponse);
|
|
}
|
|
|
|
// WorkflowStat mirrors storecontract.WorkflowStat.
|
|
message WorkflowStat {
|
|
string workflow = 1;
|
|
int64 runs = 2;
|
|
int64 merged = 3;
|
|
int64 pr_open = 4;
|
|
int64 parked = 5;
|
|
int64 avg_tokens = 6;
|
|
double avg_steps = 7;
|
|
int64 total_tokens = 8;
|
|
int64 completed = 9;
|
|
// running and last_status describe the newest runs, so a workflow whose
|
|
// runs are older than a global task page still reports its real state.
|
|
int64 running = 10;
|
|
string last_status = 11;
|
|
}
|
|
// StageStat mirrors storecontract.StageStat.
|
|
message StageStat {
|
|
string workflow = 1;
|
|
string stage = 2;
|
|
int64 runs = 3;
|
|
int64 avg_ms = 4;
|
|
int64 errors = 5;
|
|
}
|
|
// DayTokens mirrors storecontract.DayTokens.
|
|
message DayTokens {
|
|
string day = 1;
|
|
int64 tokens = 2;
|
|
}
|
|
message StatusCountsRequest {}
|
|
message StatusCountsResponse { map<string, int64> counts = 1; }
|
|
message WorkflowStatsRequest {}
|
|
message WorkflowStatsResponse { repeated WorkflowStat stats = 1; }
|
|
message StageStatsRequest {}
|
|
message StageStatsResponse { repeated StageStat stats = 1; }
|
|
message TokensByDayRequest { int64 days = 1; }
|
|
message TokensByDayResponse { repeated DayTokens tokens = 1; }
|
|
|
|
// UsageTotalRow is one cell of a model-usage report: the day, source,
|
|
// provider, model and identity the calls belong to, and the tokens they
|
|
// used. Cost is not carried: the reader prices the tokens against the model
|
|
// catalog, so a price change is a change of interpretation, not of history.
|
|
message UsageTotalRow {
|
|
string day = 1;
|
|
string source = 2;
|
|
string provider = 3;
|
|
string model = 4;
|
|
// identity is who the work was requested as, empty when unknown.
|
|
string identity = 5;
|
|
int64 calls = 6;
|
|
int64 input_tokens = 7;
|
|
int64 output_tokens = 8;
|
|
int64 cached_tokens = 9;
|
|
}
|
|
// UsageTotalsRequest names the range ending now, in days.
|
|
message UsageTotalsRequest { int64 days = 1; }
|
|
message UsageTotalsResponse { repeated UsageTotalRow rows = 1; }
|