Commit

Usage's cost shows comped runs at what they cost the provider, not $0

A run charged nothing at all (a comped workspace's) has no charge or covered amount in the ledger, only its provider cost, so flagon-io's panel read $0.00. Such runs now count at their provider cost.

syntaqxcommitted Parentee65320Browse files
2 files+8−60/2 viewed
+1−1
9292 <>
9393 <dl className="mt-4 grid grid-cols-2 gap-2">
9494 <Tile label="Tokens" value={compactTokens(usage.totalTokens)} />
95− <Tile label="Cost" value={usd(usage.costMicros / 1e6)} title="What these runs were charged" />
95+ <Tile label="Cost" value={usd(usage.costMicros / 1e6)} title="What these runs cost, whoever paid" />
9696 <Tile label="Active days" value={String(usage.activeDays)} hint={`of ${usage.days}`} />
9797 <Tile label="From cache" value={share == null ? "—" : `${Math.round(share * 100)}%`} title="Prompt tokens read from the model's cache" />
9898 </dl>
+7−5
170170 .await?
171171 .results::<DayRow>()
172172 };
173− // What the window's runs cost at g1t's price, whoever paid: what was
173+ // What the window's runs cost, whoever paid: at g1t's price, what was
174174 // left to pay plus what included usage, credit, the trial, the
175− // open-source pool or a comp covered, so a comped workspace's runs
176− // still show their cost. While g1t charges nothing, the provider's
177− // cost. For one person, the runs whose sessions counted their tokens.
175+ // open-source pool or a comp covered; a run charged nothing at all
176+ // (comped, or while g1t charges nothing) at the provider's cost.
177+ // For one person, the runs whose sessions counted their tokens.
178178 let measure = if self.free {
179179 "COALESCE(l.cost_micros, 0)"
180180 } else {
181− "(-l.amount_micros + l.credit_micros + l.trial_micros + l.oss_micros + l.given_micros)"
181+ "CASE WHEN (-l.amount_micros + l.credit_micros + l.trial_micros + l.oss_micros + l.given_micros) > 0
182+ THEN (-l.amount_micros + l.credit_micros + l.trial_micros + l.oss_micros + l.given_micros)
183+ ELSE COALESCE(l.cost_micros, 0) END"
182184 };
183185 let sessions = if person.is_some() {
184186 " AND r.session_id IN (SELECT session FROM token_usage WHERE workspace = ?1 AND person = ?3 AND day >= ?2)"