g1t/packages/contracts/src/billing.ts

1,222 lines48,326 bytesCodeBlame
1import type { ComputeKind, Reservation } from "./compute";
2import 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;
18 /**
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;
23};
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;
36 /** 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;
38};
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;
55 /** For usage: who paid the model provider. */
56 billedTo: "g1t" | "workspace";
57 /** For a top-up: the username of whoever paid. */
58 createdBy: string | null;
59 /** RFC 3339. */
60 createdAt: string;
61 /** The workspace the line belongs to, which tells an enterprise's lines apart. */
62 workspace?: string | null;
63 /** For usage: what the plan's included usage paid of it. `amountMicros` is what is left to pay. */
64 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;
69 /** For usage: what g1t covered itself, such as a trial's last run past its credit. */
70 givenMicros?: number;
71};
72
73/** What lets a sandbox, and nothing else, report what its run cost. */
74export type RunTicket = { runId: string; token: string };
75
76/**
77 * What agents cost, charged to the workspace they worked for. A workspace
78 * buys credit; each run deducts its cost plus g1t's margin; with no credit,
79 * no agent starts.
80 */
81/**
82 * The free allowance on g1t's hosted models for a workspace not otherwise
83 * open to them: a few dollars of model cost each, out of one pool, until a
84 * date. Mirrors `Trial` in `crates/contracts/src/billing.rs`.
85 */
86/** How an account is charged. Standard unless g1t set otherwise in sudo. */
87export type Terms = {
88 kind: "standard" | "comped" | "custom";
89 discountPercent: number;
90 ceilingMicros: number | null;
91 note: string;
92 until: string | null;
93 setBy: string | null;
94 setAt: string | null;
95};
96
97/**
98 * Who pays: a workspace's own account, or an enterprise's, which pays for
99 * several workspaces with one bill and one limit.
100 */
101export type PayingAccount = {
102 id: string;
103 kind: "workspace" | "enterprise";
104 name: string;
105 terms: Terms;
106 workspaces: string[];
107 /** Where an enterprise's invoices go. */
108 billingEmail?: string | null;
109 /** An enterprise's invoices, newest first. */
110 invoices?: EnterpriseInvoice[];
111 createdAt: string;
112 /** What g1t staff set for the account beyond its terms. */
113 allowances?: Allowances;
114};
115
116/** Set per account by g1t staff in sudo, on top of its terms. */
117export type Allowances = {
118 /** The g1t plan without its monthly price; usage is charged as usual. Comped accounts have it anyway. */
119 plan: boolean;
120 /** Each public repository's monthly cap on g1t's open-source pool; null for the default. */
121 ossRepoMicros: number | null;
122 /** Each workspace's trial credit, outside the monthly pool; null for the default. */
123 trialMicros: number | null;
124 /** Agents at once, in place of the plan's (2 in the first month or on the trial, then 10); null for the default. */
125 maxConcurrentAgents?: number | null;
126 /** One run's spend cap, in place of the owners' and the default $2; null for none. */
127 runCapMicros?: number | null;
128 /** What one issue's agents may spend in all, in place of the owners' and the default $10; null for none. */
129 issueCapMicros?: number | null;
130 /** 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. */
131 auditRetentionDays?: number | null;
132 /** A hold on new compute, with why; null for none. */
133 hold?: string | null;
134};
135
136// --- Entitlements, and compute started under a reservation ------------------
137//
138// Every service that starts compute asks billing first:
139// 1. `entitlements(workspace)`: what it may do at all, its caps, and whether compute is paused.
140// 2. `reserve(...)`: holds the estimate against what may pay for it, so starts at the same moment
141// cannot overshoot together. Answers who pays first, or refuses with a stable code
142// (`not_paid`, `trial_used`, `limit`, `paused`, `oss_pool_empty`) and a message for the owner.
143// 3. `settle(reservationId, actualMicros)`: releases the hold. The charge goes on the ledger the usual way.
144// A reservation never settled lapses after `RESERVATION_HOURS`.
145
146/** A reservation that is never settled stops holding after this long. */
147export const RESERVATION_HOURS = 3;
148/** What a ceiling reads as when there is none (g1t's own workspaces). */
149export const UNLIMITED_MICROS = 1_000_000_000_000_000;
150
151/** What a workspace pays g1t on, as far as compute is concerned. Mirrors `PlanKind`. */
152export type PlanKind = "free" | "paid" | "internal" | "enterprise";
153
154// `ComputeKind` (what compute is for), `PaidBy` (who pays first: credit, trial, oss, on_demand) and
155// `Reservation` are in `./compute`, with the gate that calls `reserve` and `settle`.
156
157/** One level reached: 50, 75, 90 or 100 percent. */
158export type UsageAlert = {
159 /** `included` (the plan's included usage), `spend_limit` or `ceiling`. */
160 meter: "included" | "spend_limit" | "ceiling" | string;
161 level: number;
162 usedMicros: number;
163 limitMicros: number;
164 message: string;
165};
166
167/** An hour's spend well above the workspace's usual: new compute waits for an owner. */
168export type Spike = {
169 id: string;
170 /** `open` (waiting), `continued` (keep going) or `stopped`. */
171 status: "open" | "continued" | "stopped" | string;
172 hourMicros: number;
173 averageMicros: number;
174 detectedAt: string;
175 decidedBy?: string | null;
176 decidedAt?: string | null;
177 /** While continued: until when, unless spend doubles again first. */
178 until?: string | null;
179};
180
181/** What a workspace may do now. Mirrors `Entitlements` in `crates/contracts/src/billing.rs`. */
182export type Entitlements = {
183 workspace: string;
184 plan: PlanKind;
185 /** May start sandboxes, models, deployments and semantic search at all: paid, internal, enterprise, or free with trial credit left. */
186 compute: boolean;
187 /** The one-time trial credit left; 0 if none or used. */
188 trialMicrosLeft: number;
189 /** A card check has been done; the trial and the open-source pool need it. */
190 trialVerified: boolean;
191 /** A paid workspace still in its first billing cycle. */
192 firstMonth: boolean;
193 /** 2 in the first month or on the trial, 10 after; staff can override it. */
194 maxConcurrentAgents: number;
195 /** 60 in the first month or on the trial; otherwise the guardrails' own caps. */
196 maxRunMinutes: number;
197 /** One run's spend cap, $2 by default; staff can override it. */
198 runCapMicros: number;
199 /** Agent spend on one issue in all, $10 by default. */
200 issueCapMicros: number;
201 /** g1t's ceiling on usage not yet paid for; `UNLIMITED_MICROS` for g1t's own; 0 for free. */
202 ceilingMicros: number;
203 /** Usage not yet paid for this month, prepayment taken off. */
204 exposureMicros: number;
205 /** Why new compute is paused, for the owner; null when it is not. */
206 paused: string | null;
207 /** What open reservations hold now. */
208 heldMicros?: number;
209 /** Paid in advance and not used yet. */
210 prepaidMicros?: number;
211 /** The plan's included usage each month, and what of it is used. */
212 includedMicros?: number;
213 includedUsedMicros?: number;
214 /** 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. */
215 auditRetentionDays: number;
216 /** Whether `auditRetentionDays` is what staff set for the account rather than the plan's. */
217 auditRetentionCustom?: boolean;
218 /** Private repository storage free for every workspace: past it, the plan pays and a free workspace's pushes stop. */
219 freePrivateStorageBytes: number;
220 /** The last daily measure of the workspace's private repositories (a lower bound). */
221 privateStorageBytes: number;
222 /** What g1t's open-source pool paid for the workspace this month. */
223 ossPaidMicros: number;
224 /** Deploy build time this month, every second of it metered. */
225 buildSecondsUsed?: number;
226 /** Git operations this month, and how many are free for every workspace. */
227 gitOperations?: number;
228 gitOperationsIncluded?: number;
229 /** The smallest amount a card is charged when a month closes. */
230 minChargeMicros: number;
231 /** A spend spike waiting for an owner, or decided. */
232 spike?: Spike | null;
233 /** Where usage stands against what is included and the limits, from 50%. */
234 alerts?: UsageAlert[];
235};
236
237/** A hold on a start's estimated cost, as billing answers it (`Reservation` in `./compute`, and more). */
238export type ReservationHeld = Reservation & {
239 /** What is held, at cost; may be less than the estimate for a free workspace's last bit of trial. */
240 heldMicros?: number;
241 /** When the hold lapses if never settled. */
242 expiresAt?: string;
243};
244
245/** A request to g1t: a higher limit, or help with usage past what was meant. */
246export type LimitRequest = {
247 id: string;
248 workspace: string;
249 kind: "limit" | "overage" | string;
250 amountMicros: number;
251 reason: string;
252 expectedMonthlyMicros: number;
253 status: "open" | "approved" | "declined" | string;
254 decidedMicros?: number | null;
255 decidedBy?: string | null;
256 /** The answer, as the owner sees it. */
257 answer?: string | null;
258 createdBy: string;
259 createdAt: string;
260 decidedAt?: string | null;
261};
262
263/** What staff see beside a request. */
264export type WorkspaceHistory = {
265 plan: PlanKind | null;
266 months: MonthFigures[];
267 paidClearedMicros: number;
268 payments: number;
269 disputes: number;
270 declines: number;
271 firstSeen: string | null;
272 ceilingMicros: number | null;
273 maxCeilingMicros: number | null;
274 spendLimitMicros: number | null;
275 lastHourMicros: number;
276 averageHourMicros: number;
277 lastDayMicros: number;
278};
279
280export type LimitRequestReview = { request: LimitRequest; history: WorkspaceHistory };
281
282/** What a one-time goodwill credit comes to: the margin on the overage, always, plus its cost up to the cap. */
283export type Goodwill = {
284 overageMicros: number;
285 marginMicros: number;
286 costMicros: number;
287 creditMicros: number;
288 absorbedMicros: number;
289};
290
291/** A workspace whose month went well past its usual, or hit a spike. */
292export type Overage = {
293 workspace: string;
294 plan: PlanKind;
295 typicalMonthMicros: number;
296 thisMonthMicros: number;
297 costMicros: number;
298 marginMicros: number;
299 spike: Spike | null;
300 topEntries: LedgerEntry[];
301 goodwill: Goodwill;
302 goodwillAvailable: boolean;
303 lastGoodwillAt: string | null;
304 request: LimitRequest | null;
305};
306
307/** One workspace's recent pace. */
308export type Velocity = {
309 workspace: string;
310 plan: PlanKind;
311 lastHourMicros: number;
312 averageHourMicros: number;
313 lastDayMicros: number;
314 thisMonthMicros: number;
315 ratio: number;
316 spike: Spike | null;
317 firstSeen: string | null;
318};
319
320/** g1t's capped budgets for free usage this month. */
321export type Pools = {
322 month: string;
323 trialGrantedMicros: number;
324 trialPoolMicros: number;
325 trialGrants: number;
326 ossUsedMicros: number;
327 ossPoolMicros: number;
328 ossRepoMicros: number;
329};
330
331export type AccountSummary = {
332 account: PayingAccount;
333 limit: Limit;
334 chargedMicros: number;
335 costMicros: number;
336 paidMicros: number;
337 /** The same figures for each of the account's workspaces that has any. */
338 byWorkspace: WorkspaceFigures[];
339 /** The last six months, oldest first. */
340 months?: MonthFigures[];
341};
342
343/** One workspace's share of an `AccountSummary`. */
344export type WorkspaceFigures = { workspace: string; chargedMicros: number; costMicros: number; paidMicros: number };
345
346export type StripeStatus = {
347 /** `test` or `live`, from the key; `off` without one. */
348 mode: "test" | "live" | "off" | string;
349 /** Whether `STRIPE_WEBHOOK_SECRET` is set, so events can be checked. */
350 secretSet: boolean;
351 /** The destination at billing's address in Stripe, as Stripe has it. */
352 webhook: { url: string; endpointId: string; status: "enabled" | "disabled" | string; events: string[]; createdAt: string } | null;
353 /** Events billing handles that the destination does not send. */
354 missingEvents: string[];
355 recentEvents: { id: string; kind: string; outcome: string; receivedAt: string }[];
356 error: string | null;
357};
358
359/** An enterprise's invoice: one line per workspace, paid on Stripe's page. */
360export type EnterpriseInvoice = {
361 invoiceId: string;
362 hostedUrl: string | null;
363 amountMicros: number;
364 status: "open" | "paid" | "overdue" | "void" | string;
365 period: string;
366 lines: { workspace: string; amountMicros: number }[];
367 createdAt: string;
368};
369
370/** A workspace's invoice: monthly, or when charged near its limit. Itemised, in Stripe's billing page. */
371export type WorkspaceInvoice = {
372 invoiceId: string;
373 workspace: string;
374 reason: "month" | "threshold" | string;
375 period: string;
376 amountMicros: number;
377 status: "paid" | "open" | "failed" | "void" | string;
378 hostedUrl: string | null;
379 pdfUrl: string | null;
380 lines: { description: string; amountMicros: number }[];
381 createdAt: string;
382};
383
384/** A month of the ledger, grouped by day or project, a line per kind of charge. */
385export type Statement = {
386 month: string;
387 months: string[];
388 groups: {
389 key: string;
390 label: string;
391 /** `coveredMicros`: what the plan's included usage, the trial, the open-source pool or g1t paid, not in `chargedMicros`. */
392 lines: { kind: string; count: number; chargedMicros: number; costMicros: number; coveredMicros?: number }[];
393 chargedMicros: number;
394 }[];
395 totals: {
396 chargedMicros: number;
397 paidMicros: number;
398 costMicros: number;
399 entries: number;
400 /** What paid for usage before it was charged, such as "Paid by g1t's open-source pool". */
401 covered?: { source: "included" | "trial" | "oss_pool" | "given" | string; label: string; micros: number }[];
402 /** Owed when the month closed but under the minimum charge: on the next invoice. */
403 carriedMicros?: number;
404 };
405};
406
407export type MonthFigures = {
408 month: string;
409 /** Usage charged, after what paid for it first. */
410 chargedMicros: number;
411 /** What usage cost g1t: never a workspace's own model provider. */
412 costMicros: number;
413 paidMicros: number;
414 /** The plan's monthly price, paid. */
415 plansMicros?: number;
416 /** What g1t gave at price (internal use, trials, the open-source pool, goodwill, covered). Not margin. */
417 givenMicros?: number;
418};
419
420/** What g1t gave this month from one source. */
421export type GivenFigures = { source: "internal" | "trial" | "oss_pool" | "goodwill" | "covered" | string; label: string; micros: number; costMicros: number };
422
423/** One internal workspace's use this month, and why it is not charged. */
424export type InternalUse = { workspace: string; reason: string; costMicros: number; entries: number };
425
426export type SignalKind = "at_limit" | "near_ceiling" | "declined" | "growing" | "established" | "first_payment" | "high_spend" | "cost_over_revenue";
427
428/** Why a workspace is worth reaching out to. */
429export type Signal = {
430 workspace: string;
431 kind: SignalKind;
432 detail: string;
433 valueMicros: number;
434 stage: string | null;
435 owner: string | null;
436 nextStep?: string | null;
437 /** When the next step is due, YYYY-MM-DD. */
438 nextAt?: string | null;
439};
440
441/** One invoice g1t has sent, a workspace's or an enterprise's. */
442export type InvoiceSummary = {
443 invoiceId: string;
444 kind: "workspace" | "enterprise";
445 account: string;
446 name: string;
447 reason: string;
448 period: string;
449 amountMicros: number;
450 status: string;
451 hostedUrl: string | null;
452 createdAt: string;
453 paidAt: string | null;
454};
455
456export type SalesStage = "none" | "lead" | "contacted" | "negotiating" | "won" | "lost" | "churn_risk";
457
458export type SalesRecord = {
459 workspace: string;
460 stage: SalesStage | string;
461 owner: string | null;
462 nextStep: string | null;
463 nextAt: string | null;
464 notes: { id: string; text: string; by: string; createdAt: string }[];
465 updatedAt: string | null;
466};
467
468export type Overview = {
469 month: string;
470 months: MonthFigures[];
471 byKind: { kind: string; chargedMicros: number; costMicros: number }[];
472 payingWorkspaces: number;
473 stopped: number;
474 nearCeiling: number;
475 declined: number;
476 openInvoicesMicros: number;
477 followUpsDue: number;
478 /** g1t's capped budgets for free usage, this month. */
479 pools?: Pools | null;
480 /** Usage charged plus the plan's price paid, this month. */
481 revenueMicros?: number;
482 activePlans?: number;
483 planMrrMicros?: number;
484 /** What g1t gave this month, by source, apart from its margin. */
485 given?: GivenFigures[];
486 /** g1t's own and Flagon's workspaces: what their use cost, and why they are not charged. */
487 internal?: InternalUse[];
488 openRequests?: number;
489 overages?: number;
490 openSpikes?: number;
491};
492
493/** A customer's Stripe billing page, for staff to send them. */
494export type BillingLink = {
495 /** One-time and short-lived, signed in already. */
496 portalUrl: string;
497 /** The page's sign-in, which does not expire: the customer signs in by email. */
498 loginUrl: string | null;
499 customerEmail: string | null;
500 expiresNote: string;
501};
502
503export type AdminAction = { id: string; account: string; action: string; detail: string; by: string; createdAt: string };
504
505export type AccountDetail = {
506 summary: AccountSummary;
507 workspaces: Limit[];
508 ledger: LedgerEntry[];
509 audit: AdminAction[];
510};
511
512/** Staff-only billing, for sudo.g1t.sh. Every change names who made it. */
513export interface BillingAdminApi {
514 accounts(query?: string): Promise<AccountSummary[]>;
515 account(id: string): Promise<Result<AccountDetail>>;
516 setTerms(id: string, terms: Terms, by: string): Promise<Result<PayingAccount>>;
517 /** Team on or off without charge, and the account's share of the pools. Needs a note. */
518 setAllowances(id: string, allowances: Allowances, note: string, by: string): Promise<Result<PayingAccount>>;
519 createEnterprise(name: string, workspaces: string[], by: string): Promise<Result<PayingAccount>>;
520 attach(workspace: string, account: string | null, by: string): Promise<Result<PayingAccount>>;
521 credit(workspace: string, amountMicros: number, note: string, by: string): Promise<Result<LedgerEntry>>;
522 /** The workspace's Stripe billing page, to send to the customer. Logged. */
523 billingLink(workspace: string, by: string): Promise<Result<BillingLink>>;
524 /** Where billing stands with Stripe; with `setup`, registers the webhook first. */
525 /** Stripe's state for billing; `fix` enables the destination and adds missing events first. */
526 stripe(fix?: boolean, by?: string): Promise<StripeStatus>;
527 /** Where an enterprise's invoices go; makes its Stripe customer. */
528 enterpriseBilling(id: string, email: string, by: string): Promise<Result<PayingAccount>>;
529 /** Sends an enterprise its invoice now, for what its workspaces owe. */
530 invoiceEnterprise(id: string, by: string): Promise<Result<EnterpriseInvoice>>;
531 /** Exactly these workspaces' accounts, such as one page of the list. */
532 accountsFor(workspaces: string[]): Promise<AccountSummary[]>;
533 /** Every workspace worth reaching out to, most urgent first. */
534 signals(): Promise<Signal[]>;
535 /** The business at a glance. */
536 overview(): Promise<Overview>;
537 /** A workspace's sales record. */
538 sales(workspace: string): Promise<SalesRecord>;
539 setSales(workspace: string, record: { stage: string; owner?: string | null; nextStep?: string | null; nextAt?: string | null }, by: string): Promise<Result<SalesRecord>>;
540 addNote(workspace: string, text: string, by: string): Promise<Result<SalesRecord>>;
541 /** A workspace's invoices from g1t, for staff. */
542 workspaceInvoices(workspace: string): Promise<WorkspaceInvoice[]>;
543 /** Every invoice g1t has sent, newest first. */
544 allInvoices(filter?: { status?: string; month?: string }): Promise<InvoiceSummary[]>;
545 /** Every change made in sudo and by Stripe, newest first, 100 at a time. */
546 audit(filter?: { by?: string; action?: string; before?: string }): Promise<AdminAction[]>;
547 /** Limit and overage requests, with each workspace's history; `open` by default. */
548 limitRequests(status?: "open" | "approved" | "declined" | "all"): Promise<LimitRequestReview[]>;
549 /** Approve (at the amount asked, or another) or decline; the owner is told in the app and by email. */
550 decideLimitRequest(id: string, decision: "approve" | "decline", amountMicros: number | null, note: string, by: string): Promise<Result<LimitRequest>>;
551 /** The Overages queue. */
552 overages(): Promise<Overage[]>;
553 /** A goodwill credit; no amount is the one-click credit. Larger, or a second in 12 months, needs a reason. */
554 goodwill(workspace: string, amountMicros: number | null, reason: string, by: string, day?: string | null): Promise<Result<LedgerEntry>>;
555 /** Workspaces spending in the last day, fastest first. */
556 velocity(): Promise<Velocity[]>;
557 /** Money that reached g1t outside the card pages, such as a bank transfer: entered as a payment. */
558 recordPayment(workspace: string, amountMicros: number, reference: string, note: string, by: string): Promise<Result<LedgerEntry>>;
559 /** Costs & margin: Cloudflare's bill against what g1t charged, over the last `days` (7 to 90, 30 by default). */
560 costs(days?: number): Promise<CostsReport>;
561 /** The open margin alerts, for the banner on every page. */
562 costAlerts(): Promise<MarginAlert[]>;
563 /** g1t's own spend against its caps: the daily breaker and comped budgets. */
564 spendCaps(): Promise<SpendCaps>;
565 /** Lets hosted-model runs start again for the rest of today (UTC); needs a note. */
566 liftBreaker(note: string, by: string): Promise<Result<SpendCaps>>;
567 /** Approve or reject a price proposal; a rejection needs a note. An approved rise waits out the notice period. */
568 decideProposal(id: string, decision: "approve" | "reject", note: string, by: string): Promise<Result<PriceProposal>>;
569 setCostSettings(settings: CostSettings, by: string): Promise<Result<CostSettings>>;
570 setCostMapping(mapping: CostMappingInput, by: string): Promise<Result<CostMapping>>;
571 /** Reads Cloudflare's bill and reconciles now, as the daily run does. */
572 runCosts(by: string): Promise<Result<CostsRun>>;
573}
574
575/** How much a workspace has earned g1t's trust with money. */
576export type Trust = "new" | "paid" | "established" | "reviewed" | "internal";
577
578/**
579 * How far a workspace's unpaid usage has gone this month, and where its
580 * work stops: past `ceilingMicros`, no new sandboxes, builds or app
581 * requests. Usage counts at its cost to g1t or its charge, whichever is
582 * more, so it counts while g1t is free too.
583 */
584export type Limit = {
585 workspace: string;
586 /** The account that pays: the workspace's own (`ws_<slug>`), or its enterprise's. */
587 account: string;
588 accountName: string;
589 trust: Trust;
590 exposureMicros: number;
591 /** The lower of g1t's ceiling and the owner's spend limit; null for g1t's own. */
592 ceilingMicros: number | null;
593 trustCeilingMicros: number | null;
594 spendLimitMicros: number | null;
595 state: "ok" | "warning" | "stopped";
596 message: string | null;
597 /** Charged this month: what the spend limit is measured against. */
598 spentMicros?: number;
599 /** True while the owners have not chosen a limit, so the automatic one applies: $200, or twice last month's spend. */
600 defaultSpendLimit?: boolean;
601 /** The most owners may set their own limit to without asking: the highest ceiling ever, plus what is prepaid. */
602 availableMicros?: number | null;
603 /** How the ceiling grows from here, in a sentence. */
604 growth?: string | null;
605 /** Paid in advance and not used yet; raises what can be used before work stops by as much. */
606 prepaidMicros?: number;
607 /** The highest ceiling the workspace has had. */
608 maxCeilingMicros?: number | null;
609 /** The most owners may raise the limit to themselves, once: twice the highest ceiling. Null once used. */
610 raiseOnceMicros?: number | null;
611 /** When the one-time raise was used. */
612 raisedAt?: string | null;
613 /** A paid workspace's first billing cycle, on the starting ceiling. */
614 firstMonth?: boolean;
615};
616
617/** One metered unit: what it costs g1t and what it is sold at; the price follows the cost. */
618export type Price = {
619 meter:
620 | "sandbox_second"
621 | "build_second"
622 | "app_requests"
623 | "app_cpu"
624 | "app_month"
625 | "custom_domain_month"
626 | "private_storage"
627 | "embedding_tokens"
628 | "scan_cpu"
629 | "scan_rows"
630 | string;
631 title: string;
632 unit: string;
633 costMicros: number;
634 markupPercent: number;
635 priceMicros: number;
636 /** `list`: Cloudflare's published price. `cloudflare`: measured from Cloudflare's bill. */
637 source: "list" | "cloudflare" | string;
638 checkedAt: string | null;
639 updatedAt: string;
640};
641
642export type PriceChange = {
643 meter: string;
644 oldCostMicros: number;
645 newCostMicros: number;
646 markupPercent: number;
647 /** The markup before, when the change was to the markup rather than the cost. */
648 oldMarkupPercent?: number;
649 reason: string;
650 createdAt: string;
651 /** When a change still to come takes effect: a rise is announced before it is charged. */
652 effectiveAt?: string;
653};
654
655export type PriceBook = {
656 prices: Price[];
657 changes: PriceChange[];
658 modelMarginPercent: number;
659 /** Every plan, as sold now. */
660 plans?: FeaturePlan[];
661 /** What is free, and the capped budgets that pay for it. */
662 free?: FreeTier | null;
663};
664
665/** One kind of meter's usage this month, from `usage_meters`. */
666export type MeterUsage = {
667 /** `agents`, `builds`, `requests`, `domains`, `git_storage` or `search_scans`. */
668 key: string;
669 label: string;
670 /** At price (cost plus 20%, on the account's terms), before what paid for it. */
671 micros: number;
672 /** How much, when it is known: `12 runs`, `41 build minutes`. */
673 quantity?: string | null;
674};
675
676/** What g1t gives without a plan; each is paid for by a capped budget. */
677export type FreeTier = {
678 /** Each new workspace's trial credit, once. */
679 trialWorkspaceMicros: number;
680 /** Trial grants each month, in all; new trials wait when it is spent. */
681 trialMonthlyPoolMicros: number;
682 /** g1t's open-source pool each month, and any one repository's share. */
683 ossPoolMicros: number;
684 ossRepoMicros: number;
685 /** Private repository storage free for every workspace. Past it, the plan pays; a free workspace's pushes stop. */
686 freePrivateStorageBytes: number;
687 /** Days of audit log a free workspace keeps. */
688 auditRetentionDays: number;
689 /** Days of audit log the g1t plan keeps, and g1t's own and enterprise workspaces; longer by arrangement. */
690 planAuditRetentionDays?: number;
691 /** The smallest amount a card is charged when a month closes; less carries over. */
692 minChargeMicros: number;
693 /** Git operations free for every workspace each month. Past it, the plan pays; a free workspace is slowed down. */
694 gitOperationsIncluded?: number;
695 /** A new paid workspace's ceiling in its first month. */
696 paidStartCeilingMicros?: number;
697 /** The most a one-click goodwill credit can cost g1t. */
698 overageForgiveCostMicros?: number;
699};
700
701/**
702 * A workspace's trial credit: one grant per workspace, made the first time
703 * it uses something, out of a pool that resets each calendar month. Mirrors
704 * `Trial` in `crates/contracts/src/billing.rs`.
705 */
706export type Trial = {
707 open: boolean;
708 usedMicros: number;
709 limitMicros: number;
710 /** No longer used: trials do not end on a date. */
711 endsAt: string | null;
712 /** Why it is closed: `off`, `used` (this workspace's grant is spent) or `pool` (this month's are given out). */
713 reason: "off" | "ended" | "used" | "pool" | null;
714 /** Whether the workspace has its grant already. */
715 granted?: boolean;
716 /** With `pool`: when new trials start again, the first of next month. */
717 waitsUntil?: string | null;
718};
719
720/**
721 * What a workspace pays a monthly price for: the g1t plan (`plan`). Deployments
722 * are part of it; `has_feature` for `deployments` answers whether the workspace
723 * has the plan. Mirrors `Feature` in `crates/contracts/src/billing.rs`.
724 */
725export type Feature = "plan" | "deployments";
726
727/**
728 * What deployments cost g1t, in millionths of a dollar: fallbacks for when
729 * billing's price book cannot be read. Not an allowance: on the plan every
730 * unit is metered from the first, at cost plus 20%, and drawn from the
731 * plan's included usage first. Projects, previews and the apps behind them
732 * are not metered at all. Mirrors `deployment_costs`.
733 */
734export const DEPLOYMENT_COSTS = {
735 microsPerMillionRequests: 300_000,
736 microsPerMillionCpuMs: 20_000,
737 /** One second of a build's sandbox: a fallback; billing charges the price book's `build_second`. */
738 microsPerBuildSecond: 15,
739 /** One custom domain for a month. */
740 microsPerDomainMonth: 100_000,
741} as const;
742
743export type FeaturePlan = {
744 feature: Feature;
745 title: string;
746 /** Charged every month while the plan is on, in cents. */
747 monthlyCents: number;
748 /** What the price includes, one line each. */
749 includes: string[];
750 /** How usage past the allowance is charged. */
751 overage: string;
752};
753
754export type SubscriptionStatus = "active" | "canceling" | "past_due" | "canceled";
755
756export type Subscription = {
757 feature: Feature;
758 status: SubscriptionStatus;
759 /** RFC 3339: when the period paid for ends. */
760 periodEnd: string | null;
761 startedBy: string;
762 startedAt: string;
763};
764
765/** A feature as a workspace sees it. */
766export type FeatureState = {
767 plan: FeaturePlan;
768 subscription: Subscription | null;
769 /** Whether the feature works for the workspace now. */
770 on: boolean;
771 /** On without a plan: comped terms, or given by g1t. Nothing to pay or turn off. */
772 included?: boolean;
773};
774
775export interface BillingApi {
776 status(): Promise<BillingStatus>;
777 /** Members of the workspace only. */
778 account(workspace: string, viewer: Viewer): Promise<Result<BillingAccount>>;
779 /** Newest first. Members of the workspace only. */
780 ledger(workspace: string, viewer: Viewer): Promise<Result<LedgerEntry[]>>;
781 /** A month of the ledger, grouped by `day` (default) or `project`. Members only. */
782 statement(workspace: string, viewer: Viewer, month?: string | null, group?: "day" | "project"): Promise<Result<Statement>>;
783 /** One statement line's entries, 50 at a time; `before` is the last id seen. */
784 statementEntries(
785 workspace: string,
786 viewer: Viewer,
787 filter: { month: string; kind: string; day?: string | null; project?: string | null; before?: string | null },
788 ): Promise<Result<LedgerEntry[]>>;
789 /** What the workspace's agents cost since `since`, broken down. Members only. */
790 usage(workspace: string, viewer: Viewer, since: string): Promise<Result<Usage>>;
791 /**
792 * The model tokens the workspace's runs used, day by day over the last
793 * `days` (42, at most 366), for everyone or for one `person`. Members
794 * only; a member may ask only for themselves, an owner for anyone.
795 */
796 tokenUsage(workspace: string, viewer: User, options?: { person?: string; days?: number }): Promise<Result<TokenUsage>>;
797 /**
798 * What one model answer used, added to its run's count for the day. The
799 * model proxy sends it; for usage views only, as runs are priced from AI
800 * Gateway. False when there was nothing to count.
801 */
802 recordTokens(usage: {
803 workspace: string;
804 /** The model session's id, one per run. */
805 session: string;
806 /** The person the run is for, by username. */
807 person?: string | null;
808 model: string;
809 tier?: "small" | "large" | null;
810 input: number;
811 output: number;
812 cacheRead: number;
813 cacheWrite: number;
814 }): Promise<Result<boolean>>;
815 /**
816 * Prepays usage ($25 at least) and returns the page to send the person to:
817 * by card with 3-D Secure, or by bank transfer from $1,000. Owners only.
818 * The payment's id comes back to `returnUrl` as `session`.
819 */
820 checkout(
821 actor: User,
822 workspace: string,
823 amountCents: number,
824 returnUrl: string,
825 method?: "card" | "bank_transfer",
826 ): Promise<Result<{ url: string }>>;
827 /**
828 * Stripe's hosted billing page for the workspace: card, invoices, billing
829 * email and address. g1t never handles card numbers. Owners only.
830 */
831 billingPortal(actor: User, workspace: string, returnUrl: string): Promise<Result<{ url: string }>>;
832 /** Credits a payment once the processor says it was made. Safe to repeat. */
833 confirm(workspace: string, viewer: Viewer, session: string): Promise<Result<BillingAccount>>;
834 /**
835 * Whether a workspace may start an agent now, asked before anything is
836 * opened for it. A failure, with the reason to show, when it has no credit.
837 */
838 canStart(workspace: string): Promise<Result<boolean>>;
839 /** A workspace's free allowance on g1t's hosted models; `exempt` are open to them anyway. */
840 trial(workspace: string, exempt: string[]): Promise<Trial>;
841 /**
842 * Asks whether a workspace may start an agent and opens the run it will be
843 * charged for. Null when billing is off; a failure when there is no credit.
844 */
845 /** Every paid feature and the workspace's plan for each. Members only. */
846 features(workspace: string, viewer: Viewer): Promise<Result<FeatureState[]>>;
847 /**
848 * Starts the card page for a feature's monthly plan. Owners only. The
849 * page's id comes back to `returnUrl` as `session`.
850 */
851 subscribe(actor: User, workspace: string, feature: Feature, returnUrl: string): Promise<Result<{ url: string }>>;
852 /** Turns the feature on once the plan is paid for. Safe to repeat. */
853 confirmSubscription(workspace: string, viewer: Viewer, session: string): Promise<Result<FeatureState>>;
854 /** Ends a plan at the end of its period, or (`resume`) takes that back. Owners only. */
855 cancelSubscription(actor: User, workspace: string, feature: Feature, resume?: boolean): Promise<Result<FeatureState>>;
856 /** Whether a feature works for a workspace now; a failure with the reason when not. */
857 hasFeature(workspace: string, feature: Feature): Promise<Result<boolean>>;
858 /**
859 * Usage past a plan's allowance, charged from credit at cost plus the
860 * margin, once per `reference`. False if it was charged before.
861 */
862 chargeFeature(charge: {
863 workspace: string;
864 feature: Feature;
865 costMicros: number;
866 description: string;
867 repo?: string | null;
868 reference: string;
869 /** For a build: how long it ran, so the plan's included build time pays for what it can. */
870 buildSeconds?: number | null;
871 }): Promise<Result<boolean>>;
872 /**
873 * What a source cost g1t so far this month, so the workspace's limit
874 * counts it now. Replaces the last report. Billing charges `context`
875 * and `security` itself once the month is over; `deployments` charges
876 * its own.
877 */
878 notePending(
879 workspace: string,
880 source: "deployments" | "domains" | "context" | "security",
881 costMicros: number,
882 /** How much of it, for the Billing page: `1.2 million requests and 3.4 million CPU ms`. */
883 detail?: string | null,
884 ): Promise<boolean>;
885 /**
886 * This month's usage, one line per kind of meter, at what it is charged
887 * before the plan's included usage or a pool paid for it. Members only.
888 */
889 usageMeters(workspace: string, viewer: Viewer): Promise<Result<MeterUsage[]>>;
890 /** What the workspace may do now: its plan, caps, pause, trial, and what the plan gives it. */
891 entitlements(workspace: string): Promise<Entitlements>;
892 /**
893 * Holds a start's estimated cost before the work starts. A failure's code says why not:
894 * `paused`, `limit`, `not_paid`, `trial_used` or `oss_pool_empty`, with a message for the owner.
895 */
896 reserve(reservation: {
897 workspace: string;
898 repo: RepoPath;
899 public: boolean;
900 kind: ComputeKind;
901 /** The most the work is expected to cost g1t, before the margin. */
902 estimateMicros: number;
903 }): Promise<Result<ReservationHeld>>;
904 /** Releases a reservation's hold with what the work cost g1t, before the margin. Safe to repeat. */
905 settle(reservationId: string, actualMicros: number): Promise<Result<boolean>>;
906 /** Stripe's page to save and verify a card (3-D Secure, never charged). Owners only. */
907 cardCheck(actor: User, workspace: string, returnUrl: string): Promise<Result<{ url: string }>>;
908 /** Records the card check once Stripe says it passed, and grants the trial if it can. Safe to repeat. */
909 confirmCardCheck(workspace: string, viewer: Viewer, session: string): Promise<Result<Entitlements>>;
910 /** An owner asks for a higher limit, or for help with usage past what was meant. */
911 requestLimit(
912 actor: User,
913 workspace: string,
914 request: { kind: "limit" | "overage"; amountMicros: number; reason: string; expectedMonthlyMicros: number },
915 ): Promise<Result<LimitRequest>>;
916 /** The workspace's requests and their answers, newest first. Members only. */
917 limitRequests(workspace: string, viewer: Viewer): Promise<Result<LimitRequest[]>>;
918 /**
919 * The owners' own caps on agents: one run's spend ($0.10 to $100) and one issue's ($1 to $1,000).
920 * Null goes back to the default ($2 and $10). A cap staff set wins. Owners only.
921 */
922 setCaps(actor: User, workspace: string, caps: { runCapMicros: number | null; issueCapMicros: number | null }): Promise<Result<Entitlements>>;
923 /** An owner's answer to a spend spike: keep going for 24 hours, or stop. */
924 confirmSpike(actor: User, workspace: string, keepGoing: boolean): Promise<Result<Entitlements>>;
925 /** Every metered price and the recent changes. Public. */
926 prices(): Promise<PriceBook>;
927 /** A workspace's limit, for its members. */
928 limit(workspace: string, viewer: Viewer): Promise<Result<Limit>>;
929 /** The same, for the services that enforce it. */
930 checkLimit(workspace: string): Promise<Result<Limit>>;
931 /**
932 * The owners' own monthly limit, up to what is available; null goes back
933 * to the default, and `useFullLimit` uses everything available. Owners only.
934 */
935 setSpendLimit(
936 actor: User,
937 workspace: string,
938 spendLimitMicros: number | null,
939 useFullLimit?: boolean,
940 /** Use the one-time raise: up to twice the highest ceiling, once per workspace. */
941 raiseOnce?: boolean,
942 ): Promise<Result<Limit>>;
943 /** The workspace's invoices from g1t, newest first. Members only. */
944 invoices(workspace: string, viewer: Viewer): Promise<Result<WorkspaceInvoice[]>>;
945 /**
946 * How long a sandbox ran for a workspace, reported when it stops. Its
947 * cost is recorded and every second is charged, from the first. False if
948 * `reference` was recorded before.
949 */
950 recordSandbox(usage: {
951 workspace: string;
952 seconds: number;
953 description: string;
954 repo?: string | null;
955 reference: string;
956 /** What ran; checks, workflows and the merge queue on public repositories may use the open-source pool. */
957 kind?: ComputeKind | null;
958 /** vCPU-seconds used, when the sandbox can tell: the run is priced on its own CPU. */
959 cpuSeconds?: number | null;
960 /** The reservation it started under, settled with this cost. */
961 reservationId?: string | null;
962 /** It ran on one of the workspace's self-hosted runners: its minutes go on usage at $0. */
963 selfHosted?: boolean;
964 /** The machine it ran on, by label (`g1t-4core`); absent, the standard one. */
965 instance?: string | null;
966 }): Promise<Result<boolean>>;
967 startRun(run: {
968 workspace: string;
969 repo: RepoPath;
970 number: number;
971 task: string;
972 model: string;
973 /** `workspace` when the run uses the workspace's own model provider. */
974 billedTo?: "g1t" | "workspace";
975 /** The model session's id, so the run can be settled at AI Gateway's price. */
976 session?: string | null;
977 /** `small` or `large`: the tier g1t routed the run to, on its hosted models. */
978 tier?: "small" | "large" | null;
979 }): Promise<Result<RunTicket | null>>;
980}
981
982
983/** One slice of usage: what it was for, what it cost, how many runs. */
984export type UsageSlice = { key: string; micros: number; runs: number };
985
986/** The model tokens runs used over a window of days. */
987export type TokenUsage = {
988 /** `YYYY-MM-DD`, the first day counted. */
989 since: string;
990 /** The window's length: 42 unless asked, 366 at most. */
991 days: number;
992 /** Null for the whole workspace. */
993 person: string | null;
994 totalTokens: number;
995 inputTokens: number;
996 outputTokens: number;
997 cacheReadTokens: number;
998 cacheWriteTokens: number;
999 /** What those runs were charged, as `usage` measures it. */
1000 costMicros: number;
1001 /** Days in the window with any tokens. */
1002 activeDays: number;
1003 /** Every day in the window, oldest first, zeros included. */
1004 byDay: { day: string; tokens: number }[];
1005};
1006
1007/** What a workspace's agents cost over a period. */
1008export type Usage = {
1009 since: string;
1010 /** Charged, including g1t's margin. */
1011 spentMicros: number;
1012 /** What g1t's model provider charged, before the margin. */
1013 costMicros: number;
1014 /** What runs on the workspace's own provider cost there, estimated. Not charged by g1t. */
1015 providerMicros: number;
1016 /** What the runs used, at cost: g1t's models and the workspace's own provider together. */
1017 usedMicros: number;
1018 /** g1t charges nothing for now; the slices then measure usage at cost. */
1019 free: boolean;
1020 runs: number;
1021 /** Spend per day and task, keyed `YYYY-MM-DD/task`. */
1022 byDay: UsageSlice[];
1023 byTask: UsageSlice[];
1024 byRepo: UsageSlice[];
1025 /** Keyed `namespace/name#number`. */
1026 byPull: UsageSlice[];
1027 byModel: UsageSlice[];
1028 /** Credit bought in the period. */
1029 addedMicros: number;
1030};
1031
1032/** One of g1t's products (a "bucket") on one day. Money in micros. */
1033export type CostDay = { day: string; bucket: string; cfCostMicros: number; ownCostMicros: number; valueMicros: number; cashMicros: number };
1034
1035/** One product over the range: what customers were charged at price against what it cost. */
1036export type ProductMargin = {
1037 bucket: string;
1038 title: string;
1039 /** Cloudflare's bill, or g1t's own figure where Cloudflare does not bill it (`costSource`). */
1040 costMicros: number;
1041 cfCostMicros: number;
1042 ownCostMicros: number;
1043 valueMicros: number;
1044 marginMicros: number;
1045 marginPercent: number | null;
1046 costSource: "cloudflare" | "ledger" | string;
1047 /** Running g1t, paid for by the plan. */
1048 overhead: boolean;
1049};
1050
1051/** All of g1t: money in (usage and the plan) against every cost. */
1052export type OverallMargin = { usageMicros: number; plansMicros: number; costMicros: number; marginMicros: number; marginPercent: number | null };
1053
1054/** A count, cost or leak that does not add up. */
1055export type CostDrift = {
1056 bucket: string;
1057 title: string;
1058 kind: "count" | "cost" | "leak" | string;
1059 ours: number;
1060 cloudflare: number;
1061 deltaPercent: number | null;
1062 detail: string;
1063 foundAt: string;
1064};
1065
1066export type MarginAlert = {
1067 id: string;
1068 kind: "margin" | "overall" | "leak" | "drift" | "workspace" | string;
1069 /** The product, or the workspace. */
1070 subject: string;
1071 detail: string;
1072 since: string;
1073 openedAt: string;
1074 emailedAt: string | null;
1075};
1076
1077/** A change to a price, measured from what Cloudflare charged. */
1078export type PriceProposal = {
1079 id: string;
1080 meter: string;
1081 title: string;
1082 unit: string;
1083 currentCostMicros: number;
1084 proposedCostMicros: number;
1085 changePercent: number;
1086 markupPercent: number;
1087 reason: string;
1088 source: "keeper" | "reconciler" | string;
1089 /** Far off the current cost: look before approving. */
1090 suspect: boolean;
1091 status: "open" | "applied" | "approved" | "rejected" | "superseded" | string;
1092 createdAt: string;
1093 decidedAt: string | null;
1094 decidedBy: string | null;
1095 note: string | null;
1096 effectiveAt: string | null;
1097};
1098
1099/** One version of one meter's price; never changed once written. */
1100export type PriceVersion = {
1101 id: string;
1102 meter: string;
1103 version: number;
1104 costMicros: number;
1105 markupPercent: number;
1106 priceMicros: number;
1107 effectiveAt: string;
1108 reason: string;
1109 createdBy: string;
1110 appliedAt: string | null;
1111};
1112
1113export type WorkspaceCost = { workspace: string; costMicros: number; revenueMicros: number; internal: boolean };
1114
1115export type CostLineSummary = {
1116 product: string;
1117 meter: string;
1118 rawName: string;
1119 unit: string;
1120 source: string;
1121 quantity: number;
1122 costMicros: number;
1123 /** Absent when no mapping claims it. */
1124 bucket: string | null;
1125};
1126
1127export type CostMapping = {
1128 product: string;
1129 meter: string;
1130 bucket: string;
1131 priceMeter: string | null;
1132 ownMeter: string | null;
1133 scaleToOwn: boolean;
1134 driftPercent: number;
1135 note: string;
1136 updatedAt: string;
1137 updatedBy: string;
1138};
1139
1140export type CostMappingInput = {
1141 product: string;
1142 meter: string;
1143 bucket?: string;
1144 priceMeter?: string | null;
1145 ownMeter?: string | null;
1146 scaleToOwn?: boolean;
1147 driftPercent?: number | null;
1148 note?: string;
1149 remove?: boolean;
1150};
1151
1152export type CostSettings = {
1153 autoApply: boolean;
1154 autoApplyPercent: number;
1155 noticeDays: number;
1156 marginFloorPercent: number;
1157 alertDays: number;
1158 minDailyCostMicros: number;
1159 anomalyFactor: number;
1160 anomalyFloorMicros: number;
1161};
1162
1163export type CostsReport = {
1164 configured: boolean;
1165 fetchedAt: string | null;
1166 since: string;
1167 until: string;
1168 days: CostDay[];
1169 products: ProductMargin[];
1170 overall: OverallMargin;
1171 drift: CostDrift[];
1172 alerts: MarginAlert[];
1173 proposals: PriceProposal[];
1174 versions: PriceVersion[];
1175 topWorkspaces: WorkspaceCost[];
1176 lines: CostLineSummary[];
1177 mappings: CostMapping[];
1178 settings: CostSettings;
1179 /** g1t's own spend against its two caps. */
1180 caps: SpendCaps;
1181};
1182
1183/** What g1t pays for itself, at cost, against its caps (billing's `budget`). */
1184export type SpendCaps = {
1185 /** Today (UTC), YYYY-MM-DD, and this month, YYYY-MM. */
1186 day: string;
1187 month: string;
1188 /** What g1t paid for itself today across every workspace. */
1189 todayMicros: number;
1190 /** `PLATFORM_DAILY_SPEND_CAP_MICROS`; 0: no breaker. */
1191 dailyCapMicros: number;
1192 /** New hosted-model agent runs g1t would pay for are paused. */
1193 tripped: boolean;
1194 trippedAt: string | null;
1195 liftedBy: string | null;
1196 liftedAt: string | null;
1197 liftNote: string | null;
1198 /** This month so far, by what paid: comped, trial, oss, given, unpaid. */
1199 monthBuckets: { bucket: string; title: string; micros: number }[];
1200 comped: CompedBudget[];
1201 /** Free workspaces' share of reconciled costs this month (git, storage, platform). */
1202 freeTierMicros: number;
1203 /** `CLOUDFLARE_FIXED_MONTHLY_MICROS`: Cloudflare subscriptions, an estimate. */
1204 fixedMonthlyMicros: number;
1205 /** Money in this month, through the last reconciled day. */
1206 revenueMicros: number;
1207};
1208
1209/** A comped account's monthly budget, at cost. */
1210export type CompedBudget = {
1211 account: string;
1212 name: string;
1213 usedMicros: number;
1214 /** 0: no budget. */
1215 ceilingMicros: number;
1216 /** `COMPED_MONTHLY_CEILING_MICROS`, not the account's own limit. */
1217 defaultCeiling: boolean;
1218 /** 50, 75, 90, 100, or 0. */
1219 level: number;
1220};
1221
1222export type CostsRun = { lines: number; days: number; proposals: number; alerts: number; problems: string[] };