Skip to content

g1t/packages/contracts/src/billing.ts

1,575 lines62,455 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1import type { ComputeKind, Reservation } from "./compute";
Agents as a team: lifecycle, merge queue, billing and a new shell2import type { User, Viewer } from "./identity";
3import type { RepoPath } from "./repos";
4import type { Result } from "./result";
5
6/** Millionths of a US dollar in one dollar: the unit money is held in. */
7export const MICROS_PER_DOLLAR = 1_000_000;
8
9/** Whether workspaces are charged for agents at all, and with real money. */
10export type BillingStatus = {
11 /**
12 * False when no card processor is configured: nothing is charged, and who
13 * may run agents is decided some other way.
14 */
15 enabled: boolean;
16 /** False while the card processor is in its test mode, where cards are not real. */
17 live: boolean;
Free while g1t is being built out; agents can check out their own forks18 /**
19 * True while g1t is being built out: runs are recorded with what they
20 * cost, but nothing is charged and no credit is needed. Not forever.
21 */
22 free?: boolean;
Agents as a team: lifecycle, merge queue, billing and a new shell23};
24
25/** A workspace's standing. */
26export type BillingAccount = {
27 workspace: string;
28 /**
29 * Credit left, in millionths of a dollar. Can dip below zero by the cost
30 * of the runs that were under way when it ran out.
31 */
32 balanceMicros: number;
33 status: BillingStatus;
34 /** What is added to a run's cost, in percent. */
35 marginPercent: number;
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace36 /** The card charged near the limit and when a month closes, if one is saved. */
37 card?: { brand: string; last4: string; expMonth: number; expYear: number } | null;
Agents as a team: lifecycle, merge queue, billing and a new shell38};
39
40/** One line of a workspace's statement. */
41export type LedgerEntry = {
42 id: string;
43 /** Credit bought with a card, or an agent's run. */
44 kind: "top_up" | "usage";
45 /** Positive for credit added, negative for usage. */
46 amountMicros: number;
47 description: string;
48 /** For usage: the repository and pull request the agent worked on. */
49 repo: string | null;
50 number: number | null;
51 /** For usage: `implement`, `review` or `update`. */
52 task: string | null;
53 /** For usage: the model, by its public name. */
54 model: string | null;
Integrations: your own model provider, alerts that open issues, tickets agents read55 /** For usage: who paid the model provider. */
56 billedTo: "g1t" | "workspace";
Agents as a team: lifecycle, merge queue, billing and a new shell57 /** For a top-up: the username of whoever paid. */
58 createdBy: string | null;
59 /** RFC 3339. */
60 createdAt: string;
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace61 /** The workspace the line belongs to, which tells an enterprise's lines apart. */
62 workspace?: string | null;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look63 /** For usage: what the plan's included usage paid of it. `amountMicros` is what is left to pay. */
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put64 creditMicros?: number;
65 /** For usage: what the workspace's trial credit paid of it. */
66 trialMicros?: number;
67 /** For usage: what g1t's open-source pool paid of it. */
68 ossMicros?: number;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look69 /** For usage: what g1t covered itself, such as a trial's last run past its credit. */
70 givenMicros?: number;
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging71 /** For usage: what the account's discount took off its price. */
72 discountMicros?: number;
73 /** For a credit from g1t, and for what of one expired or was revoked: its kind. */
74 creditKind?: CreditKind;
Agents as a team: lifecycle, merge queue, billing and a new shell75};
76
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging77/**
78 * Why g1t gave a workspace credit. Promotional (a welcome, a referral) and
79 * goodwill (an apology) are given away when spent; a refund gives back
80 * money already paid, and never expires.
81 */
82export type CreditKind = "promotional" | "goodwill" | "refund" | "purchased";
83
84/** One credit g1t gave, with what of it was used: spent before anything paid in advance, the soonest-expiring first. */
85export type CreditGrant = {
86 /** `crd_…`, the grant's ledger reference. */
87 id: string;
88 workspace: string;
89 kind: CreditKind;
90 amountMicros: number;
91 usedMicros: number;
92 /** What can still be spent: nothing once it expired or was revoked. */
93 leftMicros: number;
94 note: string;
95 /** A refund: what it refunds, and the day of it. */
96 refundFor?: string | null;
97 refundDay?: string | null;
98 /** RFC 3339; null never expires. */
99 expiresAt: string | null;
100 createdBy: string;
101 createdAt: string;
102 state: "open" | "used" | "expired" | "revoked";
103 closedAt?: string | null;
104 closedNote?: string | null;
105 closedBy?: string | null;
106 /** What expiring or revoking took off the balance. */
107 closedMicros?: number;
108 /** What it pays for: all usage, or models only (spent first). */
109 scope?: "all" | "models";
110 /** Where it came from. */
Usage, Billing settings and prepaid AI credit; fixes from the UX audit111 source?: "staff" | "purchase" | "promo_code" | "upgrade";
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging112};
113
114/** A workspace's credits from g1t, newest first. */
115export type Credits = { grants: CreditGrant[]; leftMicros: number };
116
117/** One month's credits of one kind: given, spent that month, and taken back unused. */
118export type CreditMonth = {
119 month: string;
120 kind: CreditKind;
121 givenMicros: number;
122 grants: number;
123 usedMicros: number;
124 expiredMicros: number;
125 revokedMicros: number;
126};
127
128/** Every credit g1t gave (at most 200, filtered), the last 12 months by kind, and who gave them. */
129export type AdminCredits = { grants: CreditGrant[]; months: CreditMonth[]; staff: string[] };
130
131/** What a credit from sudo is, past its amount and note. */
132export type CreditOptions = {
133 kind: CreditKind;
134 /** RFC 3339; never for a refund. */
135 expiresAt?: string | null;
136 /** A refund: what it is for, and the day refunded (`YYYY-MM-DD`). */
137 refundFor?: string | null;
138 refundDay?: string | null;
139};
140
Agents as a team: lifecycle, merge queue, billing and a new shell141/** What lets a sandbox, and nothing else, report what its run cost. */
142export type RunTicket = { runId: string; token: string };
143
144/**
145 * What agents cost, charged to the workspace they worked for. A workspace
146 * buys credit; each run deducts its cost plus g1t's margin; with no credit,
147 * no agent starts.
148 */
A free allowance on g1t's models, so anyone can try its agents149/**
150 * The free allowance on g1t's hosted models for a workspace not otherwise
151 * open to them: a few dollars of model cost each, out of one pool, until a
152 * date. Mirrors `Trial` in `crates/contracts/src/billing.rs`.
153 */
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging154/**
155 * How an account is charged. Standard unless g1t set otherwise in sudo:
156 * custom terms are a discount (0 to 100%), a ceiling, or both. A 100%
157 * discount charges nothing and shows the usage at its price. `comped` is
158 * from before discounts and reads as 100%; billing no longer writes it.
159 */
Billing accounts, terms and enterprises; g1t is no longer free160export type Terms = {
161 kind: "standard" | "comped" | "custom";
162 discountPercent: number;
163 ceilingMicros: number | null;
164 note: string;
165 until: string | null;
166 setBy: string | null;
167 setAt: string | null;
168};
169
170/**
171 * Who pays: a workspace's own account, or an enterprise's, which pays for
172 * several workspaces with one bill and one limit.
173 */
174export type PayingAccount = {
175 id: string;
176 kind: "workspace" | "enterprise";
177 name: string;
178 terms: Terms;
179 workspaces: string[];
Stripe webhooks, enterprise invoices, and sudo for both180 /** Where an enterprise's invoices go. */
181 billingEmail?: string | null;
182 /** An enterprise's invoices, newest first. */
183 invoices?: EnterpriseInvoice[];
Billing accounts, terms and enterprises; g1t is no longer free184 createdAt: string;
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put185 /** What g1t staff set for the account beyond its terms. */
186 allowances?: Allowances;
187};
188
189/** Set per account by g1t staff in sudo, on top of its terms. */
190export type Allowances = {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look191 /** The g1t plan without its monthly price; usage is charged as usual. Comped accounts have it anyway. */
192 plan: boolean;
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put193 /** Each public repository's monthly cap on g1t's open-source pool; null for the default. */
194 ossRepoMicros: number | null;
195 /** Each workspace's trial credit, outside the monthly pool; null for the default. */
196 trialMicros: number | null;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look197 /** Agents at once, in place of the plan's (2 in the first month or on the trial, then 10); null for the default. */
198 maxConcurrentAgents?: number | null;
199 /** One run's spend cap, in place of the owners' and the default $2; null for none. */
200 runCapMicros?: number | null;
201 /** What one issue's agents may spend in all, in place of the owners' and the default $10; null for none. */
202 issueCapMicros?: number | null;
Audit logs are kept by plan: a week on free, 90 days on the plan, and what staff set for an account in sudo203 /** Days of audit log its workspaces keep, in place of the plan's (7 free, 90 on the plan), longer or shorter; null for the plan's. */
204 auditRetentionDays?: number | null;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look205 /** A hold on new compute, with why; null for none. */
206 hold?: string | null;
Billing accounts, terms and enterprises; g1t is no longer free207};
208
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look209// --- Entitlements, and compute started under a reservation ------------------
210//
211// Every service that starts compute asks billing first:
212// 1. `entitlements(workspace)`: what it may do at all, its caps, and whether compute is paused.
213// 2. `reserve(...)`: holds the estimate against what may pay for it, so starts at the same moment
214// cannot overshoot together. Answers who pays first, or refuses with a stable code
215// (`not_paid`, `trial_used`, `limit`, `paused`, `oss_pool_empty`) and a message for the owner.
216// 3. `settle(reservationId, actualMicros)`: releases the hold. The charge goes on the ledger the usual way.
217// A reservation never settled lapses after `RESERVATION_HOURS`.
218
219/** A reservation that is never settled stops holding after this long. */
220export const RESERVATION_HOURS = 3;
221/** What a ceiling reads as when there is none (g1t's own workspaces). */
222export const UNLIMITED_MICROS = 1_000_000_000_000_000;
223
224/** What a workspace pays g1t on, as far as compute is concerned. Mirrors `PlanKind`. */
225export type PlanKind = "free" | "paid" | "internal" | "enterprise";
226
227// `ComputeKind` (what compute is for), `PaidBy` (who pays first: credit, trial, oss, on_demand) and
228// `Reservation` are in `./compute`, with the gate that calls `reserve` and `settle`.
229
230/** One level reached: 50, 75, 90 or 100 percent. */
231export type UsageAlert = {
232 /** `included` (the plan's included usage), `spend_limit` or `ceiling`. */
233 meter: "included" | "spend_limit" | "ceiling" | string;
234 level: number;
235 usedMicros: number;
236 limitMicros: number;
237 message: string;
238};
239
240/** An hour's spend well above the workspace's usual: new compute waits for an owner. */
241export type Spike = {
242 id: string;
243 /** `open` (waiting), `continued` (keep going) or `stopped`. */
244 status: "open" | "continued" | "stopped" | string;
245 hourMicros: number;
246 averageMicros: number;
247 detectedAt: string;
248 decidedBy?: string | null;
249 decidedAt?: string | null;
250 /** While continued: until when, unless spend doubles again first. */
251 until?: string | null;
252};
253
254/** What a workspace may do now. Mirrors `Entitlements` in `crates/contracts/src/billing.rs`. */
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put255export type Entitlements = {
256 workspace: string;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look257 plan: PlanKind;
258 /** May start sandboxes, models, deployments and semantic search at all: paid, internal, enterprise, or free with trial credit left. */
259 compute: boolean;
260 /** The one-time trial credit left; 0 if none or used. */
261 trialMicrosLeft: number;
262 /** A card check has been done; the trial and the open-source pool need it. */
263 trialVerified: boolean;
264 /** A paid workspace still in its first billing cycle. */
265 firstMonth: boolean;
266 /** 2 in the first month or on the trial, 10 after; staff can override it. */
267 maxConcurrentAgents: number;
268 /** 60 in the first month or on the trial; otherwise the guardrails' own caps. */
269 maxRunMinutes: number;
270 /** One run's spend cap, $2 by default; staff can override it. */
271 runCapMicros: number;
272 /** Agent spend on one issue in all, $10 by default. */
273 issueCapMicros: number;
274 /** g1t's ceiling on usage not yet paid for; `UNLIMITED_MICROS` for g1t's own; 0 for free. */
275 ceilingMicros: number;
276 /** Usage not yet paid for this month, prepayment taken off. */
277 exposureMicros: number;
278 /** Why new compute is paused, for the owner; null when it is not. */
279 paused: string | null;
280 /** What open reservations hold now. */
281 heldMicros?: number;
282 /** Paid in advance and not used yet. */
283 prepaidMicros?: number;
284 /** The plan's included usage each month, and what of it is used. */
285 includedMicros?: number;
286 includedUsedMicros?: number;
Audit logs are kept by plan: a week on free, 90 days on the plan, and what staff set for an account in sudo287 /** How far back the audit log can be read and exported, and what is kept: the plan's days, or what g1t staff set for the account. */
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put288 auditRetentionDays: number;
Audit logs are kept by plan: a week on free, 90 days on the plan, and what staff set for an account in sudo289 /** Whether `auditRetentionDays` is what staff set for the account rather than the plan's. */
290 auditRetentionCustom?: boolean;
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas291 /** Private repository storage free for every workspace: past it, the plan pays and a free workspace's pushes stop. */
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put292 freePrivateStorageBytes: number;
293 /** The last daily measure of the workspace's private repositories (a lower bound). */
294 privateStorageBytes: number;
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member295 /** On a paid plan: package storage past the free amounts is charged, never refused. */
296 hasPlan?: boolean;
297 /** Package storage free for every workspace (public, and private): past it a free workspace's pushes are refused. */
298 packagePublicFreeBytes?: number;
299 packagePrivateFreeBytes?: number;
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put300 /** What g1t's open-source pool paid for the workspace this month. */
301 ossPaidMicros: number;
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas302 /** Deploy build time this month, every second of it metered. */
303 buildSecondsUsed?: number;
304 /** Git operations this month, and how many are free for every workspace. */
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look305 gitOperations?: number;
306 gitOperationsIncluded?: number;
307 /** The smallest amount a card is charged when a month closes. */
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put308 minChargeMicros: number;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look309 /** A spend spike waiting for an owner, or decided. */
310 spike?: Spike | null;
311 /** Where usage stands against what is included and the limits, from 50%. */
312 alerts?: UsageAlert[];
313};
314
315/** A hold on a start's estimated cost, as billing answers it (`Reservation` in `./compute`, and more). */
316export type ReservationHeld = Reservation & {
317 /** What is held, at cost; may be less than the estimate for a free workspace's last bit of trial. */
318 heldMicros?: number;
319 /** When the hold lapses if never settled. */
320 expiresAt?: string;
321};
322
323/** A request to g1t: a higher limit, or help with usage past what was meant. */
324export type LimitRequest = {
325 id: string;
326 workspace: string;
327 kind: "limit" | "overage" | string;
328 amountMicros: number;
329 reason: string;
330 expectedMonthlyMicros: number;
331 status: "open" | "approved" | "declined" | string;
332 decidedMicros?: number | null;
333 decidedBy?: string | null;
334 /** The answer, as the owner sees it. */
335 answer?: string | null;
336 createdBy: string;
337 createdAt: string;
338 decidedAt?: string | null;
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put339};
340
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look341/** What staff see beside a request. */
342export type WorkspaceHistory = {
343 plan: PlanKind | null;
344 months: MonthFigures[];
345 paidClearedMicros: number;
346 payments: number;
347 disputes: number;
348 declines: number;
349 firstSeen: string | null;
350 ceilingMicros: number | null;
351 maxCeilingMicros: number | null;
352 spendLimitMicros: number | null;
353 lastHourMicros: number;
354 averageHourMicros: number;
355 lastDayMicros: number;
356};
357
358export type LimitRequestReview = { request: LimitRequest; history: WorkspaceHistory };
359
360/** What a one-time goodwill credit comes to: the margin on the overage, always, plus its cost up to the cap. */
361export type Goodwill = {
362 overageMicros: number;
363 marginMicros: number;
364 costMicros: number;
365 creditMicros: number;
366 absorbedMicros: number;
367};
368
369/** A workspace whose month went well past its usual, or hit a spike. */
370export type Overage = {
371 workspace: string;
372 plan: PlanKind;
373 typicalMonthMicros: number;
374 thisMonthMicros: number;
375 costMicros: number;
376 marginMicros: number;
377 spike: Spike | null;
378 topEntries: LedgerEntry[];
379 goodwill: Goodwill;
380 goodwillAvailable: boolean;
381 lastGoodwillAt: string | null;
382 request: LimitRequest | null;
383};
384
385/** One workspace's recent pace. */
386export type Velocity = {
387 workspace: string;
388 plan: PlanKind;
389 lastHourMicros: number;
390 averageHourMicros: number;
391 lastDayMicros: number;
392 thisMonthMicros: number;
393 ratio: number;
394 spike: Spike | null;
395 firstSeen: string | null;
396};
397
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put398/** g1t's capped budgets for free usage this month. */
399export type Pools = {
400 month: string;
401 trialGrantedMicros: number;
402 trialPoolMicros: number;
403 trialGrants: number;
404 ossUsedMicros: number;
405 ossPoolMicros: number;
406 ossRepoMicros: number;
407};
408
Billing accounts, terms and enterprises; g1t is no longer free409export type AccountSummary = {
410 account: PayingAccount;
411 limit: Limit;
412 chargedMicros: number;
413 costMicros: number;
414 paidMicros: number;
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace415 /** The same figures for each of the account's workspaces that has any. */
416 byWorkspace: WorkspaceFigures[];
Two limits, real invoices, trust that grows by itself, sales signals417 /** The last six months, oldest first. */
418 months?: MonthFigures[];
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace419};
420
421/** One workspace's share of an `AccountSummary`. */
422export type WorkspaceFigures = { workspace: string; chargedMicros: number; costMicros: number; paidMicros: number };
423
Stripe webhooks, enterprise invoices, and sudo for both424export type StripeStatus = {
425 /** `test` or `live`, from the key; `off` without one. */
426 mode: "test" | "live" | "off" | string;
Stripe's webhook secret is a Worker secret, STRIPE_WEBHOOK_SECRET, from a destination made in Stripe's dashboard427 /** Whether `STRIPE_WEBHOOK_SECRET` is set, so events can be checked. */
428 secretSet: boolean;
429 /** The destination at billing's address in Stripe, as Stripe has it. */
430 webhook: { url: string; endpointId: string; status: "enabled" | "disabled" | string; events: string[]; createdAt: string } | null;
431 /** Events billing handles that the destination does not send. */
432 missingEvents: string[];
Stripe webhooks, enterprise invoices, and sudo for both433 recentEvents: { id: string; kind: string; outcome: string; receivedAt: string }[];
434 error: string | null;
435};
436
437/** An enterprise's invoice: one line per workspace, paid on Stripe's page. */
438export type EnterpriseInvoice = {
439 invoiceId: string;
440 hostedUrl: string | null;
441 amountMicros: number;
442 status: "open" | "paid" | "overdue" | "void" | string;
443 period: string;
444 lines: { workspace: string; amountMicros: number }[];
445 createdAt: string;
446};
447
Two limits, real invoices, trust that grows by itself, sales signals448/** A workspace's invoice: monthly, or when charged near its limit. Itemised, in Stripe's billing page. */
449export type WorkspaceInvoice = {
450 invoiceId: string;
451 workspace: string;
452 reason: "month" | "threshold" | string;
453 period: string;
454 amountMicros: number;
455 status: "paid" | "open" | "failed" | "void" | string;
456 hostedUrl: string | null;
457 pdfUrl: string | null;
458 lines: { description: string; amountMicros: number }[];
459 createdAt: string;
460};
461
The statement is a month at a time, a line per kind of charge462/** A month of the ledger, grouped by day or project, a line per kind of charge. */
463export type Statement = {
464 month: string;
465 months: string[];
466 groups: {
467 key: string;
468 label: string;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look469 /** `coveredMicros`: what the plan's included usage, the trial, the open-source pool or g1t paid, not in `chargedMicros`. */
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging470 /** `priceMicros`: usage at its price; `discountMicros`: what the account's discount took off it. */
471 lines: {
472 kind: string;
473 count: number;
474 chargedMicros: number;
475 costMicros: number;
476 coveredMicros?: number;
477 priceMicros?: number;
478 discountMicros?: number;
479 }[];
The statement is a month at a time, a line per kind of charge480 chargedMicros: number;
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging481 priceMicros?: number;
482 discountMicros?: number;
The statement is a month at a time, a line per kind of charge483 }[];
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put484 totals: {
485 chargedMicros: number;
486 paidMicros: number;
487 costMicros: number;
488 entries: number;
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging489 /** Usage at price, and what the discount took off: charged is the price less the discount and what paid for it. */
490 priceMicros?: number;
491 discountMicros?: number;
492 /** The account's discount now, in percent; absent without one. */
493 discountPercent?: number | null;
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put494 /** What paid for usage before it was charged, such as "Paid by g1t's open-source pool". */
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look495 covered?: { source: "included" | "trial" | "oss_pool" | "given" | string; label: string; micros: number }[];
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put496 /** Owed when the month closed but under the minimum charge: on the next invoice. */
497 carriedMicros?: number;
498 };
The statement is a month at a time, a line per kind of charge499};
500
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look501export type MonthFigures = {
502 month: string;
503 /** Usage charged, after what paid for it first. */
504 chargedMicros: number;
505 /** What usage cost g1t: never a workspace's own model provider. */
506 costMicros: number;
507 paidMicros: number;
508 /** The plan's monthly price, paid. */
509 plansMicros?: number;
510 /** What g1t gave at price (internal use, trials, the open-source pool, goodwill, covered). Not margin. */
511 givenMicros?: number;
512};
513
514/** What g1t gave this month from one source. */
515export type GivenFigures = { source: "internal" | "trial" | "oss_pool" | "goodwill" | "covered" | string; label: string; micros: number; costMicros: number };
516
517/** One internal workspace's use this month, and why it is not charged. */
518export type InternalUse = { workspace: string; reason: string; costMicros: number; entries: number };
Two limits, real invoices, trust that grows by itself, sales signals519
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily520export type SignalKind = "at_limit" | "near_ceiling" | "declined" | "growing" | "established" | "first_payment" | "high_spend" | "cost_over_revenue";
Two limits, real invoices, trust that grows by itself, sales signals521
522/** Why a workspace is worth reaching out to. */
523export type Signal = {
524 workspace: string;
525 kind: SignalKind;
526 detail: string;
527 valueMicros: number;
528 stage: string | null;
529 owner: string | null;
Billing lists every invoice and every staff change; signals carry follow-ups530 nextStep?: string | null;
531 /** When the next step is due, YYYY-MM-DD. */
532 nextAt?: string | null;
533};
534
535/** One invoice g1t has sent, a workspace's or an enterprise's. */
536export type InvoiceSummary = {
537 invoiceId: string;
538 kind: "workspace" | "enterprise";
539 account: string;
540 name: string;
541 reason: string;
542 period: string;
543 amountMicros: number;
544 status: string;
545 hostedUrl: string | null;
546 createdAt: string;
547 paidAt: string | null;
Two limits, real invoices, trust that grows by itself, sales signals548};
549
550export type SalesStage = "none" | "lead" | "contacted" | "negotiating" | "won" | "lost" | "churn_risk";
551
552export type SalesRecord = {
553 workspace: string;
554 stage: SalesStage | string;
555 owner: string | null;
556 nextStep: string | null;
557 nextAt: string | null;
558 notes: { id: string; text: string; by: string; createdAt: string }[];
559 updatedAt: string | null;
560};
561
562export type Overview = {
563 month: string;
564 months: MonthFigures[];
565 byKind: { kind: string; chargedMicros: number; costMicros: number }[];
566 payingWorkspaces: number;
567 stopped: number;
568 nearCeiling: number;
569 declined: number;
570 openInvoicesMicros: number;
571 followUpsDue: number;
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put572 /** g1t's capped budgets for free usage, this month. */
573 pools?: Pools | null;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look574 /** Usage charged plus the plan's price paid, this month. */
575 revenueMicros?: number;
576 activePlans?: number;
577 planMrrMicros?: number;
578 /** What g1t gave this month, by source, apart from its margin. */
579 given?: GivenFigures[];
580 /** g1t's own and Flagon's workspaces: what their use cost, and why they are not charged. */
581 internal?: InternalUse[];
582 openRequests?: number;
583 overages?: number;
584 openSpikes?: number;
Two limits, real invoices, trust that grows by itself, sales signals585};
586
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace587/** A customer's Stripe billing page, for staff to send them. */
588export type BillingLink = {
589 /** One-time and short-lived, signed in already. */
590 portalUrl: string;
591 /** The page's sign-in, which does not expire: the customer signs in by email. */
592 loginUrl: string | null;
593 customerEmail: string | null;
594 expiresNote: string;
Billing accounts, terms and enterprises; g1t is no longer free595};
596
597export type AdminAction = { id: string; account: string; action: string; detail: string; by: string; createdAt: string };
598
599export type AccountDetail = {
600 summary: AccountSummary;
601 workspaces: Limit[];
602 ledger: LedgerEntry[];
603 audit: AdminAction[];
604};
605
606/** Staff-only billing, for sudo.g1t.sh. Every change names who made it. */
607export interface BillingAdminApi {
608 accounts(query?: string): Promise<AccountSummary[]>;
609 account(id: string): Promise<Result<AccountDetail>>;
610 setTerms(id: string, terms: Terms, by: string): Promise<Result<PayingAccount>>;
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put611 /** Team on or off without charge, and the account's share of the pools. Needs a note. */
612 setAllowances(id: string, allowances: Allowances, note: string, by: string): Promise<Result<PayingAccount>>;
Billing accounts, terms and enterprises; g1t is no longer free613 createEnterprise(name: string, workspaces: string[], by: string): Promise<Result<PayingAccount>>;
614 attach(workspace: string, account: string | null, by: string): Promise<Result<PayingAccount>>;
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging615 /** Credit for a workspace: promotional, goodwill or a refund; the owners are emailed. */
616 credit(workspace: string, amountMicros: number, note: string, by: string, options?: CreditOptions): Promise<Result<LedgerEntry>>;
617 /** Every credit g1t gave, filtered, with each month's totals by kind. */
618 credits(filter?: { workspace?: string | null; kind?: CreditKind | null; month?: string | null; by?: string | null }): Promise<AdminCredits>;
619 /** What is left of a credit, taken back, with why. */
620 revokeCredit(id: string, note: string, by: string): Promise<Result<CreditGrant>>;
sudo: reset a test workspace's billing so it starts again as a new customer; refused on a live Stripe key, for comped workspaces and for an enterprise's621 /** A test workspace's billing wiped, to start again as a new customer. Only on Stripe's test key; never comped or enterprise. Logged. */
622 resetBilling(workspace: string, confirm: string, note: string, by: string): Promise<Result<BillingReset>>;
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace623 /** The workspace's Stripe billing page, to send to the customer. Logged. */
624 billingLink(workspace: string, by: string): Promise<Result<BillingLink>>;
Stripe webhooks, enterprise invoices, and sudo for both625 /** Where billing stands with Stripe; with `setup`, registers the webhook first. */
Stripe's webhook secret is a Worker secret, STRIPE_WEBHOOK_SECRET, from a destination made in Stripe's dashboard626 /** Stripe's state for billing; `fix` enables the destination and adds missing events first. */
627 stripe(fix?: boolean, by?: string): Promise<StripeStatus>;
Stripe webhooks, enterprise invoices, and sudo for both628 /** Where an enterprise's invoices go; makes its Stripe customer. */
629 enterpriseBilling(id: string, email: string, by: string): Promise<Result<PayingAccount>>;
630 /** Sends an enterprise its invoice now, for what its workspaces owe. */
631 invoiceEnterprise(id: string, by: string): Promise<Result<EnterpriseInvoice>>;
632 /** Exactly these workspaces' accounts, such as one page of the list. */
633 accountsFor(workspaces: string[]): Promise<AccountSummary[]>;
Two limits, real invoices, trust that grows by itself, sales signals634 /** Every workspace worth reaching out to, most urgent first. */
635 signals(): Promise<Signal[]>;
636 /** The business at a glance. */
637 overview(): Promise<Overview>;
638 /** A workspace's sales record. */
639 sales(workspace: string): Promise<SalesRecord>;
640 setSales(workspace: string, record: { stage: string; owner?: string | null; nextStep?: string | null; nextAt?: string | null }, by: string): Promise<Result<SalesRecord>>;
641 addNote(workspace: string, text: string, by: string): Promise<Result<SalesRecord>>;
642 /** A workspace's invoices from g1t, for staff. */
643 workspaceInvoices(workspace: string): Promise<WorkspaceInvoice[]>;
Billing lists every invoice and every staff change; signals carry follow-ups644 /** Every invoice g1t has sent, newest first. */
645 allInvoices(filter?: { status?: string; month?: string }): Promise<InvoiceSummary[]>;
646 /** Every change made in sudo and by Stripe, newest first, 100 at a time. */
647 audit(filter?: { by?: string; action?: string; before?: string }): Promise<AdminAction[]>;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look648 /** Limit and overage requests, with each workspace's history; `open` by default. */
649 limitRequests(status?: "open" | "approved" | "declined" | "all"): Promise<LimitRequestReview[]>;
650 /** Approve (at the amount asked, or another) or decline; the owner is told in the app and by email. */
651 decideLimitRequest(id: string, decision: "approve" | "decline", amountMicros: number | null, note: string, by: string): Promise<Result<LimitRequest>>;
652 /** The Overages queue. */
653 overages(): Promise<Overage[]>;
654 /** A goodwill credit; no amount is the one-click credit. Larger, or a second in 12 months, needs a reason. */
655 goodwill(workspace: string, amountMicros: number | null, reason: string, by: string, day?: string | null): Promise<Result<LedgerEntry>>;
656 /** Workspaces spending in the last day, fastest first. */
657 velocity(): Promise<Velocity[]>;
658 /** Money that reached g1t outside the card pages, such as a bank transfer: entered as a payment. */
659 recordPayment(workspace: string, amountMicros: number, reference: string, note: string, by: string): Promise<Result<LedgerEntry>>;
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily660 /** Costs & margin: Cloudflare's bill against what g1t charged, over the last `days` (7 to 90, 30 by default). */
661 costs(days?: number): Promise<CostsReport>;
662 /** The open margin alerts, for the banner on every page. */
663 costAlerts(): Promise<MarginAlert[]>;
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays664 /** g1t's own spend against its caps: the daily breaker and comped budgets. */
665 spendCaps(): Promise<SpendCaps>;
666 /** Lets hosted-model runs start again for the rest of today (UTC); needs a note. */
667 liftBreaker(note: string, by: string): Promise<Result<SpendCaps>>;
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily668 /** Approve or reject a price proposal; a rejection needs a note. An approved rise waits out the notice period. */
669 decideProposal(id: string, decision: "approve" | "reject", note: string, by: string): Promise<Result<PriceProposal>>;
670 setCostSettings(settings: CostSettings, by: string): Promise<Result<CostSettings>>;
671 setCostMapping(mapping: CostMappingInput, by: string): Promise<Result<CostMapping>>;
672 /** Reads Cloudflare's bill and reconciles now, as the daily run does. */
673 runCosts(by: string): Promise<Result<CostsRun>>;
Billing accounts, terms and enterprises; g1t is no longer free674}
675
Usage limits: unpaid usage can only go so far676/** How much a workspace has earned g1t's trust with money. */
Two limits, real invoices, trust that grows by itself, sales signals677export type Trust = "new" | "paid" | "established" | "reviewed" | "internal";
Usage limits: unpaid usage can only go so far678
679/**
680 * How far a workspace's unpaid usage has gone this month, and where its
681 * work stops: past `ceilingMicros`, no new sandboxes, builds or app
682 * requests. Usage counts at its cost to g1t or its charge, whichever is
683 * more, so it counts while g1t is free too.
684 */
685export type Limit = {
686 workspace: string;
Billing accounts, terms and enterprises; g1t is no longer free687 /** The account that pays: the workspace's own (`ws_<slug>`), or its enterprise's. */
688 account: string;
689 accountName: string;
Usage limits: unpaid usage can only go so far690 trust: Trust;
691 exposureMicros: number;
692 /** The lower of g1t's ceiling and the owner's spend limit; null for g1t's own. */
693 ceilingMicros: number | null;
694 trustCeilingMicros: number | null;
695 spendLimitMicros: number | null;
696 state: "ok" | "warning" | "stopped";
697 message: string | null;
Two limits, real invoices, trust that grows by itself, sales signals698 /** Charged this month: what the spend limit is measured against. */
699 spentMicros?: number;
700 /** True while the owners have not chosen a limit, so the automatic one applies: $200, or twice last month's spend. */
701 defaultSpendLimit?: boolean;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look702 /** The most owners may set their own limit to without asking: the highest ceiling ever, plus what is prepaid. */
Two limits, real invoices, trust that grows by itself, sales signals703 availableMicros?: number | null;
704 /** How the ceiling grows from here, in a sentence. */
705 growth?: string | null;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look706 /** Paid in advance and not used yet; raises what can be used before work stops by as much. */
707 prepaidMicros?: number;
708 /** The highest ceiling the workspace has had. */
709 maxCeilingMicros?: number | null;
710 /** The most owners may raise the limit to themselves, once: twice the highest ceiling. Null once used. */
711 raiseOnceMicros?: number | null;
712 /** When the one-time raise was used. */
713 raisedAt?: string | null;
714 /** A paid workspace's first billing cycle, on the starting ceiling. */
715 firstMonth?: boolean;
Usage, Billing settings and prepaid AI credit; fixes from the UX audit716 /** The budget's alerts, in percent of the spend limit: some of 50, 75, 90 and 100. */
717 alertLevels?: number[];
718 /** Whether usage pauses at the spend limit (the default); off, it only alerts. */
719 pauseAtLimit?: boolean;
720 /** An HTTPS address told of each budget alert. */
721 budgetWebhook?: string | null;
Usage limits: unpaid usage can only go so far722};
723
Prices keep themselves current with what g1t pays724/** One metered unit: what it costs g1t and what it is sold at; the price follows the cost. */
725export type Price = {
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put726 meter:
727 | "sandbox_second"
728 | "build_second"
729 | "app_requests"
730 | "app_cpu"
731 | "app_month"
732 | "custom_domain_month"
733 | "private_storage"
734 | "embedding_tokens"
735 | "scan_cpu"
736 | "scan_rows"
737 | string;
Prices keep themselves current with what g1t pays738 title: string;
739 unit: string;
740 costMicros: number;
741 markupPercent: number;
742 priceMicros: number;
743 /** `list`: Cloudflare's published price. `cloudflare`: measured from Cloudflare's bill. */
744 source: "list" | "cloudflare" | string;
745 checkedAt: string | null;
746 updatedAt: string;
747};
748
749export type PriceChange = {
750 meter: string;
751 oldCostMicros: number;
752 newCostMicros: number;
753 markupPercent: number;
Prices are what g1t pays plus 20%, from the first second754 /** The markup before, when the change was to the markup rather than the cost. */
755 oldMarkupPercent?: number;
Prices keep themselves current with what g1t pays756 reason: string;
757 createdAt: string;
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily758 /** When a change still to come takes effect: a rise is announced before it is charged. */
759 effectiveAt?: string;
Prices keep themselves current with what g1t pays760};
761
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put762export type PriceBook = {
763 prices: Price[];
764 changes: PriceChange[];
765 modelMarginPercent: number;
766 /** Every plan, as sold now. */
767 plans?: FeaturePlan[];
768 /** What is free, and the capped budgets that pay for it. */
769 free?: FreeTier | null;
770};
Prices keep themselves current with what g1t pays771
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas772/** One kind of meter's usage this month, from `usage_meters`. */
773export type MeterUsage = {
774 /** `agents`, `builds`, `requests`, `domains`, `git_storage` or `search_scans`. */
775 key: string;
776 label: string;
777 /** At price (cost plus 20%, on the account's terms), before what paid for it. */
778 micros: number;
779 /** How much, when it is known: `12 runs`, `41 build minutes`. */
780 quantity?: string | null;
781};
782
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put783/** What g1t gives without a plan; each is paid for by a capped budget. */
784export type FreeTier = {
785 /** Each new workspace's trial credit, once. */
786 trialWorkspaceMicros: number;
787 /** Trial grants each month, in all; new trials wait when it is spent. */
788 trialMonthlyPoolMicros: number;
789 /** g1t's open-source pool each month, and any one repository's share. */
790 ossPoolMicros: number;
791 ossRepoMicros: number;
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas792 /** Private repository storage free for every workspace. Past it, the plan pays; a free workspace's pushes stop. */
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put793 freePrivateStorageBytes: number;
Audit logs are kept by plan: a week on free, 90 days on the plan, and what staff set for an account in sudo794 /** Days of audit log a free workspace keeps. */
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put795 auditRetentionDays: number;
Audit logs are kept by plan: a week on free, 90 days on the plan, and what staff set for an account in sudo796 /** Days of audit log the g1t plan keeps, and g1t's own and enterprise workspaces; longer by arrangement. */
797 planAuditRetentionDays?: number;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look798 /** The smallest amount a card is charged when a month closes; less carries over. */
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put799 minChargeMicros: number;
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas800 /** Git operations free for every workspace each month. Past it, the plan pays; a free workspace is slowed down. */
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look801 gitOperationsIncluded?: number;
802 /** A new paid workspace's ceiling in its first month. */
803 paidStartCeilingMicros?: number;
804 /** The most a one-click goodwill credit can cost g1t. */
805 overageForgiveCostMicros?: number;
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put806};
807
808/**
809 * A workspace's trial credit: one grant per workspace, made the first time
810 * it uses something, out of a pool that resets each calendar month. Mirrors
811 * `Trial` in `crates/contracts/src/billing.rs`.
812 */
A free allowance on g1t's models, so anyone can try its agents813export type Trial = {
814 open: boolean;
815 usedMicros: number;
816 limitMicros: number;
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put817 /** No longer used: trials do not end on a date. */
A free allowance on g1t's models, so anyone can try its agents818 endsAt: string | null;
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put819 /** Why it is closed: `off`, `used` (this workspace's grant is spent) or `pool` (this month's are given out). */
A free allowance on g1t's models, so anyone can try its agents820 reason: "off" | "ended" | "used" | "pool" | null;
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put821 /** Whether the workspace has its grant already. */
822 granted?: boolean;
823 /** With `pool`: when new trials start again, the first of next month. */
824 waitsUntil?: string | null;
A free allowance on g1t's models, so anyone can try its agents825};
826
Paid features: a workspace turns on Deployments with a monthly plan827/**
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar828 * What a workspace pays a monthly price for: the g1t plan (`plan`), and the
829 * Security and quality activation (`security`), sold on its own. Deployments
830 * are part of the plan; `has_feature` for `deployments` answers whether the
831 * workspace has the plan. Mirrors `Feature` in `crates/contracts/src/billing.rs`.
Paid features: a workspace turns on Deployments with a monthly plan832 */
Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar833export type Feature = "plan" | "deployments" | "security";
Paid features: a workspace turns on Deployments with a monthly plan834
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas835/**
836 * What deployments cost g1t, in millionths of a dollar: fallbacks for when
837 * billing's price book cannot be read. Not an allowance: on the plan every
838 * unit is metered from the first, at cost plus 20%, and drawn from the
839 * plan's included usage first. Projects, previews and the apps behind them
840 * are not metered at all. Mirrors `deployment_costs`.
841 */
842export const DEPLOYMENT_COSTS = {
Paid features: a workspace turns on Deployments with a monthly plan843 microsPerMillionRequests: 300_000,
844 microsPerMillionCpuMs: 20_000,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas845 /** One second of a build's sandbox: a fallback; billing charges the price book's `build_second`. */
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look846 microsPerBuildSecond: 15,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas847 /** One custom domain for a month. */
Agents and memory, checks and conflicts, profiles, slug renames, custom domains848 microsPerDomainMonth: 100_000,
Paid features: a workspace turns on Deployments with a monthly plan849} as const;
850
851export type FeaturePlan = {
852 feature: Feature;
853 title: string;
854 /** Charged every month while the plan is on, in cents. */
855 monthlyCents: number;
856 /** What the price includes, one line each. */
857 includes: string[];
858 /** How usage past the allowance is charged. */
859 overage: string;
860};
861
862export type SubscriptionStatus = "active" | "canceling" | "past_due" | "canceled";
863
864export type Subscription = {
865 feature: Feature;
866 status: SubscriptionStatus;
867 /** RFC 3339: when the period paid for ends. */
868 periodEnd: string | null;
869 startedBy: string;
870 startedAt: string;
871};
872
873/** A feature as a workspace sees it. */
874export type FeatureState = {
875 plan: FeaturePlan;
876 subscription: Subscription | null;
877 /** Whether the feature works for the workspace now. */
878 on: boolean;
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put879 /** On without a plan: comped terms, or given by g1t. Nothing to pay or turn off. */
880 included?: boolean;
Paid features: a workspace turns on Deployments with a monthly plan881};
882
Agents as a team: lifecycle, merge queue, billing and a new shell883export interface BillingApi {
884 status(): Promise<BillingStatus>;
885 /** Members of the workspace only. */
886 account(workspace: string, viewer: Viewer): Promise<Result<BillingAccount>>;
887 /** Newest first. Members of the workspace only. */
888 ledger(workspace: string, viewer: Viewer): Promise<Result<LedgerEntry[]>>;
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging889 /** Credits from g1t, newest first, with what is left of each. Members only. */
890 credits(workspace: string, viewer: Viewer): Promise<Result<Credits>>;
The statement is a month at a time, a line per kind of charge891 /** A month of the ledger, grouped by `day` (default) or `project`. Members only. */
892 statement(workspace: string, viewer: Viewer, month?: string | null, group?: "day" | "project"): Promise<Result<Statement>>;
893 /** One statement line's entries, 50 at a time; `before` is the last id seen. */
894 statementEntries(
895 workspace: string,
896 viewer: Viewer,
897 filter: { month: string; kind: string; day?: string | null; project?: string | null; before?: string | null },
898 ): Promise<Result<LedgerEntry[]>>;
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request899 /** What the workspace's agents cost since `since`, broken down. Members only. */
900 usage(workspace: string, viewer: Viewer, since: string): Promise<Result<Usage>>;
Agents as a team: lifecycle, merge queue, billing and a new shell901 /**
Mission control shows model usage, yours and the workspace's: tokens, cost, active days, cache share, each day, and the mix902 * The model tokens the workspace's runs used, day by day over the last
903 * `days` (42, at most 366), for everyone or for one `person`. Members
904 * only; a member may ask only for themselves, an owner for anyone.
905 */
906 tokenUsage(workspace: string, viewer: User, options?: { person?: string; days?: number }): Promise<Result<TokenUsage>>;
907 /**
908 * What one model answer used, added to its run's count for the day. The
909 * model proxy sends it; for usage views only, as runs are priced from AI
910 * Gateway. False when there was nothing to count.
911 */
912 recordTokens(usage: {
913 workspace: string;
914 /** The model session's id, one per run. */
915 session: string;
916 /** The person the run is for, by username. */
917 person?: string | null;
918 model: string;
919 tier?: "small" | "large" | null;
920 input: number;
921 output: number;
922 cacheRead: number;
923 cacheWrite: number;
924 }): Promise<Result<boolean>>;
925 /**
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look926 * Prepays usage ($25 at least) and returns the page to send the person to:
927 * by card with 3-D Secure, or by bank transfer from $1,000. Owners only.
928 * The payment's id comes back to `returnUrl` as `session`.
Agents as a team: lifecycle, merge queue, billing and a new shell929 */
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look930 checkout(
931 actor: User,
932 workspace: string,
933 amountCents: number,
934 returnUrl: string,
935 method?: "card" | "bank_transfer",
936 ): Promise<Result<{ url: string }>>;
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace937 /**
938 * Stripe's hosted billing page for the workspace: card, invoices, billing
939 * email and address. g1t never handles card numbers. Owners only.
940 */
941 billingPortal(actor: User, workspace: string, returnUrl: string): Promise<Result<{ url: string }>>;
Agents as a team: lifecycle, merge queue, billing and a new shell942 /** Credits a payment once the processor says it was made. Safe to repeat. */
943 confirm(workspace: string, viewer: Viewer, session: string): Promise<Result<BillingAccount>>;
944 /**
945 * Whether a workspace may start an agent now, asked before anything is
946 * opened for it. A failure, with the reason to show, when it has no credit.
947 */
948 canStart(workspace: string): Promise<Result<boolean>>;
A free allowance on g1t's models, so anyone can try its agents949 /** A workspace's free allowance on g1t's hosted models; `exempt` are open to them anyway. */
950 trial(workspace: string, exempt: string[]): Promise<Trial>;
Agents as a team: lifecycle, merge queue, billing and a new shell951 /**
952 * Asks whether a workspace may start an agent and opens the run it will be
953 * charged for. Null when billing is off; a failure when there is no credit.
954 */
Paid features: a workspace turns on Deployments with a monthly plan955 /** Every paid feature and the workspace's plan for each. Members only. */
956 features(workspace: string, viewer: Viewer): Promise<Result<FeatureState[]>>;
957 /**
958 * Starts the card page for a feature's monthly plan. Owners only. The
959 * page's id comes back to `returnUrl` as `session`.
960 */
961 subscribe(actor: User, workspace: string, feature: Feature, returnUrl: string): Promise<Result<{ url: string }>>;
962 /** Turns the feature on once the plan is paid for. Safe to repeat. */
963 confirmSubscription(workspace: string, viewer: Viewer, session: string): Promise<Result<FeatureState>>;
964 /** Ends a plan at the end of its period, or (`resume`) takes that back. Owners only. */
965 cancelSubscription(actor: User, workspace: string, feature: Feature, resume?: boolean): Promise<Result<FeatureState>>;
966 /** Whether a feature works for a workspace now; a failure with the reason when not. */
967 hasFeature(workspace: string, feature: Feature): Promise<Result<boolean>>;
968 /**
969 * Usage past a plan's allowance, charged from credit at cost plus the
970 * margin, once per `reference`. False if it was charged before.
971 */
972 chargeFeature(charge: {
973 workspace: string;
974 feature: Feature;
975 costMicros: number;
976 description: string;
977 repo?: string | null;
978 reference: string;
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put979 /** For a build: how long it ran, so the plan's included build time pays for what it can. */
980 buildSeconds?: number | null;
Paid features: a workspace turns on Deployments with a monthly plan981 }): Promise<Result<boolean>>;
Prices keep themselves current with what g1t pays982 /**
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put983 * What a source cost g1t so far this month, so the workspace's limit
984 * counts it now. Replaces the last report. Billing charges `context`
985 * and `security` itself once the month is over; `deployments` charges
986 * its own.
Prices keep themselves current with what g1t pays987 */
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas988 notePending(
989 workspace: string,
990 source: "deployments" | "domains" | "context" | "security",
991 costMicros: number,
992 /** How much of it, for the Billing page: `1.2 million requests and 3.4 million CPU ms`. */
993 detail?: string | null,
994 ): Promise<boolean>;
995 /**
996 * This month's usage, one line per kind of meter, at what it is charged
997 * before the plan's included usage or a pool paid for it. Members only.
998 */
999 usageMeters(workspace: string, viewer: Viewer): Promise<Result<MeterUsage[]>>;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1000 /** What the workspace may do now: its plan, caps, pause, trial, and what the plan gives it. */
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1001 entitlements(workspace: string): Promise<Entitlements>;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1002 /**
1003 * Holds a start's estimated cost before the work starts. A failure's code says why not:
1004 * `paused`, `limit`, `not_paid`, `trial_used` or `oss_pool_empty`, with a message for the owner.
1005 */
1006 reserve(reservation: {
1007 workspace: string;
1008 repo: RepoPath;
1009 public: boolean;
1010 kind: ComputeKind;
1011 /** The most the work is expected to cost g1t, before the margin. */
1012 estimateMicros: number;
1013 }): Promise<Result<ReservationHeld>>;
1014 /** Releases a reservation's hold with what the work cost g1t, before the margin. Safe to repeat. */
1015 settle(reservationId: string, actualMicros: number): Promise<Result<boolean>>;
1016 /** Stripe's page to save and verify a card (3-D Secure, never charged). Owners only. */
1017 cardCheck(actor: User, workspace: string, returnUrl: string): Promise<Result<{ url: string }>>;
1018 /** Records the card check once Stripe says it passed, and grants the trial if it can. Safe to repeat. */
1019 confirmCardCheck(workspace: string, viewer: Viewer, session: string): Promise<Result<Entitlements>>;
1020 /** An owner asks for a higher limit, or for help with usage past what was meant. */
1021 requestLimit(
1022 actor: User,
1023 workspace: string,
1024 request: { kind: "limit" | "overage"; amountMicros: number; reason: string; expectedMonthlyMicros: number },
1025 ): Promise<Result<LimitRequest>>;
1026 /** The workspace's requests and their answers, newest first. Members only. */
1027 limitRequests(workspace: string, viewer: Viewer): Promise<Result<LimitRequest[]>>;
1028 /**
1029 * The owners' own caps on agents: one run's spend ($0.10 to $100) and one issue's ($1 to $1,000).
1030 * Null goes back to the default ($2 and $10). A cap staff set wins. Owners only.
1031 */
1032 setCaps(actor: User, workspace: string, caps: { runCapMicros: number | null; issueCapMicros: number | null }): Promise<Result<Entitlements>>;
1033 /** An owner's answer to a spend spike: keep going for 24 hours, or stop. */
1034 confirmSpike(actor: User, workspace: string, keepGoing: boolean): Promise<Result<Entitlements>>;
Prices keep themselves current with what g1t pays1035 /** Every metered price and the recent changes. Public. */
1036 prices(): Promise<PriceBook>;
Usage limits: unpaid usage can only go so far1037 /** A workspace's limit, for its members. */
1038 limit(workspace: string, viewer: Viewer): Promise<Result<Limit>>;
1039 /** The same, for the services that enforce it. */
1040 checkLimit(workspace: string): Promise<Result<Limit>>;
Every sandbox is metered by the second1041 /**
Two limits, real invoices, trust that grows by itself, sales signals1042 * The owners' own monthly limit, up to what is available; null goes back
1043 * to the default, and `useFullLimit` uses everything available. Owners only.
1044 */
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1045 setSpendLimit(
1046 actor: User,
1047 workspace: string,
1048 spendLimitMicros: number | null,
1049 useFullLimit?: boolean,
1050 /** Use the one-time raise: up to twice the highest ceiling, once per workspace. */
1051 raiseOnce?: boolean,
1052 ): Promise<Result<Limit>>;
Two limits, real invoices, trust that grows by itself, sales signals1053 /** The workspace's invoices from g1t, newest first. Members only. */
1054 invoices(workspace: string, viewer: Viewer): Promise<Result<WorkspaceInvoice[]>>;
1055 /**
Every sandbox is metered by the second1056 * How long a sandbox ran for a workspace, reported when it stops. Its
Prices are what g1t pays plus 20%, from the first second1057 * cost is recorded and every second is charged, from the first. False if
1058 * `reference` was recorded before.
Every sandbox is metered by the second1059 */
1060 recordSandbox(usage: {
1061 workspace: string;
1062 seconds: number;
1063 description: string;
1064 repo?: string | null;
1065 reference: string;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1066 /** What ran; checks, workflows and the merge queue on public repositories may use the open-source pool. */
1067 kind?: ComputeKind | null;
1068 /** vCPU-seconds used, when the sandbox can tell: the run is priced on its own CPU. */
1069 cpuSeconds?: number | null;
1070 /** The reservation it started under, settled with this cost. */
1071 reservationId?: string | null;
Fast pages, required checks on the branch, self-hosted runners, honest incidents1072 /** It ran on one of the workspace's self-hosted runners: its minutes go on usage at $0. */
1073 selfHosted?: boolean;
1074 /** The machine it ran on, by label (`g1t-4core`); absent, the standard one. */
1075 instance?: string | null;
Every sandbox is metered by the second1076 }): Promise<Result<boolean>>;
Agents as a team: lifecycle, merge queue, billing and a new shell1077 startRun(run: {
1078 workspace: string;
1079 repo: RepoPath;
1080 number: number;
1081 task: string;
1082 model: string;
Integrations: your own model provider, alerts that open issues, tickets agents read1083 /** `workspace` when the run uses the workspace's own model provider. */
1084 billedTo?: "g1t" | "workspace";
Prices keep themselves current with what g1t pays1085 /** The model session's id, so the run can be settled at AI Gateway's price. */
1086 session?: string | null;
Auto model routing: the cheapest tier that can do each piece of work, a retry goes up a tier, and each run records its tier1087 /** `small` or `large`: the tier g1t routed the run to, on its hosted models. */
1088 tier?: "small" | "large" | null;
Agents as a team: lifecycle, merge queue, billing and a new shell1089 }): Promise<Result<RunTicket | null>>;
Usage, Billing settings and prepaid AI credit; fixes from the UX audit1090 /** Usage over a range of days (`YYYY-MM-DD`, both included), at price, by product, meter, project and day. Members only. */
1091 usageReport(
1092 workspace: string,
1093 viewer: Viewer,
1094 range: { from: string; until: string; products?: string[]; projects?: string[] },
1095 ): Promise<Result<UsageReport>>;
1096 /** The workspace's prepaid AI credit, auto-reload and prices. Members only. */
1097 aiCredit(workspace: string, viewer: Viewer): Promise<Result<AiCredit>>;
1098 /** Stripe's page to buy AI credit ( to ,000, the card fee on its own line). Owners only. The page's id comes back to `returnUrl` as `ai_credit`. */
1099 buyAiCredit(actor: User, workspace: string, amountCents: number, returnUrl: string): Promise<Result<{ url: string }>>;
1100 /** Credits a purchase once Stripe says it was paid, once. Safe to repeat. */
1101 confirmAiCredit(workspace: string, viewer: Viewer, session: string): Promise<Result<AiCredit>>;
1102 /** Auto-reload's settings. Owners only. */
1103 setAiReload(
1104 actor: User,
1105 workspace: string,
1106 reload: { enabled: boolean; thresholdMicros: number; targetMicros: number; monthlyMaxMicros: number },
1107 ): Promise<Result<AiCredit>>;
1108 /** The monthly budget: the spend limit, its alerts, whether usage pauses at 100%, and a webhook. Owners only. */
1109 setBudget(
1110 actor: User,
1111 workspace: string,
1112 budget: { amountMicros: number | null; alerts: number[]; pauseAtLimit: boolean; webhook: string | null; keepLimit?: boolean },
1113 ): Promise<Result<Limit>>;
1114 /** Invoice details from the Stripe customer, the default payment method, invoices and the next invoice. Members only. */
1115 billingDetails(workspace: string, viewer: Viewer): Promise<Result<BillingDetails>>;
1116 /** Saves invoice details on the Stripe customer; absent fields stay, empty clears. Owners only. */
1117 setBillingDetails(actor: User, workspace: string, details: BillingDetailsInput): Promise<Result<BillingDetails>>;
Agents as a team: lifecycle, merge queue, billing and a new shell1118}
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request1119
1120
1121/** One slice of usage: what it was for, what it cost, how many runs. */
1122export type UsageSlice = { key: string; micros: number; runs: number };
1123
Mission control shows model usage, yours and the workspace's: tokens, cost, active days, cache share, each day, and the mix1124/** The model tokens runs used over a window of days. */
1125export type TokenUsage = {
1126 /** `YYYY-MM-DD`, the first day counted. */
1127 since: string;
1128 /** The window's length: 42 unless asked, 366 at most. */
1129 days: number;
1130 /** Null for the whole workspace. */
1131 person: string | null;
1132 totalTokens: number;
1133 inputTokens: number;
1134 outputTokens: number;
1135 cacheReadTokens: number;
1136 cacheWriteTokens: number;
1137 /** What those runs were charged, as `usage` measures it. */
1138 costMicros: number;
1139 /** Days in the window with any tokens. */
1140 activeDays: number;
1141 /** Every day in the window, oldest first, zeros included. */
1142 byDay: { day: string; tokens: number }[];
1143};
1144
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request1145/** What a workspace's agents cost over a period. */
1146export type Usage = {
1147 since: string;
1148 /** Charged, including g1t's margin. */
1149 spentMicros: number;
Billing and Usage reconcile: own-provider runs leave Billing's at-price total, and Usage's not-charged part is at price less charged1150 /** What g1t's usage came to at price, less what was charged: the plan's included usage, the trial, a pool or a free period paid it. Usage at price is `spentMicros` plus this. */
Billing's usage total is labeled at price, and Usage says what part of it was paid for1151 coveredMicros?: number;
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging1152 /** What the account's discount took off the price; usage at price is spent + covered + this. */
1153 discountMicros?: number;
1154 /** The account's discount now, in percent; with one, the slices are at price. */
1155 discountPercent?: number | null;
Usage, Billing settings and prepaid AI credit; fixes from the UX audit1156 /** Usage at price: spent + covered + discount, from the same ledger lines. The one usage figure every page shows. */
1157 priceMicros?: number;
Integrations: your own model provider, alerts that open issues, tickets agents read1158 /** What g1t's model provider charged, before the margin. */
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request1159 costMicros: number;
Integrations: your own model provider, alerts that open issues, tickets agents read1160 /** What runs on the workspace's own provider cost there, estimated. Not charged by g1t. */
1161 providerMicros: number;
Usage while free is shown at cost; agents get rustfmt and clippy1162 /** What the runs used, at cost: g1t's models and the workspace's own provider together. */
1163 usedMicros: number;
1164 /** g1t charges nothing for now; the slices then measure usage at cost. */
1165 free: boolean;
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request1166 runs: number;
1167 /** Spend per day and task, keyed `YYYY-MM-DD/task`. */
1168 byDay: UsageSlice[];
1169 byTask: UsageSlice[];
1170 byRepo: UsageSlice[];
1171 /** Keyed `namespace/name#number`. */
1172 byPull: UsageSlice[];
1173 byModel: UsageSlice[];
1174 /** Credit bought in the period. */
1175 addedMicros: number;
1176};
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily1177
1178/** One of g1t's products (a "bucket") on one day. Money in micros. */
1179export type CostDay = { day: string; bucket: string; cfCostMicros: number; ownCostMicros: number; valueMicros: number; cashMicros: number };
1180
1181/** One product over the range: what customers were charged at price against what it cost. */
1182export type ProductMargin = {
1183 bucket: string;
1184 title: string;
1185 /** Cloudflare's bill, or g1t's own figure where Cloudflare does not bill it (`costSource`). */
1186 costMicros: number;
1187 cfCostMicros: number;
1188 ownCostMicros: number;
1189 valueMicros: number;
1190 marginMicros: number;
1191 marginPercent: number | null;
1192 costSource: "cloudflare" | "ledger" | string;
1193 /** Running g1t, paid for by the plan. */
1194 overhead: boolean;
1195};
1196
1197/** All of g1t: money in (usage and the plan) against every cost. */
Costs: margin is measured on what was sold; comped workspaces, free periods, the trial and the pools are given away, a budget shown beside it1198export type OverallMargin = {
1199 usageMicros: number;
1200 plansMicros: number;
1201 costMicros: number;
1202 marginMicros: number;
1203 marginPercent: number | null;
1204 /** Of costMicros, what went on usage g1t gave away on purpose: comped workspaces, free periods, the trial and the open-source pool. */
1205 givenMicros?: number;
1206 /** Money in against costMicros - givenMicros. */
1207 soldMarginMicros?: number;
1208 soldMarginPercent?: number | null;
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running1209 /** Usage sold: usageMicros against what that usage cost, less what was given. */
1210 usageCostMicros?: number;
1211 usageMarginMicros?: number;
1212 usageMarginPercent?: number | null;
1213 /** Running g1t: plansMicros against the platform's cost, less its given share. */
1214 runningCostMicros?: number;
1215 /** Cost no mapping names, less its given share. */
1216 unmappedCostMicros?: number;
1217 /** givenMicros by why. Free is free periods, free allowances and overruns g1t covered. */
1218 givenCompedMicros?: number;
1219 givenFreeMicros?: number;
1220 givenTrialMicros?: number;
1221 givenPoolMicros?: number;
Merge branch 'worktree-agent-a633ac0f7f66d419d'1222 /** What discounts on an account's terms took below cost plus the margin: given, not margin lost. */
1223 givenDiscountMicros?: number;
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging1224 /** Credits from g1t spent on usage, by kind: given, never money in. Refunds come off money in instead. */
1225 givenCreditPromotionalMicros?: number;
1226 givenCreditGoodwillMicros?: number;
1227 /** Credits over the range: given (every kind), spent on usage, and refunds' money given back. */
1228 creditsGivenMicros?: number;
1229 creditsUsedMicros?: number;
1230 creditsRefundedMicros?: number;
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running1231 /** costMicros by who g1t pays: Cloudflare's bill (billed, after included allowances) and model providers (tokens, not on Cloudflare's bill). */
Costs: the plan's included usage counts as paid for the usage it covered, out of what plans leave for running g1t; the run button shows it is running with CSS alone (sudo ships no JavaScript)1232 /** What the plan's included usage paid for, at price: money in for usage, paid out of plansMicros. */
1233 includedMicros?: number;
Costs: a statement that keeps usage sold, running g1t, subscriptions and what was given away (comped, free use, trial, pool) apart, and says who was paid; free use carries its own cost; the run button says it is running1234 cloudflareCostMicros?: number;
1235 modelsCostMicros?: number;
Costs: margin is measured on what was sold; comped workspaces, free periods, the trial and the pools are given away, a budget shown beside it1236};
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily1237
1238/** A count, cost or leak that does not add up. */
1239export type CostDrift = {
1240 bucket: string;
1241 title: string;
1242 kind: "count" | "cost" | "leak" | string;
1243 ours: number;
1244 cloudflare: number;
1245 deltaPercent: number | null;
1246 detail: string;
1247 foundAt: string;
1248};
1249
1250export type MarginAlert = {
1251 id: string;
1252 kind: "margin" | "overall" | "leak" | "drift" | "workspace" | string;
1253 /** The product, or the workspace. */
1254 subject: string;
1255 detail: string;
1256 since: string;
1257 openedAt: string;
1258 emailedAt: string | null;
1259};
1260
1261/** A change to a price, measured from what Cloudflare charged. */
1262export type PriceProposal = {
1263 id: string;
1264 meter: string;
1265 title: string;
1266 unit: string;
1267 currentCostMicros: number;
1268 proposedCostMicros: number;
1269 changePercent: number;
1270 markupPercent: number;
1271 reason: string;
1272 source: "keeper" | "reconciler" | string;
1273 /** Far off the current cost: look before approving. */
1274 suspect: boolean;
1275 status: "open" | "applied" | "approved" | "rejected" | "superseded" | string;
1276 createdAt: string;
1277 decidedAt: string | null;
1278 decidedBy: string | null;
1279 note: string | null;
1280 effectiveAt: string | null;
1281};
1282
1283/** One version of one meter's price; never changed once written. */
1284export type PriceVersion = {
1285 id: string;
1286 meter: string;
1287 version: number;
1288 costMicros: number;
1289 markupPercent: number;
1290 priceMicros: number;
1291 effectiveAt: string;
1292 reason: string;
1293 createdBy: string;
1294 appliedAt: string | null;
1295};
1296
sudo: reset a test workspace's billing so it starts again as a new customer; refused on a live Stripe key, for comped workspaces and for an enterprise's1297/** What `resetBilling` removed. */
sudo: a billing reset runs the costs analysis again so every figure is fresh; every submit button shows it is working (CSS only); no margin percentage on less than a cent sold1298export type BillingReset = { workspace: string; rows: number; refreshed?: boolean };
sudo: reset a test workspace's billing so it starts again as a new customer; refused on a live Stripe key, for comped workspaces and for an enterprise's1299
Costs: margin is measured on what was sold; comped workspaces, free periods, the trial and the pools are given away, a budget shown beside it1300export type WorkspaceCost = { workspace: string; costMicros: number; revenueMicros: number; givenMicros?: number; internal: boolean };
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily1301
1302export type CostLineSummary = {
1303 product: string;
1304 meter: string;
1305 rawName: string;
1306 unit: string;
1307 source: string;
1308 quantity: number;
1309 costMicros: number;
1310 /** Absent when no mapping claims it. */
1311 bucket: string | null;
1312};
1313
1314export type CostMapping = {
1315 product: string;
1316 meter: string;
1317 bucket: string;
1318 priceMeter: string | null;
1319 ownMeter: string | null;
1320 scaleToOwn: boolean;
1321 driftPercent: number;
1322 note: string;
1323 updatedAt: string;
1324 updatedBy: string;
1325};
1326
1327export type CostMappingInput = {
1328 product: string;
1329 meter: string;
1330 bucket?: string;
1331 priceMeter?: string | null;
1332 ownMeter?: string | null;
1333 scaleToOwn?: boolean;
1334 driftPercent?: number | null;
1335 note?: string;
1336 remove?: boolean;
1337};
1338
1339export type CostSettings = {
1340 autoApply: boolean;
1341 autoApplyPercent: number;
1342 noticeDays: number;
1343 marginFloorPercent: number;
1344 alertDays: number;
1345 minDailyCostMicros: number;
1346 anomalyFactor: number;
1347 anomalyFloorMicros: number;
Usage, Billing settings and prepaid AI credit; fixes from the UX audit1348 /** Pass Stripe's card fee on as its own line when AI credit is bought by card. */
1349 cardFee: boolean;
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily1350};
1351
1352export type CostsReport = {
1353 configured: boolean;
1354 fetchedAt: string | null;
1355 since: string;
1356 until: string;
1357 days: CostDay[];
1358 products: ProductMargin[];
1359 overall: OverallMargin;
1360 drift: CostDrift[];
1361 alerts: MarginAlert[];
1362 proposals: PriceProposal[];
1363 versions: PriceVersion[];
1364 topWorkspaces: WorkspaceCost[];
1365 lines: CostLineSummary[];
1366 mappings: CostMapping[];
1367 settings: CostSettings;
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays1368 /** g1t's own spend against its two caps. */
1369 caps: SpendCaps;
1370};
1371
1372/** What g1t pays for itself, at cost, against its caps (billing's `budget`). */
1373export type SpendCaps = {
1374 /** Today (UTC), YYYY-MM-DD, and this month, YYYY-MM. */
1375 day: string;
1376 month: string;
1377 /** What g1t paid for itself today across every workspace. */
1378 todayMicros: number;
1379 /** `PLATFORM_DAILY_SPEND_CAP_MICROS`; 0: no breaker. */
1380 dailyCapMicros: number;
1381 /** New hosted-model agent runs g1t would pay for are paused. */
1382 tripped: boolean;
1383 trippedAt: string | null;
1384 liftedBy: string | null;
1385 liftedAt: string | null;
1386 liftNote: string | null;
1387 /** This month so far, by what paid: comped, trial, oss, given, unpaid. */
1388 monthBuckets: { bucket: string; title: string; micros: number }[];
1389 comped: CompedBudget[];
1390 /** Free workspaces' share of reconciled costs this month (git, storage, platform). */
1391 freeTierMicros: number;
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing1392 /** Cloudflare's subscriptions a month: read from Cloudflare each day, else `CLOUDFLARE_FIXED_MONTHLY_MICROS`, an estimate. */
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays1393 fixedMonthlyMicros: number;
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing1394 fixedSource?: "cloudflare" | "estimate" | string;
1395 fixedReadAt?: string | null;
1396 /** Each subscription, when read from Cloudflare. */
1397 fixedItems?: { name: string; monthlyMicros: number }[];
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays1398 /** Money in this month, through the last reconciled day. */
1399 revenueMicros: number;
1400};
1401
1402/** A comped account's monthly budget, at cost. */
1403export type CompedBudget = {
1404 account: string;
1405 name: string;
1406 usedMicros: number;
1407 /** 0: no budget. */
1408 ceilingMicros: number;
1409 /** `COMPED_MONTHLY_CEILING_MICROS`, not the account's own limit. */
1410 defaultCeiling: boolean;
1411 /** 50, 75, 90, 100, or 0. */
1412 level: number;
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily1413};
1414
1415export type CostsRun = { lines: number; days: number; proposals: number; alerts: number; problems: string[] };
Usage, Billing settings and prepaid AI credit; fixes from the UX audit1416
1417/** The product families the Usage page groups meters into, in order. */
1418export const PRODUCTS = [
1419 { key: "agent", label: "Agent" },
1420 { key: "sandboxes", label: "Sandboxes" },
1421 { key: "gateway", label: "AI Gateway" },
1422 { key: "deployments", label: "Deployments" },
1423 { key: "git_storage", label: "Git & storage" },
1424 { key: "packages", label: "Packages" },
1425 { key: "security", label: "Security & quality" },
1426 { key: "search", label: "Search" },
1427] as const;
1428
1429export type ProductKey = (typeof PRODUCTS)[number]["key"];
1430
1431/** What usage came to over a range, and what paid for it: price − discount − included − credits = charged. */
1432export type UsageTotals = {
1433 /** Usage at price, pending usage included. */
1434 priceMicros: number;
1435 discountMicros: number;
1436 /** Paid by the plan's included usage, the trial and g1t's pools. */
1437 includedMicros: number;
1438 /** Paid by AI credit and credit from g1t. */
1439 creditsMicros: number;
1440 /** Left for the workspace to pay. */
1441 chargedMicros: number;
1442 /** Metered this month, charged when it closes. */
1443 pendingMicros: number;
1444 costMicros: number;
1445};
1446
1447export type UsageDay = { day: string; product: string; micros: number };
1448
1449export type UsageAllowance = { used: number; of: number; unit: string };
1450
1451export type ProjectUsage = { project: string; micros: number; quantity: number };
1452
1453/** One meter over a range. */
1454export type MeterLine = {
1455 key: string;
1456 label: string;
1457 product: string;
1458 /** `tokens`, `seconds`, `bytes`, `operations`, `requests` or `entries`. */
1459 unit: string;
1460 quantity: number;
1461 micros: number;
1462 pendingMicros?: number;
1463 /** Every day of the range, oldest first, at price. */
1464 daily: number[];
1465 allowance?: UsageAllowance | null;
1466 byProject: ProjectUsage[];
1467};
1468
1469export type FeatureUsage = { key: string; label: string; micros: number; count: number };
1470
1471export type ProductUsage = { key: string; label: string; micros: number; meters: MeterLine[]; features?: FeatureUsage[] };
1472
1473export type UsageReport = {
1474 from: string;
1475 until: string;
1476 totals: UsageTotals;
1477 days: UsageDay[];
1478 products: ProductUsage[];
1479 projects: string[];
1480 /** The plan's included usage this month, in micros. */
1481 included?: UsageAllowance | null;
1482 discountPercent?: number | null;
1483 aiCreditMicros: number;
1484 creditMicros: number;
1485 trialMicros?: number | null;
1486 plan: PlanKind;
1487 free: boolean;
1488};
1489
1490export type AiReload = {
1491 enabled: boolean;
1492 thresholdMicros: number;
1493 targetMicros: number;
1494 monthlyMaxMicros: number;
1495 reloadedMicros?: number;
1496 failedAt?: string | null;
1497 error?: string | null;
1498};
1499
1500export type CardFee = { on: boolean; percentMicros: number; fixedCents: number };
1501
1502/** Prepaid AI credit: what Agent and AI Gateway usage draws on. */
1503export type AiCredit = {
1504 balanceMicros: number;
1505 purchasedMicros: number;
1506 givenMicros: number;
1507 grants: CreditGrant[];
1508 /** A 100% discount pays for AI usage: nothing to buy. */
1509 freeViaDiscount: boolean;
1510 /** Invoiced after use (an enterprise). */
1511 postpaid: boolean;
1512 /** New runs on g1t's models are refused for want of credit. */
1513 blocked: boolean;
1514 canBuy: boolean;
1515 presetsCents: number[];
1516 minCents: number;
1517 maxCents: number;
1518 cardFee: CardFee;
1519 reload: AiReload;
1520 /** The agent rate per million tokens, at price. */
1521 agentRateMicros: number;
1522 modelMarkupPercent: number;
1523 gatewayMarkupPercent: number;
1524 upgradeCreditMicros: number;
1525 expiresDays: number;
1526};
1527
1528export type PostalAddress = { line1: string; line2: string; city: string; state: string; postalCode: string; country: string };
1529
1530export type PaymentMethod = {
1531 kind: string;
1532 brand?: string | null;
1533 last4?: string | null;
1534 expMonth?: number | null;
1535 expYear?: number | null;
1536};
1537
1538export type StripeInvoice = {
1539 id: string;
1540 number?: string | null;
1541 status: string;
1542 totalCents: number;
1543 currency: string;
1544 createdAt: string;
1545 description?: string | null;
1546 hostedUrl?: string | null;
1547 pdfUrl?: string | null;
1548};
1549
1550export type UpcomingInvoice = { closesAt: string; subscriptionsMicros: number; usageMicros: number; totalMicros: number };
1551
1552export type BillingDetails = {
1553 customer: boolean;
1554 email: string | null;
1555 name: string | null;
1556 address: PostalAddress | null;
1557 taxIdType: string | null;
1558 taxId: string | null;
1559 poNumber: string | null;
1560 language: string | null;
1561 paymentMethod: PaymentMethod | null;
1562 invoices: StripeInvoice[];
1563 upcoming: UpcomingInvoice;
1564 unavailable?: string | null;
1565};
1566
1567export type BillingDetailsInput = {
1568 email?: string;
1569 name?: string;
1570 address?: PostalAddress;
1571 taxIdType?: string;
1572 taxId?: string;
1573 poNumber?: string;
1574 language?: string;
1575};

This file's history is long; its oldest lines are credited to the oldest commit read.