Commit

Billing's usage total is labeled at price, and Usage says what part of it was paid for

syntaqx's Billing said $9.14 of usage and its Usage $6.01 spent: the first is at price, the second what was charged after the trial and pools paid their $3.13. Usage now returns covered_micros and its Spent card says so; Billing's total reads Total at price.

syntaqxcommitted Parent73aad90Browse files
6 files+25−70/6 viewed
+5−2
118118 **This month's usage**: what each kind of usage has come to so far, in
119119 dollars and in what was used (*Agents & sandboxes*, *Builds*, *Requests &
120120 CPU*, *Custom domains*, *Git operations & storage*, *Search & security
121−scans*). App traffic, custom domains, storage and git operations are
122−counted through the month and charged when it closes. **Manage on Stripe** opens the card, invoices and
121+scans*). Its **Total at price** is before the included usage, the trial or
122+a pool paid their part, so it can be more than what was charged; the
123+workspace's **Usage** page shows what was charged as **Spent**, and how much
124+of the total those paid. App traffic, custom domains, storage and git
125+operations are counted through the month and charged when it closes. **Manage on Stripe** opens the card, invoices and
123126 billing details. **End at the end of the period** ends the plan then, with
124127 nothing more charged after; **Keep the plan** takes that back until then.
125128 If a renewal payment fails, the card says **Payment failed**, with
+4−2
346346 ))}
347347 </ul>
348348 <div className="mt-1 flex items-baseline justify-between gap-4 border-t border-line pt-2.5 text-sm">
349− <span className="font-medium">Total</span>
349+ {/* At price, before the plan's included usage, the trial and the pools paid
350+ their part: Usage shows what was charged. */}
351+ <span className="font-medium">Total at price</span>
350352 <span className="font-medium tabular-nums">{dollars(total)}</span>
351353 </div>
352354 <p className="mt-2 text-xs text-faint">
354356 ? "What this workspace's usage would cost. g1t covers it."
355357 : on
356358 ? `Drawn from the included usage first, then charged up to your spend limit. Projects, previews and repositories are never charged, and the first ${freeStorage} of private storage and ${freeGit} git operations a month are free. App traffic, custom domains, storage and git operations are counted through the month and charged when it closes.`
357− : `The forge is free: ${freeStorage} of private storage and ${freeGit} git operations a month. Agents run from the trial or the open-source pool.`}
359+ : `The forge is free: ${freeStorage} of private storage and ${freeGit} git operations a month. Agents run from the trial or the open-source pool, which pay part of this total: Usage shows what was charged.`}
358360 </p>
359361 </div>
360362 );
+5−3
228228 label="Spent"
229229 value={dollars(usage.spentMicros)}
230230 note={
231− usage.providerMicros > 0
232− ? `Plus about ${dollars(usage.providerMicros)} billed by your own model provider`
233− : `${dollars(usage.costMicros)} of it the model provider's`
231+ (usage.coveredMicros ?? 0) > 0
232+ ? `Of ${dollars(usage.spentMicros + (usage.coveredMicros ?? 0))} at price: ${dollars(usage.coveredMicros ?? 0)} of it was paid by the included usage, the trial or a pool`
233+ : usage.providerMicros > 0
234+ ? `Plus about ${dollars(usage.providerMicros)} billed by your own model provider`
235+ : `${dollars(usage.costMicros)} of it the model provider's`
234236 }
235237 />
236238 )}
+5−0
324324 pub since: String,
325325 /// Charged, including g1t's margin.
326326 pub spent_micros: i64,
327+ /// What paid for usage before it was charged, at price: the plan's
328+ /// included usage, the trial, the open-source pool and what g1t
329+ /// covered. Usage at price is `spent_micros` plus this.
330+ #[serde(default)]
331+ pub covered_micros: i64,
327332 /// What g1t's model provider charged, before the margin.
328333 pub cost_micros: i64,
329334 /// What runs on the workspace's own provider cost there, as the harness
+2−0
10141014 since: string;
10151015 /** Charged, including g1t's margin. */
10161016 spentMicros: number;
1017+ /** What paid for usage before it was charged, at price: the plan's included usage, the trial, the open-source pool, what g1t covered. Usage at price is `spentMicros` plus this. */
1018+ coveredMicros?: number;
10171019 /** What g1t's model provider charged, before the margin. */
10181020 costMicros: number;
10191021 /** What runs on the workspace's own provider cost there, estimated. Not charged by g1t. */
+4−0
428428 #[derive(serde::Deserialize)]
429429 struct Totals {
430430 spent: Option<i64>,
431+ covered: Option<i64>,
431432 cost: Option<i64>,
432433 provider: Option<i64>,
433434 runs: Option<u32>,
438439 .prepare(
439440 "SELECT
440441 -SUM(CASE WHEN kind = 'usage' THEN amount_micros END) AS spent,
442+ SUM(CASE WHEN kind = 'usage' THEN credit_micros + trial_micros + oss_micros + given_micros END) AS covered,
441443 SUM(CASE WHEN kind = 'usage' AND COALESCE(billed_to, 'g1t') = 'g1t' THEN cost_micros END) AS cost,
442444 SUM(CASE WHEN kind = 'usage' AND billed_to = 'workspace' THEN cost_micros END) AS provider,
443445 SUM(CASE WHEN kind = 'usage' THEN 1 ELSE 0 END) AS runs,
463465 .await?;
464466 let totals = totals.unwrap_or(Totals {
465467 spent: None,
468+ covered: None,
466469 cost: None,
467470 provider: None,
468471 runs: None,
470473 });
471474 Ok(Outcome::Ok(Usage {
472475 spent_micros: totals.spent.unwrap_or_default(),
476+ covered_micros: totals.covered.unwrap_or_default(),
473477 cost_micros: totals.cost.unwrap_or_default(),
474478 provider_micros: totals.provider.unwrap_or_default(),
475479 used_micros: totals.cost.unwrap_or_default() + totals.provider.unwrap_or_default(),