g1t/crates/contracts/src/billing.rs

2,695 lines97,103 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.

Agents as a team: lifecycle, merge queue, billing and a new shell1//! The billing service: what agents cost, charged to the workspace they
2//! worked for.
3//!
4//! A workspace buys credit and each agent run deducts what it cost, plus
5//! g1t's margin. With no credit, no agent starts. Money is held in
6//! millionths of a US dollar, so that a run costing a fraction of a cent is
7//! recorded exactly.
8//!
9//! Each `*Args` struct is the argument of the method of the same name,
10//! served at `POST /rpc/<method>`.
11
12use serde::{Deserialize, Serialize};
13
14use crate::repos::RepoPath;
15use crate::{User, Viewer};
16
17/// Millionths of a US dollar in one dollar.
18pub const MICROS_PER_DOLLAR: i64 = 1_000_000;
19
20/// Whether workspaces are charged for agents at all, and with real money.
21/// `status` takes nothing and returns this.
22#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]
23pub struct Status {
24 /// False when no payment provider is configured: nothing is charged,
25 /// and who may run agents is decided some other way.
26 pub enabled: bool,
27 /// False while the payment provider is in its test mode, where cards
28 /// are not real.
29 pub live: bool,
Free while g1t is being built out; agents can check out their own forks30 /// True while g1t is being built out: runs are recorded, with what
31 /// they cost, but nothing is charged and no credit is needed. Not a
32 /// promise that it stays free.
33 #[serde(default)]
34 pub free: bool,
Agents as a team: lifecycle, merge queue, billing and a new shell35}
36
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put37/// `trial`: a workspace's trial credit, so people can try g1t (its agents on
38/// g1t's hosted models among it) without a key or a card of their own. Each
39/// new workspace gets one grant of usage credit (`TRIAL_WORKSPACE_MICROS`),
40/// made when it first uses something, out of a pool for everyone that
41/// resets each calendar month (`TRIAL_MONTHLY_POOL_MICROS`). When this
42/// month's pool is given out, new grants wait for the next month. Returns
43/// `Trial`.
A free allowance on g1t's models, so anyone can try its agents44#[derive(Debug, Serialize, Deserialize)]
45#[serde(rename_all = "camelCase")]
46pub struct TrialArgs {
47 pub workspace: String,
48 /// Workspaces open to hosted models anyway, whose use is not counted
49 /// against the pool.
50 #[serde(default)]
51 pub exempt: Vec<String>,
52}
53
54#[derive(Clone, Debug, Serialize, Deserialize)]
55#[serde(rename_all = "camelCase")]
56pub struct Trial {
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put57 /// Whether its agents may use g1t's hosted models on the trial now: it
58 /// has credit left, or this month's pool can still grant it some.
A free allowance on g1t's models, so anyone can try its agents59 pub open: bool,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put60 /// What the trial has paid for so far, in millionths of a dollar.
A free allowance on g1t's models, so anyone can try its agents61 pub used_micros: i64,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put62 /// Its grant, or what it would be granted.
A free allowance on g1t's models, so anyone can try its agents63 pub limit_micros: i64,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put64 /// No longer used: the trial does not end on a date. Kept for older
65 /// readers; always null.
A free allowance on g1t's models, so anyone can try its agents66 pub ends_at: Option<String>,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put67 /// Why it is closed: `off` (no trials), `used` (this workspace's grant
68 /// is spent) or `pool` (this month's grants are all given out; see
69 /// `waits_until`). `ended` is no longer sent.
A free allowance on g1t's models, so anyone can try its agents70 pub reason: Option<String>,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put71 /// Whether the workspace has its grant already.
72 #[serde(default)]
73 pub granted: bool,
74 /// RFC 3339: when a workspace waiting for a grant can get one, the
75 /// first of next month. Only with reason `pool`.
76 #[serde(default)]
77 pub waits_until: Option<String>,
A free allowance on g1t's models, so anyone can try its agents78}
79
Agents as a team: lifecycle, merge queue, billing and a new shell80/// A workspace's standing.
81#[derive(Clone, Debug, Serialize, Deserialize)]
82#[serde(rename_all = "camelCase")]
83pub struct Account {
84 pub workspace: String,
85 /// Credit left, in millionths of a dollar. Can dip below zero by the
86 /// cost of the runs that were under way when it ran out.
87 pub balance_micros: i64,
88 pub status: Status,
89 /// What is added to a run's cost, in percent.
90 pub margin_percent: u32,
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace91 /// The card g1t charges as the workspace nears its limit and when a
92 /// month closes, if one is on file.
93 #[serde(default)]
94 pub card: Option<Card>,
Agents as a team: lifecycle, merge queue, billing and a new shell95}
96
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace97/// A saved card, as far as it is safe to show.
98#[derive(Clone, Debug, Serialize, Deserialize)]
99#[serde(rename_all = "camelCase")]
100pub struct Card {
101 /// `visa`, `mastercard`, ...
102 pub brand: String,
103 pub last4: String,
104 pub exp_month: u32,
105 pub exp_year: u32,
106}
107
108/// `billing_portal`: Stripe's hosted billing page for the workspace, where
109/// an owner adds or replaces the card, sees invoices and receipts, and sets
110/// the billing email and address. g1t never handles card numbers. Owners
111/// only. Returns `Outcome<Checkout>` (its `url`); Stripe sends them back
112/// to `return_url`.
113#[derive(Debug, Serialize, Deserialize)]
114pub struct BillingPortalArgs {
115 pub actor: User,
116 pub workspace: String,
117 pub return_url: String,
118}
119
120/// `admin_billing_link`: for staff to send a customer: their Stripe billing
121/// page. Returns `Outcome<BillingLink>`.
122#[derive(Debug, Serialize, Deserialize)]
123pub struct AdminBillingLinkArgs {
124 pub workspace: String,
125 pub by: String,
126}
127
128#[derive(Clone, Debug, Serialize, Deserialize)]
129#[serde(rename_all = "camelCase")]
130pub struct BillingLink {
131 /// A one-time session on Stripe's billing page, signed in already.
132 pub portal_url: String,
133 /// The billing page's sign-in page, which does not expire: the
134 /// customer signs in with the email Stripe has for them.
135 pub login_url: Option<String>,
136 pub customer_email: Option<String>,
137 pub expires_note: String,
138}
139
Agents as a team: lifecycle, merge queue, billing and a new shell140#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
141#[serde(rename_all = "snake_case")]
142pub enum EntryKind {
143 /// Credit bought with a card.
144 TopUp,
Paid features: a workspace turns on Deployments with a monthly plan145 /// An agent's run, or a paid feature's usage past its allowance.
Agents as a team: lifecycle, merge queue, billing and a new shell146 Usage,
147}
148
149/// One line of a workspace's statement.
150#[derive(Clone, Debug, Serialize, Deserialize)]
151#[serde(rename_all = "camelCase")]
152pub struct LedgerEntry {
153 pub id: String,
154 pub kind: EntryKind,
155 /// Positive for credit added, negative for usage.
156 pub amount_micros: i64,
157 pub description: String,
158 /// For usage: the repository and pull request the agent worked on.
159 pub repo: Option<String>,
160 pub number: Option<u32>,
161 /// For usage: `implement`, `review` or `update`.
162 pub task: Option<String>,
163 /// For usage: the model, by its public name.
164 pub model: Option<String>,
Integrations: your own model provider, alerts that open issues, tickets agents read165 /// For usage: `g1t` when g1t paid the model provider, `workspace` when
Prices are what g1t pays plus 20%, from the first second166 /// the workspace's own account did. Runs on the workspace's own
167 /// provider pay only their sandbox time now, so only older entries
168 /// are `workspace`.
Integrations: your own model provider, alerts that open issues, tickets agents read169 #[serde(default = "g1t")]
170 pub billed_to: String,
Agents as a team: lifecycle, merge queue, billing and a new shell171 /// For a top-up: the username of whoever paid.
172 pub created_by: Option<String>,
173 /// RFC 3339.
174 pub created_at: String,
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace175 /// The workspace the line belongs to, which tells an enterprise's
176 /// lines apart.
177 #[serde(default, skip_serializing_if = "Option::is_none")]
178 pub workspace: Option<String>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look179 /// For usage: what the g1t plan's monthly included usage paid of it.
180 /// The entry's `amount_micros` 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 put181 #[serde(default)]
182 pub credit_micros: i64,
183 /// For usage: what the workspace's trial credit paid of it.
184 #[serde(default)]
185 pub trial_micros: i64,
186 /// For usage: what g1t's open-source pool paid of it.
187 #[serde(default)]
188 pub oss_micros: i64,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look189 /// For usage: what g1t covered itself, such as the part of a free
190 /// workspace's last trial run that went past its trial credit.
191 #[serde(default)]
192 pub given_micros: i64,
Agents as a team: lifecycle, merge queue, billing and a new shell193}
194
Integrations: your own model provider, alerts that open issues, tickets agents read195fn g1t() -> String {
196 "g1t".to_owned()
197}
198
Agents as a team: lifecycle, merge queue, billing and a new shell199/// `account` (`Outcome<Account>`) and `ledger` (`Outcome<Vec<LedgerEntry>>`,
200/// newest first). Members of the workspace only.
201#[derive(Debug, Serialize, Deserialize)]
202pub struct AccountArgs {
203 pub workspace: String,
204 pub viewer: Viewer,
205}
206
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look207/// `checkout`: prepays usage: money paid in advance, drawn down by usage
208/// after the plan's included usage, which raises what can be used before
209/// work stops by the same amount at once. $25 at the least. By card, with
210/// 3-D Secure; from $1,000 also by bank transfer. Owners of the workspace
Agents as a team: lifecycle, merge queue, billing and a new shell211/// only. Returns `Outcome<Checkout>`.
212#[derive(Debug, Serialize, Deserialize)]
213#[serde(rename_all = "camelCase")]
214pub struct CheckoutArgs {
215 pub actor: User,
216 pub workspace: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look217 /// How much to prepay, in cents.
Agents as a team: lifecycle, merge queue, billing and a new shell218 pub amount_cents: u32,
219 /// Where the payment page sends the person afterwards. The payment's
220 /// id is appended as `session`.
221 pub return_url: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look222 /// `card` (the default) or `bank_transfer` (from $1,000): Stripe gives
223 /// the account details, and the money counts once it arrives.
224 #[serde(default)]
225 pub method: Option<String>,
Agents as a team: lifecycle, merge queue, billing and a new shell226}
227
228#[derive(Debug, Serialize, Deserialize)]
229pub struct Checkout {
230 /// The payment page to send the person to.
231 pub url: String,
232}
233
234/// `confirm`: credits a payment once the provider says it was made. Safe
235/// to call any number of times. Returns `Outcome<Account>`.
236#[derive(Debug, Serialize, Deserialize)]
237pub struct ConfirmArgs {
238 pub workspace: String,
239 pub viewer: Viewer,
240 /// The payment's id, as returned to `return_url`.
241 pub session: String,
242}
243
244/// `can_start`: whether a workspace may start an agent now, asked before
245/// anything is opened for it. Returns `Outcome<bool>`: a failure, with the
246/// reason to show, when it has no credit.
247#[derive(Debug, Serialize, Deserialize)]
248pub struct CanStartArgs {
249 pub workspace: String,
250}
251
252/// `start_run`: asks whether a workspace may start an agent, and opens the
253/// run it will be charged for. Called by the runner service. Returns
254/// `Outcome<Option<RunTicket>>`: no ticket when billing is off, a failure
255/// when the workspace has no credit.
256#[derive(Debug, Serialize, Deserialize)]
257pub struct StartRunArgs {
258 pub workspace: String,
259 pub repo: RepoPath,
260 pub number: u32,
261 /// `implement`, `review` or `update`.
262 pub task: String,
263 /// The model, by its public name.
264 pub model: String,
Integrations: your own model provider, alerts that open issues, tickets agents read265 /// `workspace` when the run uses the workspace's own model provider.
Models per workspace: several providers, routed by kind of work266 /// The runner, which is TypeScript, sends it as `billedTo`.
267 #[serde(default = "g1t", alias = "billedTo")]
Integrations: your own model provider, alerts that open issues, tickets agents read268 pub billed_to: String,
Prices keep themselves current with what g1t pays269 /// The model session's id, when its requests go through g1t's AI
270 /// Gateway: settling charges the run what the gateway priced them at.
271 #[serde(default)]
272 pub session: Option<String>,
Auto model routing: the cheapest tier that can do each piece of work, a retry goes up a tier, and each run records its tier273 /// `small` or `large`: the tier g1t routed the run to, when g1t pays
274 /// for its model. None on the workspace's own provider.
275 #[serde(default)]
276 pub tier: Option<String>,
Agents as a team: lifecycle, merge queue, billing and a new shell277}
278
279#[derive(Clone, Debug, Serialize, Deserialize)]
280#[serde(rename_all = "camelCase")]
281pub struct RunTicket {
282 pub run_id: String,
283 /// Lets the sandbox, and nothing else, report what this run cost.
284 pub token: String,
285}
286
287/// `finish_run`: what a run cost, as its sandbox reports it. Charged once.
288/// Returns `Outcome<bool>`.
289#[derive(Debug, Serialize, Deserialize)]
290#[serde(rename_all = "camelCase")]
291pub struct FinishRunArgs {
292 pub run_id: String,
293 pub token: String,
294 /// What the model provider charged, in US dollars.
295 pub cost_usd: f64,
296 #[serde(default)]
297 pub turns: u32,
298}
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request299
300
301/// `usage`: what a workspace's agents cost over a period, broken down.
302/// Members only. Returns `Outcome<Usage>`.
303#[derive(Debug, Serialize, Deserialize)]
304pub struct UsageArgs {
305 pub workspace: String,
306 pub viewer: Viewer,
307 /// RFC 3339: the start of the period. The period runs to now.
308 pub since: String,
309}
310
311/// One slice of usage: what it was for, what it cost, how many runs.
312#[derive(Clone, Debug, Serialize, Deserialize)]
313#[serde(rename_all = "camelCase")]
314pub struct UsageSlice {
315 pub key: String,
316 pub micros: i64,
317 pub runs: u32,
318}
319
320/// What a workspace's agents cost over a period.
321#[derive(Clone, Debug, Serialize, Deserialize)]
322#[serde(rename_all = "camelCase")]
323pub struct Usage {
324 pub since: String,
325 /// Charged, including g1t's margin.
326 pub spent_micros: i64,
Integrations: your own model provider, alerts that open issues, tickets agents read327 /// What g1t's model provider charged, before the margin.
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request328 pub cost_micros: i64,
Integrations: your own model provider, alerts that open issues, tickets agents read329 /// What runs on the workspace's own provider cost there, as the harness
330 /// estimated it. Not charged by g1t.
331 pub provider_micros: i64,
Usage while free is shown at cost; agents get rustfmt and clippy332 /// What the runs used, at cost: g1t's models and the workspace's own
333 /// provider together, whatever was charged for them.
334 pub used_micros: i64,
335 /// g1t charges nothing for now. The slices then measure usage at cost,
336 /// since every charge is zero.
337 pub free: bool,
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request338 pub runs: u32,
339 /// Spend per day (`YYYY-MM-DD`) and task, as `day/task` keys.
340 pub by_day: Vec<UsageSlice>,
341 /// Per task: implement, review, revise, update, plan.
342 pub by_task: Vec<UsageSlice>,
343 /// Per repository, `namespace/name`.
344 pub by_repo: Vec<UsageSlice>,
345 /// The pull requests that cost most, as `namespace/name#number`.
346 pub by_pull: Vec<UsageSlice>,
347 /// Per model, by its public name.
348 pub by_model: Vec<UsageSlice>,
349 /// Credit bought in the period.
350 pub added_micros: i64,
351}
Models per workspace: several providers, routed by kind of work352
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look353/// What a workspace pays a monthly price for. There is one plan, `plan`
354/// ("g1t"): a flat price per workspace, never per person, with included
355/// usage each month, more private storage, and deployments. Never free:
356/// `FREE_WHILE_BUILDING` does not cover it.
357///
358/// `deployments` is not sold on its own any more: it comes with the plan.
359/// A service that asks `has_feature` for it is told whether the workspace
360/// has the plan, and a Deployments subscription bought before the change
361/// keeps working until its period ends.
Paid features: a workspace turns on Deployments with a monthly plan362#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
363#[serde(rename_all = "snake_case")]
364pub enum Feature {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look365 /// The g1t plan. Older readers called it `team`.
366 #[serde(alias = "team")]
367 Plan,
368 /// Previews per pull request and production on g1t.page: part of the
369 /// plan.
Paid features: a workspace turns on Deployments with a monthly plan370 Deployments,
371}
372
373impl Feature {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look374 /// What is sold: the plan alone.
375 pub const ALL: [Feature; 1] = [Feature::Plan];
Paid features: a workspace turns on Deployments with a monthly plan376
377 pub fn as_str(self) -> &'static str {
378 match self {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look379 Feature::Plan => "plan",
Paid features: a workspace turns on Deployments with a monthly plan380 Feature::Deployments => "deployments",
381 }
382 }
383
384 pub fn parse(name: &str) -> Option<Feature> {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look385 match name {
386 "plan" | "team" => Some(Feature::Plan),
387 "deployments" => Some(Feature::Deployments),
388 _ => None,
389 }
Paid features: a workspace turns on Deployments with a monthly plan390 }
391
392 pub fn title(self) -> &'static str {
393 match self {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look394 Feature::Plan => "g1t",
Paid features: a workspace turns on Deployments with a monthly plan395 Feature::Deployments => "Deployments",
396 }
397 }
398}
399
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas400/// What deployments cost g1t, in millionths of a dollar: fallbacks for
401/// when billing's price book cannot be read. Nothing here is an allowance:
402/// on the plan every unit is metered from the first, at cost plus the
403/// margin, and drawn from the plan's included usage before anything is
404/// charged. Projects, previews and the apps behind them are not metered at
405/// all: Cloudflare's Workers for Platforms includes far more scripts than
406/// g1t runs, so an app costs g1t only the requests and CPU it answers with.
407pub mod deployment_costs {
408 /// Workers for Platforms: $0.30 per million requests.
Paid features: a workspace turns on Deployments with a monthly plan409 pub const MICROS_PER_MILLION_REQUESTS: i64 = 300_000;
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas410 /// $0.02 per million CPU milliseconds.
Paid features: a workspace turns on Deployments with a monthly plan411 pub const MICROS_PER_MILLION_CPU_MS: i64 = 20_000;
Deployments: a preview for every pull request, production on g1t.page412 /// What one second of a build's sandbox costs g1t (Cloudflare
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look413 /// Containers, standard-1: half a vCPU, 4 GiB, 8 GB disk), rounded up,
414 /// as the price keeper measured it on 2026-10-05 (14.5). Only a
415 /// fallback: billing charges builds at the price book's `build_second`,
416 /// which the keeper keeps current.
417 pub const MICROS_PER_BUILD_SECOND: i64 = 15;
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas418 /// What one custom hostname costs g1t a month (Cloudflare for SaaS):
419 /// $0.10.
Agents and memory, checks and conflicts, profiles, slug renames, custom domains420 pub const MICROS_PER_DOMAIN_MONTH: i64 = 100_000;
Paid features: a workspace turns on Deployments with a monthly plan421}
422
Every sandbox is metered by the second423/// `record_sandbox`: how long one sandbox ran for a workspace, reported by
Prices are what g1t pays plus 20%, from the first second424/// the runner when it stops. Every sandbox g1t starts for a workspace
425/// (agents, reviews, checks, the merge queue, workflow jobs) is metered by
426/// the second, from the first: recorded once per `reference`, with what it
427/// cost g1t, and charged at the price book's `sandbox_second` price unless
428/// `FREE_WHILE_BUILDING`. Deploy builds are charged by the Deployments plan
429/// instead.
Every sandbox is metered by the second430/// Returns `Outcome<bool>`: false if that reference was recorded before.
431#[derive(Debug, Serialize, Deserialize)]
432#[serde(rename_all = "camelCase")]
433pub struct RecordSandboxArgs {
434 pub workspace: String,
435 pub seconds: u32,
436 /// What ran, e.g. `Checks on acme/api#12`.
437 pub description: String,
438 /// `namespace/name`.
439 pub repo: Option<String>,
440 /// Unique to the run.
441 pub reference: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look442 /// What ran: `agent`, `check`, `workflow` or `queue`. Decides whether
443 /// g1t's open-source pool may pay for it (checks, workflows and the
444 /// merge queue on public repositories). Absent: not the pool.
445 #[serde(default)]
446 pub kind: Option<ComputeKind>,
447 /// The vCPU-seconds the sandbox used, when it can tell. With it, the
448 /// run is priced on its own CPU (`sandbox_base_second` per second plus
449 /// `sandbox_cpu_second` per vCPU-second); without it, at the average
450 /// (`sandbox_second`).
451 #[serde(default, alias = "cpu_seconds")]
452 pub cpu_seconds: Option<f64>,
453 /// The reservation the work started under, settled with this cost.
454 #[serde(default, alias = "reservation_id")]
455 pub reservation_id: Option<String>,
Fast pages, required checks on the branch, self-hosted runners, honest incidents456 /// It ran on one of the workspace's self-hosted runners: recorded as
457 /// self-hosted time, for the minutes, at $0.
458 #[serde(default, alias = "self_hosted")]
459 pub self_hosted: bool,
460 /// The machine it ran on, by label (`g1t-4core`); absent, the standard
461 /// one. A larger machine's memory and disk cost more each second.
462 #[serde(default)]
463 pub instance: Option<String>,
Every sandbox is metered by the second464}
465
Usage limits: unpaid usage can only go so far466/// How much a workspace has earned g1t's trust with money, which sets how
467/// far its unpaid usage can go before its work stops.
468#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
469#[serde(rename_all = "snake_case")]
470pub enum Trust {
471 /// No live payment yet: only a little past the free allowances.
472 New,
473 /// Has paid g1t real money: the ceiling grows with what it has paid.
474 Paid,
Two limits, real invoices, trust that grows by itself, sales signals475 /// Has paid steadily for months, with nothing disputed or declined:
476 /// the ceiling follows its monthly spend, up to $10,000, by itself.
477 Established,
Usage limits: unpaid usage can only go so far478 /// A ceiling g1t set by hand, after talking to the workspace.
479 Reviewed,
480 /// g1t's own workspaces: no ceiling.
481 Internal,
482}
483
484#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
485#[serde(rename_all = "snake_case")]
486pub enum LimitState {
487 Ok,
488 /// Past 80% of the ceiling.
489 Warning,
490 /// At or past it: no new sandboxes, builds or app requests.
491 Stopped,
492}
493
494/// How far a workspace's unpaid usage has gone this month, and where its
495/// work stops: like Fly's or Cloudflare's limits for new accounts, so no
496/// one runs up costs g1t cannot collect. Usage counts at what it cost g1t
497/// or what it is charged, whichever is more, so it counts while g1t is
498/// free too.
499#[derive(Clone, Debug, Serialize, Deserialize)]
500#[serde(rename_all = "camelCase")]
501pub struct Limit {
502 pub workspace: String,
Billing accounts, terms and enterprises; g1t is no longer free503 /// The account that pays, whose usage and payments the limit counts:
504 /// the workspace's own, or its enterprise's.
505 #[serde(default)]
506 pub account: String,
507 #[serde(default)]
508 pub account_name: String,
Usage limits: unpaid usage can only go so far509 pub trust: Trust,
510 /// Usage this month (UTC) less what was paid this month.
511 pub exposure_micros: i64,
512 /// Where work stops: the lower of g1t's ceiling and the owner's own
513 /// spend limit. None for g1t's own workspaces.
514 pub ceiling_micros: Option<i64>,
515 /// The ceiling g1t sets from `trust`.
516 pub trust_ceiling_micros: Option<i64>,
517 /// The owner's own monthly limit, if they set one.
518 pub spend_limit_micros: Option<i64>,
519 pub state: LimitState,
520 /// What to tell people when work is stopped or close to it.
521 pub message: Option<String>,
Two limits, real invoices, trust that grows by itself, sales signals522 /// Charged this month, which the spend limit is measured against.
523 #[serde(default)]
524 pub spent_micros: i64,
525 /// True while the owners have not chosen a spend limit of their own, so
526 /// the automatic one applies: $200, or twice last month's spend.
527 #[serde(default)]
528 pub default_spend_limit: bool,
529 /// The most the owners may set their own limit to: g1t's ceiling. To
530 /// go past it, they contact g1t.
531 #[serde(default)]
532 pub available_micros: Option<i64>,
533 /// How the ceiling grows from here, in a sentence.
534 #[serde(default)]
535 pub growth: Option<String>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look536 /// Money paid in advance and not used yet. It raises what can be used
537 /// before work stops by the same amount, at once.
538 #[serde(default)]
539 pub prepaid_micros: i64,
540 /// The highest ceiling the workspace has ever had. Owners may set their
541 /// spend limit anywhere up to it (plus what is prepaid) without asking.
542 #[serde(default)]
543 pub max_ceiling_micros: Option<i64>,
544 /// The most the owners may raise the limit to themselves, once, with
545 /// `raise_once`: twice the highest ceiling. None once it is used.
546 #[serde(default)]
547 pub raise_once_micros: Option<i64>,
548 /// When the one-time raise was used, RFC 3339.
549 #[serde(default)]
550 pub raised_at: Option<String>,
551 /// True in a paid workspace's first billing cycle, when the ceiling is
552 /// the starting one (`LIMIT_PAID_START_MICROS`).
553 #[serde(default)]
554 pub first_month: bool,
Usage limits: unpaid usage can only go so far555}
556
557/// `limit`: a workspace's limit, for its members. Returns `Outcome<Limit>`.
558#[derive(Debug, Serialize, Deserialize)]
559pub struct LimitArgs {
560 pub workspace: String,
561 pub viewer: Viewer,
562}
563
564/// `check_limit`: the same, for the services that enforce it. Returns
565/// `Outcome<Limit>`.
566#[derive(Debug, Serialize, Deserialize)]
567pub struct CheckLimitArgs {
568 pub workspace: String,
569}
570
Prices keep themselves current with what g1t pays571/// `note_pending`: usage this month that will be charged later, such as
572/// app traffic past a plan, so the workspace's limit counts it now. Each
573/// report replaces the last for that workspace, source and month. Called
574/// by the service that meters it. Returns `bool`.
575#[derive(Debug, Serialize, Deserialize)]
576#[serde(rename_all = "camelCase")]
577pub struct NotePendingArgs {
578 pub workspace: String,
Fast pages, required checks on the branch, self-hosted runners, honest incidents579 /// `deployments`, `security` (scans), `context` (search embeddings),
580 /// `storage` or `cache` (actions/cache, plan only). Billing charges
581 /// `security`, `context`, `storage` and `cache` itself once the month
582 /// is over; `deployments` charges its own.
Prices keep themselves current with what g1t pays583 pub source: String,
584 /// What it cost g1t so far this month, before the margin.
585 pub cost_micros: i64,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas586 /// How much of it, for the Billing page: `1.2 million requests and
587 /// 3.4 million CPU ms`, `2 custom domains`.
588 #[serde(default)]
589 pub detail: Option<String>,
Prices keep themselves current with what g1t pays590}
591
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas592/// `usage_meters`: this month's usage for a workspace, one line per kind
593/// of meter, at what it is charged (cost plus the margin, on the account's
594/// terms) before the plan's included usage, the trial or g1t's pools paid
595/// for any of it. Members only. Returns `Outcome<Vec<MeterUsage>>`.
596#[derive(Debug, Serialize, Deserialize)]
597pub struct UsageMetersArgs {
598 pub workspace: String,
599 pub viewer: Viewer,
600}
601
602/// One kind of meter's usage this month.
603#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
604#[serde(rename_all = "camelCase")]
605pub struct MeterUsage {
606 /// `agents` (agent runs, models and sandboxes for checks, workflows
607 /// and the merge queue), `builds`, `requests` (app requests and CPU),
608 /// `domains`, `git_storage` (git operations and private storage) or
609 /// `search_scans` (search embeddings and security scans).
610 pub key: String,
611 pub label: String,
612 /// At price, before what paid for it.
613 pub micros: i64,
614 /// How much, when it is known: `12 runs`, `41 build minutes`.
615 #[serde(default)]
616 pub quantity: Option<String>,
617}
618
Usage limits: unpaid usage can only go so far619/// `set_spend_limit`: the owner's own monthly ceiling, under g1t's; None
620/// removes it. Owners only. Returns `Outcome<Limit>`.
621#[derive(Debug, Serialize, Deserialize)]
622#[serde(rename_all = "camelCase")]
623pub struct SetSpendLimitArgs {
624 pub actor: User,
625 pub workspace: String,
Two limits, real invoices, trust that grows by itself, sales signals626 /// A monthly limit, at most what is available; None goes back to the
627 /// default.
Usage limits: unpaid usage can only go so far628 pub spend_limit_micros: Option<i64>,
Two limits, real invoices, trust that grows by itself, sales signals629 /// Use everything available, with no limit of their own.
630 #[serde(default)]
631 pub use_full_limit: bool,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look632 /// Use the one-time raise: up to twice the highest ceiling the
633 /// workspace has had, without asking. Once per workspace.
634 #[serde(default, alias = "raiseOnce")]
635 pub raise_once: bool,
Usage limits: unpaid usage can only go so far636}
637
Prices keep themselves current with what g1t pays638/// One metered unit: what it costs g1t, and what it is sold at. The price
639/// is always `cost × (100 + markup) / 100`, so it follows the cost.
640#[derive(Clone, Debug, Serialize, Deserialize)]
641#[serde(rename_all = "camelCase")]
642pub struct Price {
643 /// `sandbox_second`, `build_second`, `app_requests`, `app_cpu`, `app_month`.
644 pub meter: String,
645 pub title: String,
646 pub unit: String,
647 /// Millionths of a dollar per unit; may have a fraction.
648 pub cost_micros: f64,
649 pub markup_percent: u32,
650 pub price_micros: f64,
651 /// `list`: Cloudflare's published price. `cloudflare`: what Cloudflare
652 /// actually billed g1t, measured.
653 pub source: String,
654 /// When it was last checked against Cloudflare's bill.
655 pub checked_at: Option<String>,
656 pub updated_at: String,
657}
658
659impl Price {
660 pub fn price_for(cost_micros: f64, markup_percent: u32) -> f64 {
661 cost_micros * f64::from(100 + markup_percent) / 100.0
662 }
663}
664
665/// A cost that moved.
666#[derive(Clone, Debug, Serialize, Deserialize)]
667#[serde(rename_all = "camelCase")]
668pub struct PriceChange {
669 pub meter: String,
670 pub old_cost_micros: f64,
671 pub new_cost_micros: f64,
672 pub markup_percent: u32,
Prices are what g1t pays plus 20%, from the first second673 /// The markup before, when the change was to the markup rather than
674 /// to the cost. Absent when the markup stayed `markup_percent`.
675 #[serde(default, skip_serializing_if = "Option::is_none")]
676 pub old_markup_percent: Option<u32>,
Prices keep themselves current with what g1t pays677 pub reason: String,
678 pub created_at: String,
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily679 /// When a change still to come takes effect: a rise is announced
680 /// before it is charged. Absent for changes already made.
681 #[serde(default, skip_serializing_if = "Option::is_none")]
682 pub effective_at: Option<String>,
Prices keep themselves current with what g1t pays683}
684
685/// `prices`: every metered price and the recent changes. Public. Returns
686/// `PriceBook`.
687#[derive(Clone, Debug, Serialize, Deserialize)]
688#[serde(rename_all = "camelCase")]
689pub struct PriceBook {
690 pub prices: Vec<Price>,
691 pub changes: Vec<PriceChange>,
692 /// The margin on model usage, which is charged at what AI Gateway
693 /// priced each request at.
694 pub model_margin_percent: u32,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put695 /// Every plan, as it is sold now.
696 #[serde(default)]
697 pub plans: Vec<Plan>,
698 /// What is free, and what pays for it.
699 #[serde(default)]
700 pub free: Option<FreeTier>,
Prices keep themselves current with what g1t pays701}
702
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put703/// What g1t gives without a plan, each with what pays for it: a capped
704/// budget, never an open-ended allowance.
705#[derive(Clone, Debug, Default, Serialize, Deserialize)]
706#[serde(rename_all = "camelCase")]
707pub struct FreeTier {
708 /// Each new workspace's trial credit, once.
709 pub trial_workspace_micros: i64,
710 /// Trial grants each month, in all; new trials wait when it is spent.
711 pub trial_monthly_pool_micros: i64,
712 /// g1t's open-source pool each month, and any one repository's share.
713 pub oss_pool_micros: i64,
714 pub oss_repo_micros: i64,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas715 /// Private repository storage that is free for every workspace. Past
716 /// it, the plan pays at cost plus the margin; a free workspace's pushes
717 /// to private repositories stop instead.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put718 pub free_private_storage_bytes: i64,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look719 /// Days of audit log, the same on every plan.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put720 pub audit_retention_days: u32,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look721 /// The smallest amount a card is charged when a month closes; less
722 /// carries over. Charges at a limit always go through.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put723 pub min_charge_micros: i64,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas724 /// Git operations (clones, fetches and pushes through g1t) that are
725 /// free for every workspace each month. Past it, the plan pays at cost
726 /// plus the margin and is never slowed; a free workspace is slowed
727 /// down, never charged.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look728 #[serde(default)]
729 pub git_operations_included: u64,
730 /// A new paid workspace's ceiling in its first month.
731 #[serde(default)]
732 pub paid_start_ceiling_micros: i64,
733 /// The most a one-click goodwill credit can cost g1t.
734 #[serde(default)]
735 pub overage_forgive_cost_micros: i64,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put736}
737
Billing accounts, terms and enterprises; g1t is no longer free738/// Who pays: a billing account. Every workspace has one; by default its
739/// own. An enterprise account pays for several workspaces at once, as
740/// GitHub Enterprise does: one bill, one limit, one set of terms.
741#[derive(Clone, Debug, Serialize, Deserialize)]
742#[serde(rename_all = "camelCase")]
743pub struct BillingAccount {
744 /// `ws_<slug>` for a workspace's own account; `ent_…` for an enterprise.
745 pub id: String,
746 pub kind: AccountKind,
747 pub name: String,
748 pub terms: Terms,
749 /// The workspaces it pays for.
750 pub workspaces: Vec<String>,
Stripe webhooks, enterprise invoices, and sudo for both751 /// Where an enterprise's invoices go.
752 #[serde(default)]
753 pub billing_email: Option<String>,
754 /// An enterprise's invoices, newest first. Empty for a workspace's own.
755 #[serde(default)]
756 pub invoices: Vec<EnterpriseInvoice>,
Billing accounts, terms and enterprises; g1t is no longer free757 pub created_at: String,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put758 /// What g1t staff set for the account beyond its terms.
759 #[serde(default)]
760 pub allowances: Allowances,
761}
762
763/// Set per account by g1t staff in sudo, on top of its terms.
764#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
765#[serde(rename_all = "camelCase")]
766pub struct Allowances {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look767 /// The g1t plan without paying for its monthly price, such as for a
768 /// partner. Usage is charged as usual. Comped accounts have it anyway.
769 #[serde(default, alias = "team")]
770 pub plan: bool,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put771 /// Each of the account's public repositories' monthly cap on g1t's
772 /// open-source pool, in place of `OSS_REPO_MICROS`. None: the default.
773 #[serde(default)]
774 pub oss_repo_micros: Option<i64>,
775 /// The trial credit each of its workspaces gets, in place of
776 /// `TRIAL_WORKSPACE_MICROS`, outside the monthly pool. None: the default.
777 #[serde(default)]
778 pub trial_micros: Option<i64>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look779 /// Agents at once, in place of the plan's (2 in the first month or on
780 /// the trial, then 10). None: the default.
781 #[serde(default)]
782 pub max_concurrent_agents: Option<u32>,
783 /// One run's spend cap, in place of `RUN_CAP_MICROS` and the owners'
784 /// own. None: theirs, or the default.
785 #[serde(default)]
786 pub run_cap_micros: Option<i64>,
787 /// What the agents on one issue may spend in all, in place of
788 /// `ISSUE_CAP_MICROS` and the owners' own. None: theirs, or the default.
789 #[serde(default)]
790 pub issue_cap_micros: Option<i64>,
791 /// A hold g1t staff put on new compute, with why. None: no hold.
792 #[serde(default)]
793 pub hold: Option<String>,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put794}
795
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look796/// `admin_set_allowances`: the plan on or off without charge, overrides of
797/// the plan's caps, a hold, and the account's share of g1t's pools.
798/// Recorded with who and why. Returns `Outcome<BillingAccount>`.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put799#[derive(Debug, Serialize, Deserialize)]
800pub struct AdminSetAllowancesArgs {
801 pub id: String,
802 pub allowances: Allowances,
803 pub note: String,
804 pub by: String,
805}
806
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look807// --- Entitlements, and compute started under a reservation -----------------
808//
809// Every service that starts compute (sandboxes for agents, checks,
810// workflows and the merge queue; builds; models; semantic search) asks
811// billing first:
812//
813// 1. `entitlements { workspace }` says what the workspace may do at all:
814// its plan, whether it may start compute, its caps, and whether compute
815// is paused.
816// 2. `reserve { workspace, repo, public, kind, estimate_micros }` holds the
817// work's estimated cost against what may pay for it, so that starts at
818// the same moment cannot overshoot the ceiling together. It answers who
819// pays first, or refuses with a stable code and a message for the owner.
820// 3. `settle { reservation_id, actual_micros }` releases the hold once the
821// work is done. The charge itself goes on the ledger the usual way
822// (`finish_run`, `record_sandbox`, `charge_feature`, `note_pending`).
823//
824// A reservation never settled expires after `RESERVATION_HOURS`.
825
826/// A reservation that is never settled stops holding after this long.
827pub const RESERVATION_HOURS: u64 = 3;
828/// What a ceiling reads as when there is none (g1t's own workspaces): a
829/// billion dollars, which JavaScript holds exactly.
830pub const UNLIMITED_MICROS: i64 = 1_000_000_000_000_000;
831
832/// What a workspace pays g1t on, as far as compute is concerned.
833#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
834#[serde(rename_all = "snake_case")]
835pub enum PlanKind {
836 /// No plan: the forge is free; compute only from a trial or g1t's
837 /// open-source pool, after a card check.
838 Free,
839 /// The g1t plan, paid for (or given by g1t staff without its price).
840 Paid,
841 /// g1t's own workspaces and Flagon's (comped terms): the plan without
842 /// being charged. Usage is still recorded at what it cost.
843 Internal,
844 /// Paid for by an enterprise account, invoiced.
845 Enterprise,
846}
847
848impl PlanKind {
849 pub fn as_str(self) -> &'static str {
850 match self {
851 PlanKind::Free => "free",
852 PlanKind::Paid => "paid",
853 PlanKind::Internal => "internal",
854 PlanKind::Enterprise => "enterprise",
855 }
856 }
857
858 /// Whether usage past what is included may be charged (on demand).
859 pub fn on_demand(self) -> bool {
860 !matches!(self, PlanKind::Free)
861 }
862}
863
864/// What compute is for.
865#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
866#[serde(rename_all = "snake_case")]
867pub enum ComputeKind {
868 /// An agent's run: its sandbox and its model.
869 Agent,
870 /// Checks on a pull request.
871 Check,
872 /// A workflow job.
873 Workflow,
874 /// The merge queue's checks.
875 Queue,
876 /// A deployment's build.
877 Deploy,
878 /// Semantic search: embeddings in the context hub.
879 Embedding,
880}
881
882impl ComputeKind {
883 pub fn as_str(self) -> &'static str {
884 match self {
885 ComputeKind::Agent => "agent",
886 ComputeKind::Check => "check",
887 ComputeKind::Workflow => "workflow",
888 ComputeKind::Queue => "queue",
889 ComputeKind::Deploy => "deploy",
890 ComputeKind::Embedding => "embedding",
891 }
892 }
893
894 /// Whether g1t's open-source pool may pay for it on a public
895 /// repository: checks, workflows and the merge queue only.
896 pub fn open_source_pool(self) -> bool {
897 matches!(self, ComputeKind::Check | ComputeKind::Workflow | ComputeKind::Queue)
898 }
899}
900
901/// Who pays first for reserved work. What the first source cannot cover
902/// falls to the next, in this order.
903#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
904#[serde(rename_all = "snake_case")]
905pub enum PaidBy {
906 /// The plan's included usage this month.
907 Credit,
908 /// The workspace's one-time trial credit.
909 Trial,
910 /// g1t's open-source pool.
911 Oss,
912 /// Charged to the workspace, at cost plus the margin.
913 OnDemand,
914}
915
916/// `entitlements`: what a workspace may do now, for the services that
917/// start compute and the pages that show it. Takes `EntitlementsArgs`;
918/// returns `Entitlements`. No viewer: callers decide who sees it.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put919#[derive(Debug, Serialize, Deserialize)]
920pub struct EntitlementsArgs {
921 pub workspace: String,
922}
923
924#[derive(Clone, Debug, Serialize, Deserialize)]
925#[serde(rename_all = "camelCase")]
926pub struct Entitlements {
927 pub workspace: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look928 pub plan: PlanKind,
929 /// May start sandboxes, models, deployments and semantic search at all:
930 /// paid, internal and enterprise workspaces, or a free one with trial
931 /// credit left. A free workspace may still use the open-source pool
932 /// for checks, workflows and the merge queue on public repositories
933 /// after a card check; `reserve` decides that per start.
934 pub compute: bool,
935 /// The one-time trial credit left; 0 if none was granted or it is used.
936 pub trial_micros_left: i64,
937 /// A card check has been done. The trial and the open-source pool need
938 /// it.
939 pub trial_verified: bool,
940 /// A paid workspace still in its first billing cycle.
941 pub first_month: bool,
942 /// Agents at once: 2 in the first month or on the trial, 10 after;
943 /// staff can override it.
944 pub max_concurrent_agents: u32,
945 /// The longest one run may take: 60 minutes in the first month or on
946 /// the trial; otherwise the guardrails' own caps (`MAX_MINUTES`).
947 pub max_run_minutes: u32,
948 /// One run's spend cap (`RUN_CAP_MICROS`, $2 by default); staff can
949 /// override it.
950 pub run_cap_micros: i64,
951 /// What agents may spend on one issue in all (`ISSUE_CAP_MICROS`, $10
952 /// by default); the owners can set it (`set_caps`), and staff override.
953 pub issue_cap_micros: i64,
954 /// Where on-demand work stops: g1t's ceiling on usage not yet paid
955 /// for. `UNLIMITED_MICROS` for g1t's own workspaces; 0 for a free one,
956 /// which has no on-demand usage.
957 pub ceiling_micros: i64,
958 /// Usage not yet paid for this month, with prepayment taken off.
959 pub exposure_micros: i64,
960 /// Why new compute is paused, for the owner: the limit is reached, a
961 /// spend spike is waiting for an owner to confirm it, or g1t staff put
962 /// a hold on it. None when it is not.
963 pub paused: Option<String>,
964 // What the workspace's plan gives it, for its pages.
965 /// What open reservations hold now.
966 #[serde(default)]
967 pub held_micros: i64,
968 /// Paid in advance and not used yet.
969 #[serde(default)]
970 pub prepaid_micros: i64,
971 /// The plan's included usage each month, and what of it is used.
972 #[serde(default)]
973 pub included_micros: i64,
974 #[serde(default)]
975 pub included_used_micros: i64,
976 /// How far back the audit log can be read and exported: the same on
977 /// every plan.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put978 pub audit_retention_days: u32,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas979 /// Private repository storage that is free for every workspace: past
980 /// it, the plan pays for it 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 put981 pub free_private_storage_bytes: i64,
982 /// The last daily measure of the workspace's private repositories.
983 pub private_storage_bytes: i64,
984 /// What g1t's open-source pool paid for the workspace this month.
985 pub oss_paid_micros: i64,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas986 /// Deploy build time this month, every second of it metered.
987 #[serde(default)]
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put988 pub build_seconds_used: u32,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas989 /// Git operations this month, and how many are free for every
990 /// workspace (past it: metered on the plan, slowed when free).
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look991 #[serde(default)]
992 pub git_operations: u64,
993 #[serde(default)]
994 pub git_operations_included: u64,
995 /// 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 put996 pub min_charge_micros: i64,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look997 /// A spend spike waiting for an owner, or decided.
998 #[serde(default)]
999 pub spike: Option<Spike>,
1000 /// Where usage stands against what is included and the limits, from 50%.
1001 #[serde(default)]
1002 pub alerts: Vec<UsageAlert>,
1003}
1004
1005/// One level reached: 50, 75, 90 or 100 percent of something.
1006#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1007#[serde(rename_all = "camelCase")]
1008pub struct UsageAlert {
1009 /// `included` (the plan's included usage), `spend_limit` (the owners'
1010 /// own limit) or `ceiling` (g1t's, on usage not yet paid for).
1011 pub meter: String,
1012 pub level: u32,
1013 pub used_micros: i64,
1014 pub limit_micros: i64,
1015 pub message: String,
Billing accounts, terms and enterprises; g1t is no longer free1016}
1017
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1018/// An hour's spend well above the workspace's usual pace: new compute
1019/// waits until an owner says to keep going.
1020#[derive(Clone, Debug, Serialize, Deserialize)]
1021#[serde(rename_all = "camelCase")]
1022pub struct Spike {
1023 pub id: String,
1024 /// `open` (waiting for an owner), `continued` (an owner said keep
1025 /// going) or `stopped` (an owner said stop).
1026 pub status: String,
1027 /// The hour's spend when it was found, and the usual hour's.
1028 pub hour_micros: i64,
1029 pub average_micros: i64,
1030 pub detected_at: String,
1031 #[serde(default)]
1032 pub decided_by: Option<String>,
1033 #[serde(default)]
1034 pub decided_at: Option<String>,
1035 /// While continued: until when, unless spend doubles again first.
1036 #[serde(default)]
1037 pub until: Option<String>,
1038}
1039
1040/// `reserve`: holds an estimate of a start's cost before the work starts.
1041/// Returns `Outcome<Reservation>`, or a failure whose code says why not:
1042///
1043/// - `paused`: a spend spike waiting for an owner, or a hold.
1044/// - `limit`: the spend limit or g1t's ceiling would be passed.
1045/// - `not_paid`: no plan, and nothing else pays for this kind of work (or
1046/// no card check yet).
1047/// - `trial_used`: the one-time trial is spent.
1048/// - `oss_pool_empty`: the open-source pool, or the repository's share of
1049/// it, is spent this month.
1050///
1051/// The message says exactly what to do, with the page to do it on (such as
1052/// `/acme/-/billing`).
1053#[derive(Debug, Serialize, Deserialize)]
1054#[serde(rename_all = "camelCase")]
1055pub struct ReserveArgs {
1056 pub workspace: String,
1057 pub repo: RepoPath,
1058 /// Whether the repository is public: the open-source pool pays only for
1059 /// public repositories' checks, workflows and merge queue.
1060 pub public: bool,
1061 pub kind: ComputeKind,
1062 /// The most the work is expected to cost g1t, before the margin, in
1063 /// millionths of a dollar (billing adds the margin, as it does to every
1064 /// charge). For an agent, its model's average plus its sandbox for its
1065 /// whole time cap.
1066 #[serde(alias = "estimate_micros")]
1067 pub estimate_micros: i64,
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays1068 /// An agent run on g1t's hosted models (not the workspace's own
1069 /// provider). Unsaid, an agent run is taken to be one. g1t's daily
1070 /// spend breaker pauses these when g1t is paying for them.
1071 #[serde(default, alias = "hosted_model")]
1072 pub hosted_model: Option<bool>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1073}
1074
1075#[derive(Clone, Debug, Serialize, Deserialize)]
1076#[serde(rename_all = "camelCase")]
1077pub struct Reservation {
1078 pub id: String,
1079 pub paid_by: PaidBy,
1080 /// What is held, at cost; less than the estimate when a free
1081 /// workspace's last bit of trial credit is all there is.
1082 #[serde(default)]
1083 pub held_micros: i64,
1084 /// RFC 3339: when the hold lapses if never settled.
1085 #[serde(default)]
1086 pub expires_at: String,
1087}
1088
1089/// `settle`: releases a reservation's hold with what the work cost. The
1090/// charge goes on the ledger the usual way. Safe to repeat. Returns
1091/// `Outcome<bool>`: false if it was settled or had lapsed before.
1092#[derive(Debug, Serialize, Deserialize)]
1093#[serde(rename_all = "camelCase")]
1094pub struct SettleArgs {
1095 #[serde(alias = "reservation_id")]
1096 pub reservation_id: String,
1097 /// What the work cost g1t, before the margin.
1098 #[serde(alias = "actual_micros")]
1099 pub actual_micros: i64,
1100}
1101
1102// --- Card checks, the plan, prepayment -------------------------------------
1103
1104/// `card_check`: starts Stripe's page to save and verify a card: a setup
1105/// with 3-D Secure where the card supports it, which the card's bank sees
1106/// as a $0 or $1 authorization that is never charged. The trial and the
1107/// open-source pool need it, and it is the card the plan uses. Owners only.
1108/// Returns `Outcome<Checkout>`; the page's id comes back to `return_url` as
1109/// `session`, for `confirm_card_check`.
1110#[derive(Debug, Serialize, Deserialize)]
1111#[serde(rename_all = "camelCase")]
1112pub struct CardCheckArgs {
1113 pub actor: User,
1114 pub workspace: String,
1115 #[serde(alias = "return_url")]
1116 pub return_url: String,
1117}
1118
1119/// `confirm_card_check`: records the check once Stripe says the card was
1120/// verified, and grants the trial if the month's pool has room and the card
1121/// has not had one before. Safe to repeat. Returns `Outcome<Entitlements>`.
1122#[derive(Debug, Serialize, Deserialize)]
1123pub struct ConfirmCardCheckArgs {
1124 pub workspace: String,
1125 pub viewer: Viewer,
1126 pub session: String,
1127}
1128
1129// --- Limits: raising them, and spikes ---------------------------------------
1130
1131/// A request to g1t: a higher limit, or help with usage that went past
1132/// what was meant.
1133#[derive(Clone, Debug, Serialize, Deserialize)]
1134#[serde(rename_all = "camelCase")]
1135pub struct LimitRequest {
1136 pub id: String,
1137 pub workspace: String,
1138 /// `limit` (raise my limit) or `overage` (spent more than meant to).
1139 pub kind: String,
1140 /// The limit asked for; for an overage, what they think went wrong.
1141 pub amount_micros: i64,
1142 pub reason: String,
1143 pub expected_monthly_micros: i64,
1144 /// `open`, `approved` or `declined`.
1145 pub status: String,
1146 /// What was approved, which may differ from what was asked.
1147 #[serde(default)]
1148 pub decided_micros: Option<i64>,
1149 #[serde(default)]
1150 pub decided_by: Option<String>,
1151 /// The answer, as the owner sees it.
1152 #[serde(default)]
1153 pub answer: Option<String>,
1154 pub created_by: String,
1155 pub created_at: String,
1156 #[serde(default)]
1157 pub decided_at: Option<String>,
1158}
1159
1160/// `request_limit`: an owner asks g1t for more, or for help with usage past
1161/// what they meant. Answered within one business day, in the app and by
1162/// email. Owners only. Returns `Outcome<LimitRequest>`.
1163#[derive(Debug, Serialize, Deserialize)]
1164#[serde(rename_all = "camelCase")]
1165pub struct RequestLimitArgs {
1166 pub actor: User,
1167 pub workspace: String,
1168 /// `limit` or `overage`.
1169 pub kind: String,
1170 #[serde(alias = "amount_micros")]
1171 pub amount_micros: i64,
1172 pub reason: String,
1173 #[serde(default, alias = "expected_monthly_micros")]
1174 pub expected_monthly_micros: i64,
1175}
1176
1177/// `limit_requests`: a workspace's requests, newest first. Members only.
1178/// Returns `Outcome<Vec<LimitRequest>>`.
1179#[derive(Debug, Serialize, Deserialize)]
1180pub struct LimitRequestsArgs {
1181 pub workspace: String,
1182 pub viewer: Viewer,
1183}
1184
1185/// `confirm_spike`: an owner's answer to a spend spike. Keep going lifts the
1186/// pause for 24 hours, or until the hour's spend doubles again; stop keeps
1187/// new compute paused until an owner says to keep going. Owners only.
1188/// Returns `Outcome<Entitlements>`.
1189#[derive(Debug, Serialize, Deserialize)]
1190#[serde(rename_all = "camelCase")]
1191pub struct ConfirmSpikeArgs {
1192 pub actor: User,
1193 pub workspace: String,
1194 #[serde(alias = "keep_going")]
1195 pub keep_going: bool,
1196}
1197
1198/// `set_caps`: the owners' own caps on agents: one run's spend ($0.10 to
1199/// $100) and what the agents on one issue may spend in all ($1 to $1,000).
1200/// None goes back to the default ($2 and $10). A cap g1t staff set for the
1201/// account wins over both. Owners only. Returns `Outcome<Entitlements>`.
1202#[derive(Debug, Serialize, Deserialize)]
1203#[serde(rename_all = "camelCase")]
1204pub struct SetCapsArgs {
1205 pub actor: User,
1206 pub workspace: String,
1207 #[serde(default, alias = "run_cap_micros")]
1208 pub run_cap_micros: Option<i64>,
1209 #[serde(default, alias = "issue_cap_micros")]
1210 pub issue_cap_micros: Option<i64>,
1211}
1212
1213/// What staff see beside a request: the workspace's history with g1t.
1214#[derive(Clone, Debug, Default, Serialize, Deserialize)]
1215#[serde(rename_all = "camelCase")]
1216pub struct WorkspaceHistory {
1217 pub plan: Option<PlanKind>,
1218 /// The last six months, oldest first.
1219 pub months: Vec<MonthFigures>,
1220 /// Live payments that have cleared, and how many.
1221 pub paid_cleared_micros: i64,
1222 pub payments: u32,
1223 pub disputes: u32,
1224 pub declines: u32,
1225 /// The first time the workspace appears in billing, RFC 3339.
1226 pub first_seen: Option<String>,
1227 pub ceiling_micros: Option<i64>,
1228 pub max_ceiling_micros: Option<i64>,
1229 pub spend_limit_micros: Option<i64>,
1230 /// Recent velocity: the last hour, the usual hour over the last week,
1231 /// and the last 24 hours, at price.
1232 pub last_hour_micros: i64,
1233 pub average_hour_micros: i64,
1234 pub last_day_micros: i64,
1235}
1236
1237#[derive(Clone, Debug, Serialize, Deserialize)]
1238#[serde(rename_all = "camelCase")]
1239pub struct LimitRequestReview {
1240 pub request: LimitRequest,
1241 pub history: WorkspaceHistory,
1242}
1243
1244/// `admin_limit_requests`: requests for staff, oldest open first. Returns
1245/// `Vec<LimitRequestReview>`.
1246#[derive(Debug, Default, Serialize, Deserialize)]
1247pub struct AdminLimitRequestsArgs {
1248 /// `open` (the default), `approved`, `declined` or `all`.
1249 #[serde(default)]
1250 pub status: Option<String>,
1251}
1252
1253/// `admin_decide_limit_request`: approve (at the amount asked, or
1254/// `amount_micros`) or decline. The owner is told in the app and by email.
1255/// Recorded with who and why. Returns `Outcome<LimitRequest>`.
1256#[derive(Debug, Serialize, Deserialize)]
1257pub struct AdminDecideLimitRequestArgs {
1258 pub id: String,
1259 /// `approve` or `decline`.
1260 pub decision: String,
1261 #[serde(default)]
1262 pub amount_micros: Option<i64>,
1263 /// What the owner is told, beside the decision.
1264 #[serde(default)]
1265 pub note: String,
1266 pub by: String,
1267}
1268
1269/// `admin_record_payment`: money that reached g1t outside the card pages,
1270/// such as a bank transfer, entered as a payment (it raises the limit like
1271/// one). Recorded with who and the transfer's reference. Returns
1272/// `Outcome<LedgerEntry>`.
1273#[derive(Debug, Serialize, Deserialize)]
1274pub struct AdminRecordPaymentArgs {
1275 pub workspace: String,
1276 pub amount_micros: i64,
1277 /// The bank's reference for the transfer, or Stripe's payment id.
1278 pub reference: String,
1279 pub note: String,
1280 pub by: String,
1281}
1282
1283// --- Overages and goodwill (sudo) --------------------------------------------
1284
1285/// What a one-time goodwill credit would come to: g1t's margin on the
1286/// overage, always, plus as much of its underlying cost as the cap allows.
1287#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1288#[serde(rename_all = "camelCase")]
1289pub struct Goodwill {
1290 /// This month's charges above the workspace's typical month.
1291 pub overage_micros: i64,
1292 /// The part of the overage that is g1t's margin.
1293 pub margin_micros: i64,
1294 /// The part that is what g1t paid its providers.
1295 pub cost_micros: i64,
1296 /// The one-click credit: the margin plus the cost up to the cap.
1297 pub credit_micros: i64,
1298 /// Of the credit, the real cost g1t absorbs.
1299 pub absorbed_micros: i64,
1300}
1301
1302/// A workspace whose month went well past its usual, or hit a spike.
1303#[derive(Clone, Debug, Serialize, Deserialize)]
1304#[serde(rename_all = "camelCase")]
1305pub struct Overage {
1306 pub workspace: String,
1307 pub plan: PlanKind,
1308 /// The median of its last three months' charges.
1309 pub typical_month_micros: i64,
1310 pub this_month_micros: i64,
1311 /// What this month cost g1t, and what g1t keeps of it.
1312 pub cost_micros: i64,
1313 pub margin_micros: i64,
1314 /// A spike this month, if there was one.
1315 pub spike: Option<Spike>,
1316 /// The runs that cost the most this month.
1317 pub top_entries: Vec<LedgerEntry>,
1318 pub goodwill: Goodwill,
1319 /// False when a goodwill credit was given in the last 12 months.
1320 pub goodwill_available: bool,
1321 pub last_goodwill_at: Option<String>,
1322 /// An open overage request from the owner, if there is one.
1323 pub request: Option<LimitRequest>,
1324}
1325
1326/// `admin_overages`: the Overages queue. Returns `Vec<Overage>`.
1327#[derive(Debug, Default, Serialize, Deserialize)]
1328pub struct AdminOveragesArgs {}
1329
1330/// `admin_goodwill`: credits a workspace for accidental usage. With no
1331/// amount, the one-click credit (`Goodwill::credit_micros`), once per
1332/// workspace in 12 months. A larger amount, or a second within 12 months,
1333/// needs a typed reason. It shows on the statement as "Credit from g1t:
1334/// accidental usage on <date>". Returns `Outcome<LedgerEntry>`.
1335#[derive(Debug, Serialize, Deserialize)]
1336pub struct AdminGoodwillArgs {
1337 pub workspace: String,
1338 #[serde(default)]
1339 pub amount_micros: Option<i64>,
1340 /// Why, typed by staff; needed past the one-click credit.
1341 #[serde(default)]
1342 pub reason: String,
1343 /// The day the accidental usage happened, `YYYY-MM-DD`; today if absent.
1344 #[serde(default)]
1345 pub day: Option<String>,
1346 pub by: String,
1347}
1348
1349/// One workspace's recent pace, for sudo's velocity view.
1350#[derive(Clone, Debug, Serialize, Deserialize)]
1351#[serde(rename_all = "camelCase")]
1352pub struct Velocity {
1353 pub workspace: String,
1354 pub plan: PlanKind,
1355 pub last_hour_micros: i64,
1356 pub average_hour_micros: i64,
1357 pub last_day_micros: i64,
1358 pub this_month_micros: i64,
1359 /// The last hour over the usual hour; 0 with no history.
1360 pub ratio: f64,
1361 pub spike: Option<Spike>,
1362 pub first_seen: Option<String>,
1363}
1364
1365/// `admin_velocity`: workspaces spending in the last day, fastest first.
1366/// Returns `Vec<Velocity>`.
1367#[derive(Debug, Default, Serialize, Deserialize)]
1368pub struct AdminVelocityArgs {}
1369
Billing accounts, terms and enterprises; g1t is no longer free1370#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1371#[serde(rename_all = "snake_case")]
1372pub enum AccountKind {
1373 Workspace,
1374 Enterprise,
1375}
1376
1377/// How an account is charged. Standard unless g1t set otherwise in sudo.
1378#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1379#[serde(rename_all = "camelCase")]
1380pub struct Terms {
1381 pub kind: TermsKind,
1382 /// Off every usage charge, in percent. Custom terms only.
1383 #[serde(default)]
1384 pub discount_percent: u32,
1385 /// A ceiling on unpaid usage that replaces the one trust would give.
1386 #[serde(default)]
1387 pub ceiling_micros: Option<i64>,
1388 /// Why, for whoever looks next.
1389 #[serde(default)]
1390 pub note: String,
1391 /// When the terms end and the account goes back to standard.
1392 #[serde(default)]
1393 pub until: Option<String>,
1394 #[serde(default)]
1395 pub set_by: Option<String>,
1396 #[serde(default)]
1397 pub set_at: Option<String>,
1398}
1399
1400impl Terms {
1401 pub fn standard() -> Self {
1402 Terms {
1403 kind: TermsKind::Standard,
1404 discount_percent: 0,
1405 ceiling_micros: None,
1406 note: String::new(),
1407 until: None,
1408 set_by: None,
1409 set_at: None,
1410 }
1411 }
1412
1413 /// What a charge becomes under these terms.
1414 pub fn apply(&self, charge_micros: i64) -> i64 {
1415 match self.kind {
1416 TermsKind::Comped => 0,
1417 TermsKind::Custom => charge_micros * i64::from(100 - self.discount_percent.min(100)) / 100,
1418 TermsKind::Standard => charge_micros,
1419 }
1420 }
1421}
1422
1423#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1424#[serde(rename_all = "snake_case")]
1425pub enum TermsKind {
1426 /// Prices as published, limits by trust.
1427 Standard,
1428 /// Nothing charged; usage still recorded with its cost. Paid features
1429 /// are on without a plan. For g1t's own workspaces, partners, and the
1430 /// like.
1431 Comped,
1432 /// A discount, a ceiling, or both.
1433 Custom,
1434}
1435
Stripe webhooks, enterprise invoices, and sudo for both1436/// `stripe_webhook`: an event from Stripe, as the API received it: the raw
1437/// body and its `Stripe-Signature` header. Billing checks the signature
1438/// against the secret of the endpoint it registered, and handles each
1439/// event once. Returns `Outcome<bool>`: false for one already handled.
1440#[derive(Debug, Serialize, Deserialize)]
1441pub struct StripeWebhookArgs {
1442 pub payload: String,
1443 pub signature: String,
1444}
1445
1446/// `admin_stripe`: where billing stands with Stripe. Staff only. Returns
1447/// `StripeStatus`. With `setup: true`, registers (or replaces) the webhook
1448/// endpoint for the current mode first.
1449#[derive(Debug, Default, Serialize, Deserialize)]
1450pub struct AdminStripeArgs {
1451 #[serde(default)]
1452 pub setup: bool,
1453 #[serde(default)]
1454 pub by: Option<String>,
1455}
1456
1457#[derive(Clone, Debug, Serialize, Deserialize)]
1458#[serde(rename_all = "camelCase")]
1459pub struct StripeStatus {
1460 /// `test` or `live`, from the key; `off` without one.
1461 pub mode: String,
1462 pub webhook: Option<StripeWebhook>,
1463 /// The latest events handled, newest first.
1464 pub recent_events: Vec<StripeEventSummary>,
1465 /// What went wrong setting up, if it did.
1466 pub error: Option<String>,
1467}
1468
1469#[derive(Clone, Debug, Serialize, Deserialize)]
1470#[serde(rename_all = "camelCase")]
1471pub struct StripeWebhook {
1472 pub url: String,
1473 pub endpoint_id: String,
1474 pub events: Vec<String>,
1475 pub created_by: String,
1476 pub created_at: String,
1477}
1478
1479#[derive(Clone, Debug, Serialize, Deserialize)]
1480#[serde(rename_all = "camelCase")]
1481pub struct StripeEventSummary {
1482 pub id: String,
1483 pub kind: String,
1484 pub outcome: String,
1485 pub received_at: String,
1486}
1487
1488/// `admin_enterprise_billing`: where an enterprise's invoices go. Creates
1489/// or updates its Stripe customer. Returns `Outcome<BillingAccount>`.
1490#[derive(Debug, Serialize, Deserialize)]
1491pub struct AdminEnterpriseBillingArgs {
1492 pub id: String,
1493 pub email: String,
1494 pub by: String,
1495}
1496
1497/// `admin_invoice_enterprise`: sends an enterprise its invoice now, for
1498/// what its workspaces owe, rather than waiting for the month to close.
1499/// Returns `Outcome<EnterpriseInvoice>`.
1500#[derive(Debug, Serialize, Deserialize)]
1501pub struct AdminInvoiceEnterpriseArgs {
1502 pub id: String,
1503 pub by: String,
1504}
1505
1506/// An enterprise's invoice: one line per workspace, paid on Stripe.
1507#[derive(Clone, Debug, Serialize, Deserialize)]
1508#[serde(rename_all = "camelCase")]
1509pub struct EnterpriseInvoice {
1510 pub invoice_id: String,
1511 /// Stripe's page for it, where it is paid.
1512 pub hosted_url: Option<String>,
1513 pub amount_micros: i64,
1514 /// `open`, `paid`, `overdue` or `void`.
1515 pub status: String,
1516 pub period: String,
1517 pub lines: Vec<InvoiceLine>,
1518 pub created_at: String,
1519}
1520
1521#[derive(Clone, Debug, Serialize, Deserialize)]
1522#[serde(rename_all = "camelCase")]
1523pub struct InvoiceLine {
1524 pub workspace: String,
1525 pub amount_micros: i64,
1526}
1527
Two limits, real invoices, trust that grows by itself, sales signals1528/// A workspace's invoice from g1t: one per month, and one each time it is
1529/// charged near its limit. Itemised, charged to the card on file, and kept
1530/// in Stripe's billing page with its PDF.
1531#[derive(Clone, Debug, Serialize, Deserialize)]
1532#[serde(rename_all = "camelCase")]
1533pub struct WorkspaceInvoice {
1534 pub invoice_id: String,
1535 pub workspace: String,
1536 /// `month` (2026-10) or `threshold`.
1537 pub reason: String,
1538 pub period: String,
1539 pub amount_micros: i64,
1540 /// `paid`, `open`, `failed` or `void`.
1541 pub status: String,
1542 pub hosted_url: Option<String>,
1543 pub pdf_url: Option<String>,
1544 pub lines: Vec<InvoiceItem>,
1545 pub created_at: String,
1546}
1547
1548#[derive(Clone, Debug, Serialize, Deserialize)]
1549#[serde(rename_all = "camelCase")]
1550pub struct InvoiceItem {
1551 pub description: String,
1552 pub amount_micros: i64,
1553}
1554
1555/// `invoices`: a workspace's invoices from g1t, newest first. Members
1556/// only. Returns `Outcome<Vec<WorkspaceInvoice>>`.
1557#[derive(Debug, Serialize, Deserialize)]
1558pub struct InvoicesArgs {
1559 pub workspace: String,
1560 pub viewer: Viewer,
1561}
1562
1563/// `admin_workspace_invoices`: the same, for staff. Returns
1564/// `Vec<WorkspaceInvoice>`.
1565#[derive(Debug, Serialize, Deserialize)]
1566pub struct AdminWorkspaceInvoicesArgs {
1567 pub workspace: String,
1568}
1569
The statement is a month at a time, a line per kind of charge1570/// `statement`: a month of a workspace's ledger, grouped by day (or by
1571/// project) with a line per kind of charge. Members only. Returns
1572/// `Outcome<Statement>`.
1573#[derive(Debug, Serialize, Deserialize)]
1574pub struct StatementArgs {
1575 pub workspace: String,
1576 pub viewer: Viewer,
1577 /// YYYY-MM; this month when absent.
1578 #[serde(default)]
1579 pub month: Option<String>,
1580 /// `day` (the default) or `project`.
1581 #[serde(default)]
1582 pub group: Option<String>,
1583}
1584
1585#[derive(Clone, Debug, Serialize, Deserialize)]
1586#[serde(rename_all = "camelCase")]
1587pub struct Statement {
1588 pub month: String,
1589 /// Months with any entries, newest first.
1590 pub months: Vec<String>,
1591 pub groups: Vec<StatementGroup>,
1592 pub totals: StatementTotals,
1593}
1594
1595#[derive(Clone, Debug, Serialize, Deserialize)]
1596#[serde(rename_all = "camelCase")]
1597pub struct StatementGroup {
1598 /// The day (YYYY-MM-DD) or the project (`owner/name`, or empty).
1599 pub key: String,
1600 pub label: String,
1601 pub lines: Vec<StatementLine>,
1602 /// What the group's charges come to.
1603 pub charged_micros: i64,
1604}
1605
1606#[derive(Clone, Debug, Serialize, Deserialize)]
1607#[serde(rename_all = "camelCase")]
1608pub struct StatementLine {
1609 /// Agent runs, Sandbox time, Deployments, Payments, Credits from g1t,
Prices are what g1t pays plus 20%, from the first second1610 /// Refunds, and, for older entries, Runs on your own model provider.
The statement is a month at a time, a line per kind of charge1611 pub kind: String,
1612 pub count: u32,
1613 /// Charges positive; money in (payments, credits) negative.
1614 pub charged_micros: i64,
1615 pub cost_micros: i64,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1616 /// Of the usage on the line, what was paid for before it was charged:
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1617 /// by the plan's included usage, the trial credit, g1t's open-source
1618 /// pool, or g1t itself. Not in `charged_micros`.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1619 #[serde(default)]
1620 pub covered_micros: i64,
The statement is a month at a time, a line per kind of charge1621}
1622
1623#[derive(Clone, Debug, Serialize, Deserialize)]
1624#[serde(rename_all = "camelCase")]
1625pub struct StatementTotals {
1626 pub charged_micros: i64,
1627 pub paid_micros: i64,
1628 pub cost_micros: i64,
1629 pub entries: u32,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1630 /// What paid for usage before it was charged, one line per source,
1631 /// such as "Paid by g1t's open-source pool".
1632 #[serde(default)]
1633 pub covered: Vec<Covered>,
1634 /// Owed when the month closed but under the minimum charge, so it
1635 /// carries over to the next invoice. Zero when nothing carried.
1636 #[serde(default)]
1637 pub carried_micros: i64,
1638}
1639
1640/// One source that paid for usage before it was charged.
1641#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1642#[serde(rename_all = "camelCase")]
1643pub struct Covered {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1644 /// `included`, `trial`, `oss_pool` or `given`.
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1645 pub source: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1646 /// "Paid by your plan's included usage", "Paid by your trial credit",
1647 /// "Paid by g1t's open-source pool", "Covered by g1t".
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1648 pub label: String,
1649 pub micros: i64,
The statement is a month at a time, a line per kind of charge1650}
1651
1652/// `statement_entries`: one statement line's entries, newest first, 50 at
1653/// a time (`before` = the last id seen). Returns `Outcome<Vec<LedgerEntry>>`.
1654#[derive(Debug, Serialize, Deserialize)]
1655pub struct StatementEntriesArgs {
1656 pub workspace: String,
1657 pub viewer: Viewer,
1658 pub month: String,
1659 pub kind: String,
1660 #[serde(default)]
1661 pub day: Option<String>,
1662 #[serde(default)]
1663 pub project: Option<String>,
1664 #[serde(default)]
1665 pub before: Option<String>,
1666}
1667
Two limits, real invoices, trust that grows by itself, sales signals1668// --- Sales (sudo.g1t.sh) ------------------------------------------------------
1669//
1670// What staff need to know to reach out: who is growing, who is close to
1671// their limit, who was declined, who has become a steady customer. And what
1672// was done about it: a stage, an owner on g1t's side, a next step, notes.
1673
1674/// Why a workspace is worth a look.
1675#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1676#[serde(rename_all = "snake_case")]
1677pub enum SignalKind {
1678 /// At its limit, or its own spend limit: work is stopped.
1679 AtLimit,
1680 /// Past 80% of what is available to it: about to need more.
1681 NearCeiling,
1682 /// Its card was declined or a payment disputed.
1683 Declined,
1684 /// This month is well ahead of last month.
1685 Growing,
1686 /// Became Established: the ceiling now follows its spend.
1687 Established,
1688 /// Paid g1t for the first time.
1689 FirstPayment,
1690 /// Spending enough that custom terms or an enterprise may suit it.
1691 HighSpend,
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily1692 /// Costs g1t more on Cloudflare than it pays, over 30 days: a pricing
1693 /// gap or abuse to look at (billing's `margin`).
1694 CostOverRevenue,
Two limits, real invoices, trust that grows by itself, sales signals1695}
1696
1697#[derive(Clone, Debug, Serialize, Deserialize)]
1698#[serde(rename_all = "camelCase")]
1699pub struct Signal {
1700 pub workspace: String,
1701 pub kind: SignalKind,
1702 /// One sentence, with the figures.
1703 pub detail: String,
1704 /// The figure that matters, such as this month's spend.
1705 pub value_micros: i64,
1706 /// Its sales stage, if staff gave it one.
1707 pub stage: Option<String>,
1708 pub owner: Option<String>,
Billing lists every invoice and every staff change; signals carry follow-ups1709 #[serde(default)]
1710 pub next_step: Option<String>,
1711 /// When the next step is due, `YYYY-MM-DD`.
1712 #[serde(default)]
1713 pub next_at: Option<String>,
1714}
1715
1716/// `admin_invoices`: every invoice g1t has sent, workspaces' and
1717/// enterprises', newest first. Returns `Vec<InvoiceSummary>`.
1718#[derive(Debug, Default, Serialize, Deserialize)]
1719pub struct AdminInvoicesArgs {
1720 /// `paid`, `open`, `failed`, `overdue` or `void`.
1721 #[serde(default)]
1722 pub status: Option<String>,
1723 /// YYYY-MM, by when it was sent.
1724 #[serde(default)]
1725 pub month: Option<String>,
1726}
1727
1728#[derive(Clone, Debug, Serialize, Deserialize)]
1729#[serde(rename_all = "camelCase")]
1730pub struct InvoiceSummary {
1731 pub invoice_id: String,
1732 /// `workspace` or `enterprise`.
1733 pub kind: String,
1734 /// The workspace's slug, or the enterprise's account id.
1735 pub account: String,
1736 /// What to call it: the workspace, or the enterprise's name.
1737 pub name: String,
1738 pub reason: String,
1739 pub period: String,
1740 pub amount_micros: i64,
1741 pub status: String,
1742 pub hosted_url: Option<String>,
1743 pub created_at: String,
1744 pub paid_at: Option<String>,
1745}
1746
1747/// `admin_audit`: every change made in sudo, and by Stripe, newest first.
1748/// Returns `Vec<AdminAction>`.
1749#[derive(Debug, Default, Serialize, Deserialize)]
1750pub struct AdminAuditArgs {
1751 #[serde(default)]
1752 pub by: Option<String>,
1753 #[serde(default)]
1754 pub action: Option<String>,
1755 /// Only those before this time, for paging.
1756 #[serde(default)]
1757 pub before: Option<String>,
Two limits, real invoices, trust that grows by itself, sales signals1758}
1759
1760/// `admin_signals`: every workspace worth reaching out to, most urgent
1761/// first. Returns `Vec<Signal>`.
1762#[derive(Debug, Default, Serialize, Deserialize)]
1763pub struct AdminSignalsArgs {}
1764
1765/// What staff are doing about a workspace.
1766#[derive(Clone, Debug, Serialize, Deserialize)]
1767#[serde(rename_all = "camelCase")]
1768pub struct SalesRecord {
1769 pub workspace: String,
1770 /// `none`, `lead`, `contacted`, `negotiating`, `won`, `lost` or `churn_risk`.
1771 pub stage: String,
1772 /// The staff member looking after it.
1773 pub owner: Option<String>,
1774 pub next_step: Option<String>,
1775 /// RFC 3339 date.
1776 pub next_at: Option<String>,
1777 pub notes: Vec<SalesNote>,
1778 pub updated_at: Option<String>,
1779}
1780
1781#[derive(Clone, Debug, Serialize, Deserialize)]
1782#[serde(rename_all = "camelCase")]
1783pub struct SalesNote {
1784 pub id: String,
1785 pub text: String,
1786 pub by: String,
1787 pub created_at: String,
1788}
1789
1790/// `admin_sales`: a workspace's sales record. Returns `SalesRecord`.
1791#[derive(Debug, Serialize, Deserialize)]
1792pub struct AdminSalesArgs {
1793 pub workspace: String,
1794}
1795
1796/// `admin_set_sales`: its stage, owner and next step. Returns `Outcome<SalesRecord>`.
1797#[derive(Debug, Serialize, Deserialize)]
1798pub struct AdminSetSalesArgs {
1799 pub workspace: String,
1800 pub stage: String,
1801 #[serde(default)]
1802 pub owner: Option<String>,
1803 #[serde(default)]
1804 pub next_step: Option<String>,
1805 #[serde(default)]
1806 pub next_at: Option<String>,
1807 pub by: String,
1808}
1809
1810/// `admin_add_note`. Returns `Outcome<SalesRecord>`.
1811#[derive(Debug, Serialize, Deserialize)]
1812pub struct AdminAddNoteArgs {
1813 pub workspace: String,
1814 pub text: String,
1815 pub by: String,
1816}
1817
1818/// `admin_overview`: the business at a glance. Returns `Overview`.
1819#[derive(Debug, Default, Serialize, Deserialize)]
1820pub struct AdminOverviewArgs {}
1821
1822#[derive(Clone, Debug, Serialize, Deserialize)]
1823#[serde(rename_all = "camelCase")]
1824pub struct Overview {
1825 /// YYYY-MM.
1826 pub month: String,
1827 /// The last six months, oldest first, all workspaces together.
1828 pub months: Vec<MonthFigures>,
1829 /// This month by kind of usage: models, sandbox, deployments, plans.
1830 pub by_kind: Vec<KindFigures>,
1831 pub paying_workspaces: u32,
1832 pub stopped: u32,
1833 pub near_ceiling: u32,
1834 pub declined: u32,
1835 /// Sent and not yet paid, workspaces and enterprises.
1836 pub open_invoices_micros: i64,
1837 /// Follow-ups due today or earlier.
1838 pub follow_ups_due: u32,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1839 /// The capped budgets g1t pays from, this month.
1840 #[serde(default)]
1841 pub pools: Option<Pools>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1842 /// This month's revenue: usage charged plus the plan's price paid.
1843 #[serde(default)]
1844 pub revenue_micros: i64,
1845 /// Workspaces on the paid plan now, and what their price comes to a
1846 /// month.
1847 #[serde(default)]
1848 pub active_plans: u32,
1849 #[serde(default)]
1850 pub plan_mrr_micros: i64,
1851 /// What g1t gave this month, by source, apart from its margin.
1852 #[serde(default)]
1853 pub given: Vec<GivenFigures>,
1854 /// g1t's own and Flagon's workspaces this month: what their use cost,
1855 /// and why they are not charged.
1856 #[serde(default)]
1857 pub internal: Vec<InternalUse>,
1858 /// Open limit requests, and workspaces in the Overages queue.
1859 #[serde(default)]
1860 pub open_requests: u32,
1861 #[serde(default)]
1862 pub overages: u32,
1863 /// Spend spikes waiting for an owner.
1864 #[serde(default)]
1865 pub open_spikes: u32,
Two limits, real invoices, trust that grows by itself, sales signals1866}
1867
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1868/// What g1t gave this month from one source.
1869#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
1870#[serde(rename_all = "camelCase")]
1871pub struct GivenFigures {
1872 /// `internal`, `trial`, `oss_pool`, `goodwill` or `covered`.
1873 pub source: String,
1874 pub label: String,
1875 /// At price, and what it cost g1t.
1876 pub micros: i64,
1877 pub cost_micros: i64,
1878}
1879
1880/// One internal workspace's use this month.
1881#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
1882#[serde(rename_all = "camelCase")]
1883pub struct InternalUse {
1884 pub workspace: String,
1885 /// Why it is not charged: its terms' note.
1886 pub reason: String,
1887 pub cost_micros: i64,
1888 pub entries: u32,
1889}
1890
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put1891/// g1t's capped budgets for free usage, this calendar month (UTC).
1892#[derive(Clone, Debug, Default, Serialize, Deserialize)]
1893#[serde(rename_all = "camelCase")]
1894pub struct Pools {
1895 /// YYYY-MM.
1896 pub month: String,
1897 /// Trial grants made this month, against the month's pool.
1898 pub trial_granted_micros: i64,
1899 pub trial_pool_micros: i64,
1900 pub trial_grants: u32,
1901 /// What the open-source pool paid this month, against its cap.
1902 pub oss_used_micros: i64,
1903 pub oss_pool_micros: i64,
1904 /// Each public repository's monthly cap on the pool.
1905 pub oss_repo_micros: i64,
1906}
1907
Two limits, real invoices, trust that grows by itself, sales signals1908#[derive(Clone, Debug, Serialize, Deserialize)]
1909#[serde(rename_all = "camelCase")]
1910pub struct KindFigures {
1911 pub kind: String,
1912 pub charged_micros: i64,
1913 pub cost_micros: i64,
1914}
1915
Billing accounts, terms and enterprises; g1t is no longer free1916// --- Staff (sudo.g1t.sh) ------------------------------------------------------
1917//
1918// Called only by the sudo app, which only g1t staff can reach (behind
1919// Cloudflare Access). Each change names who made it, and is kept in the
1920// audit log.
1921
1922/// `admin_accounts`: every billing account, with where each stands this
1923/// month. Returns `Vec<AccountSummary>`.
1924#[derive(Debug, Default, Serialize, Deserialize)]
1925pub struct AdminAccountsArgs {
1926 #[serde(default)]
1927 pub query: Option<String>,
Stripe webhooks, enterprise invoices, and sudo for both1928 /// Exactly these workspaces' accounts, such as one page of sudo's
1929 /// list; every account with activity when absent.
1930 #[serde(default)]
1931 pub workspaces: Option<Vec<String>>,
Billing accounts, terms and enterprises; g1t is no longer free1932}
1933
1934#[derive(Clone, Debug, Serialize, Deserialize)]
1935#[serde(rename_all = "camelCase")]
1936pub struct AccountSummary {
1937 pub account: BillingAccount,
1938 pub limit: Limit,
1939 /// Charged this month, after terms.
1940 pub charged_micros: i64,
1941 /// What this month's usage cost g1t.
1942 pub cost_micros: i64,
1943 /// Paid, ever.
1944 pub paid_micros: i64,
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace1945 /// The same figures for each of the account's workspaces that has
1946 /// any, so staff can see what one member of an enterprise used.
1947 #[serde(default)]
1948 pub by_workspace: Vec<WorkspaceFigures>,
Two limits, real invoices, trust that grows by itself, sales signals1949 /// The last six months, oldest first, for trends.
1950 #[serde(default)]
1951 pub months: Vec<MonthFigures>,
1952}
1953
1954/// One month of an account's billing.
1955#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
1956#[serde(rename_all = "camelCase")]
1957pub struct MonthFigures {
1958 /// YYYY-MM.
1959 pub month: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1960 /// Usage charged, after what paid for it first.
Two limits, real invoices, trust that grows by itself, sales signals1961 pub charged_micros: i64,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1962 /// What usage cost g1t: only what g1t paid for, never a workspace's own
1963 /// model provider.
Two limits, real invoices, trust that grows by itself, sales signals1964 pub cost_micros: i64,
1965 pub paid_micros: i64,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1966 /// The plan's monthly price, paid.
1967 #[serde(default)]
1968 pub plans_micros: i64,
1969 /// What g1t gave, at price: internal (comped) use, trials, the
1970 /// open-source pool, goodwill credits and what g1t covered. Not margin.
1971 #[serde(default)]
1972 pub given_micros: i64,
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace1973}
1974
1975/// One workspace's share of an [`AccountSummary`].
1976#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
1977#[serde(rename_all = "camelCase")]
1978pub struct WorkspaceFigures {
1979 pub workspace: String,
1980 pub charged_micros: i64,
1981 pub cost_micros: i64,
1982 pub paid_micros: i64,
Billing accounts, terms and enterprises; g1t is no longer free1983}
1984
1985/// `admin_account`: one account in full. Returns `Outcome<AccountDetail>`.
1986#[derive(Debug, Serialize, Deserialize)]
1987pub struct AdminAccountArgs {
1988 /// An account id, or a workspace slug.
1989 pub id: String,
1990}
1991
1992#[derive(Clone, Debug, Serialize, Deserialize)]
1993#[serde(rename_all = "camelCase")]
1994pub struct AccountDetail {
1995 pub summary: AccountSummary,
1996 /// Each workspace's limit, for an enterprise.
1997 pub workspaces: Vec<Limit>,
1998 pub ledger: Vec<LedgerEntry>,
1999 pub audit: Vec<AdminAction>,
2000}
2001
2002/// `admin_set_terms`. Returns `Outcome<BillingAccount>`.
2003#[derive(Debug, Serialize, Deserialize)]
2004pub struct AdminSetTermsArgs {
2005 pub id: String,
2006 pub terms: Terms,
2007 pub by: String,
2008}
2009
2010/// `admin_create_enterprise`. Returns `Outcome<BillingAccount>`.
2011#[derive(Debug, Serialize, Deserialize)]
2012pub struct AdminCreateEnterpriseArgs {
2013 pub name: String,
2014 pub workspaces: Vec<String>,
2015 pub by: String,
2016}
2017
2018/// `admin_attach`: moves a workspace onto an enterprise account, or back
2019/// onto its own with `account: None`. Returns `Outcome<BillingAccount>`.
2020#[derive(Debug, Serialize, Deserialize)]
2021pub struct AdminAttachArgs {
2022 pub workspace: String,
2023 pub account: Option<String>,
2024 pub by: String,
2025}
2026
2027/// `admin_credit`: money g1t gives a workspace, such as a refund or a
2028/// goodwill credit. Returns `Outcome<LedgerEntry>`.
2029#[derive(Debug, Serialize, Deserialize)]
2030pub struct AdminCreditArgs {
2031 pub workspace: String,
2032 pub amount_micros: i64,
2033 pub note: String,
2034 pub by: String,
2035}
2036
2037/// One change made in sudo.
2038#[derive(Clone, Debug, Serialize, Deserialize)]
2039#[serde(rename_all = "camelCase")]
2040pub struct AdminAction {
2041 pub id: String,
2042 pub account: String,
2043 pub action: String,
2044 pub detail: String,
2045 pub by: String,
2046 pub created_at: String,
2047}
2048
Paid features: a workspace turns on Deployments with a monthly plan2049/// What a feature's plan costs and includes.
2050#[derive(Clone, Debug, Serialize, Deserialize)]
2051#[serde(rename_all = "camelCase")]
2052pub struct Plan {
2053 pub feature: Feature,
2054 pub title: String,
2055 /// Charged every month while the plan is on, in cents.
2056 pub monthly_cents: u32,
2057 /// What the monthly price includes, one line each, for people to read.
2058 pub includes: Vec<String>,
2059 /// How usage past the allowance is charged, for people to read.
2060 pub overage: String,
2061}
2062
2063#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
2064#[serde(rename_all = "snake_case")]
2065pub enum SubscriptionStatus {
2066 /// Paid up; the feature works.
2067 Active,
2068 /// Paid up to the end of the period, and ends then.
2069 Canceling,
2070 /// The last payment failed; the feature is off until it is paid.
2071 PastDue,
2072 /// Ended.
2073 Canceled,
2074}
2075
2076impl SubscriptionStatus {
2077 /// Whether the feature works in this state.
2078 pub fn on(self) -> bool {
2079 matches!(self, SubscriptionStatus::Active | SubscriptionStatus::Canceling)
2080 }
2081}
2082
2083/// A workspace's plan for one feature.
2084#[derive(Clone, Debug, Serialize, Deserialize)]
2085#[serde(rename_all = "camelCase")]
2086pub struct Subscription {
2087 pub feature: Feature,
2088 pub status: SubscriptionStatus,
2089 /// RFC 3339: when the period paid for ends, and the plan renews or
2090 /// ends.
2091 pub period_end: Option<String>,
2092 /// Username of whoever turned it on.
2093 pub started_by: String,
2094 /// RFC 3339.
2095 pub started_at: String,
2096}
2097
2098/// A feature as a workspace sees it: what it costs, and its plan if it has
2099/// one.
2100#[derive(Clone, Debug, Serialize, Deserialize)]
2101#[serde(rename_all = "camelCase")]
2102pub struct FeatureState {
2103 pub plan: Plan,
2104 pub subscription: Option<Subscription>,
2105 /// Whether the feature works for the workspace now.
2106 pub on: bool,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put2107 /// On without a plan: comped terms, or given by g1t. Nothing to pay
2108 /// and nothing to turn off.
2109 #[serde(default)]
2110 pub included: bool,
Paid features: a workspace turns on Deployments with a monthly plan2111}
2112
2113/// `features`: every paid feature and the workspace's plan for each.
2114/// Members only. Returns `Outcome<Vec<FeatureState>>`.
2115#[derive(Debug, Serialize, Deserialize)]
2116pub struct FeaturesArgs {
2117 pub workspace: String,
2118 pub viewer: Viewer,
2119}
2120
2121/// `subscribe`: starts the card page for a feature's monthly plan. Owners
2122/// only. Returns `Outcome<Checkout>`; the page's id comes back to
2123/// `return_url` as `session`, for `confirm_subscription`.
2124#[derive(Debug, Serialize, Deserialize)]
2125#[serde(rename_all = "camelCase")]
2126pub struct SubscribeArgs {
2127 pub actor: User,
2128 pub workspace: String,
2129 pub feature: Feature,
2130 pub return_url: String,
2131}
2132
2133/// `confirm_subscription`: turns the feature on once the processor says
2134/// the plan was paid for. Safe to call any number of times. Returns
2135/// `Outcome<FeatureState>`.
2136#[derive(Debug, Serialize, Deserialize)]
2137pub struct ConfirmSubscriptionArgs {
2138 pub workspace: String,
2139 pub viewer: Viewer,
2140 pub session: String,
2141}
2142
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look2143/// `close_workspace`: settles a workspace that is about to be deleted.
2144/// Owners only. Refused while it has an invoice that failed, while it
2145/// holds prepaid credit, or while it owes money it cannot be charged for
2146/// now; otherwise what it owes is invoiced to its card at once (no
2147/// minimum), its plan is cancelled at Stripe straight away, and its
2148/// account is marked closed, so the month-end close, autopay and limit
2149/// warnings pass it by. Its ledger, invoices and statements stay. With
2150/// `dry_run`, only says whether it could, changing nothing. Returns
2151/// `Outcome<bool>`.
2152#[derive(Debug, Serialize, Deserialize)]
2153#[serde(rename_all = "camelCase")]
2154pub struct CloseWorkspaceArgs {
2155 pub actor: User,
2156 pub workspace: String,
2157 #[serde(default)]
2158 pub dry_run: bool,
2159}
2160
Paid features: a workspace turns on Deployments with a monthly plan2161/// `cancel_subscription` (`resume` false) ends a plan at the end of the
2162/// period paid for; with `resume` true, takes that back. Owners only.
2163/// Returns `Outcome<FeatureState>`.
2164#[derive(Debug, Serialize, Deserialize)]
2165pub struct CancelSubscriptionArgs {
2166 pub actor: User,
2167 pub workspace: String,
2168 pub feature: Feature,
2169 #[serde(default)]
2170 pub resume: bool,
2171}
2172
2173/// `has_feature`: whether a feature works for a workspace now, asked by the
2174/// service that provides it before doing paid work. Returns
2175/// `Outcome<bool>`: a failure, with the reason to show, when it does not.
2176/// True everywhere when no card processor is configured.
2177#[derive(Debug, Serialize, Deserialize)]
2178pub struct HasFeatureArgs {
2179 pub workspace: String,
2180 pub feature: Feature,
2181}
2182
2183/// `charge_feature`: usage of a feature past its plan's allowance, charged
2184/// from the workspace's credit at cost plus the margin, whatever
2185/// `FREE_WHILE_BUILDING` says. Called by the service that provides it.
2186/// Charged once per `reference`. Returns `Outcome<bool>`: false if that
2187/// reference was charged before.
2188#[derive(Debug, Serialize, Deserialize)]
2189#[serde(rename_all = "camelCase")]
2190pub struct ChargeFeatureArgs {
2191 pub workspace: String,
2192 pub feature: Feature,
2193 /// What it cost g1t, in millionths of a dollar, before the margin.
2194 pub cost_micros: i64,
2195 pub description: String,
2196 /// `namespace/name`, when the usage was one repository's.
2197 pub repo: Option<String>,
2198 /// Unique to this charge, e.g. `deployments/acme/2026-10`.
2199 pub reference: String,
Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put2200 /// For a build: how long it ran. The plan's included build time this
2201 /// month pays for what it can, and only the rest of `cost_micros` is
2202 /// charged.
2203 #[serde(default)]
2204 pub build_seconds: Option<u32>,
Paid features: a workspace turns on Deployments with a monthly plan2205}
2206
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily2207// ---------------------------------------------------------------------
2208// Costs and margin: what Cloudflare charges g1t against what g1t
2209// charges (billing's costs.rs, margin.rs and pricing.rs). Staff only.
2210// ---------------------------------------------------------------------
2211
2212/// `admin_costs`: the Costs & margin page. Returns `CostsReport`.
2213#[derive(Debug, Default, Serialize, Deserialize)]
2214pub struct AdminCostsArgs {
2215 /// How many days back, 7 to 90; 30 when absent.
2216 #[serde(default)]
2217 pub days: Option<u32>,
2218}
2219
2220/// One of g1t's products on one day.
2221#[derive(Clone, Debug, Default, Serialize, Deserialize)]
2222#[serde(rename_all = "camelCase")]
2223pub struct CostDay {
2224 pub day: String,
2225 pub bucket: String,
2226 /// What Cloudflare charged g1t.
2227 pub cf_cost_micros: i64,
2228 /// What g1t's meters recorded it cost, at the price book's cost.
2229 pub own_cost_micros: i64,
2230 /// What customers were charged for it at price, before included
2231 /// usage, trials and pools paid for some.
2232 pub value_micros: i64,
2233 /// Of that, what workspaces paid.
2234 pub cash_micros: i64,
2235}
2236
2237/// One product over the range.
2238#[derive(Clone, Debug, Default, Serialize, Deserialize)]
2239#[serde(rename_all = "camelCase")]
2240pub struct ProductMargin {
2241 pub bucket: String,
2242 pub title: String,
2243 /// The cost the margin is taken from: Cloudflare's bill, or g1t's own
2244 /// figure for what Cloudflare does not bill (models).
2245 pub cost_micros: i64,
2246 pub cf_cost_micros: i64,
2247 pub own_cost_micros: i64,
2248 pub value_micros: i64,
2249 pub margin_micros: i64,
2250 pub margin_percent: Option<f64>,
2251 /// `cloudflare` or `ledger`.
2252 pub cost_source: String,
2253 /// Running g1t itself, paid for by the plan.
2254 pub overhead: bool,
2255}
2256
2257/// All of g1t over the range: money in against every cost.
2258#[derive(Clone, Debug, Default, Serialize, Deserialize)]
2259#[serde(rename_all = "camelCase")]
2260pub struct OverallMargin {
2261 /// What workspaces paid for usage, and for the plan.
2262 pub usage_micros: i64,
2263 pub plans_micros: i64,
2264 pub cost_micros: i64,
2265 pub margin_micros: i64,
2266 pub margin_percent: Option<f64>,
2267}
2268
2269/// A count, cost or leak that does not add up.
2270#[derive(Clone, Debug, Serialize, Deserialize)]
2271#[serde(rename_all = "camelCase")]
2272pub struct CostDrift {
2273 pub bucket: String,
2274 pub title: String,
2275 /// `count` (units g1t counted against Cloudflare's), `cost` (the bill
2276 /// against the price book's cost of the same usage), or `leak`.
2277 pub kind: String,
2278 pub ours: f64,
2279 pub cloudflare: f64,
2280 pub delta_percent: Option<f64>,
2281 pub detail: String,
2282 pub found_at: String,
2283}
2284
2285/// A margin alert, open while its condition lasts.
2286#[derive(Clone, Debug, Serialize, Deserialize)]
2287#[serde(rename_all = "camelCase")]
2288pub struct MarginAlert {
2289 pub id: String,
2290 /// `margin`, `overall`, `leak`, `drift` or `workspace`.
2291 pub kind: String,
2292 /// The product, or the workspace.
2293 pub subject: String,
2294 pub detail: String,
2295 pub since: String,
2296 pub opened_at: String,
2297 pub emailed_at: Option<String>,
2298}
2299
2300/// A change to a price the reconciler measured.
2301#[derive(Clone, Debug, Serialize, Deserialize)]
2302#[serde(rename_all = "camelCase")]
2303pub struct PriceProposal {
2304 pub id: String,
2305 pub meter: String,
2306 pub title: String,
2307 pub unit: String,
2308 pub current_cost_micros: f64,
2309 pub proposed_cost_micros: f64,
2310 pub change_percent: f64,
2311 pub markup_percent: u32,
2312 pub reason: String,
2313 /// `keeper` or `reconciler`.
2314 pub source: String,
2315 /// Far off the current cost: look before approving.
2316 pub suspect: bool,
2317 /// `open`, `applied`, `approved`, `rejected` or `superseded`.
2318 pub status: String,
2319 pub created_at: String,
2320 pub decided_at: Option<String>,
2321 pub decided_by: Option<String>,
2322 pub note: Option<String>,
2323 /// When it takes or took effect, once approved or applied.
2324 pub effective_at: Option<String>,
2325}
2326
2327/// One version of one meter's price. Never changed once written.
2328#[derive(Clone, Debug, Serialize, Deserialize)]
2329#[serde(rename_all = "camelCase")]
2330pub struct PriceVersion {
2331 pub id: String,
2332 pub meter: String,
2333 pub version: u32,
2334 pub cost_micros: f64,
2335 pub markup_percent: u32,
2336 pub price_micros: f64,
2337 pub effective_at: String,
2338 pub reason: String,
2339 pub created_by: String,
2340 /// When the price book took it on; absent while it waits for its date.
2341 pub applied_at: Option<String>,
2342}
2343
2344/// What a workspace cost g1t over the range, Cloudflare's costs shared
2345/// out by g1t's own meters, against what it paid.
2346#[derive(Clone, Debug, Serialize, Deserialize)]
2347#[serde(rename_all = "camelCase")]
2348pub struct WorkspaceCost {
2349 pub workspace: String,
2350 pub cost_micros: i64,
2351 pub revenue_micros: i64,
2352 /// One of g1t's own (comped) workspaces.
2353 pub internal: bool,
2354}
2355
2356/// One Cloudflare meter over the range, and the product it is a cost of.
2357#[derive(Clone, Debug, Serialize, Deserialize)]
2358#[serde(rename_all = "camelCase")]
2359pub struct CostLineSummary {
2360 pub product: String,
2361 pub meter: String,
2362 pub raw_name: String,
2363 pub unit: String,
2364 pub source: String,
2365 pub quantity: f64,
2366 pub cost_micros: i64,
2367 /// Absent when no mapping claims it.
2368 pub bucket: Option<String>,
2369}
2370
2371/// A row of the mapping from Cloudflare's meters to g1t's products.
2372#[derive(Clone, Debug, Serialize, Deserialize)]
2373#[serde(rename_all = "camelCase")]
2374pub struct CostMapping {
2375 pub product: String,
2376 pub meter: String,
2377 pub bucket: String,
2378 pub price_meter: Option<String>,
2379 pub own_meter: Option<String>,
2380 pub scale_to_own: bool,
2381 pub drift_percent: f64,
2382 pub note: String,
2383 pub updated_at: String,
2384 pub updated_by: String,
2385}
2386
2387/// The guardrails on prices and the alerts.
2388#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
2389#[serde(rename_all = "camelCase")]
2390pub struct CostSettings {
2391 /// Apply small moves without staff.
2392 pub auto_apply: bool,
2393 /// The largest move applied without staff, either way, in percent.
2394 pub auto_apply_percent: f64,
2395 /// Days between telling customers of a rise and charging it.
2396 pub notice_days: u32,
2397 /// Below this margin, in percent, for `alert_days` days in a row, alert.
2398 pub margin_floor_percent: f64,
2399 pub alert_days: u32,
2400 /// Days with less cost than this say nothing about a margin.
2401 pub min_daily_cost_micros: i64,
2402 /// A workspace costing more than its revenue times this, over 30 days,
2403 /// and at least `anomaly_floor_micros`, is flagged.
2404 pub anomaly_factor: f64,
2405 pub anomaly_floor_micros: i64,
2406}
2407
2408impl Default for CostSettings {
2409 fn default() -> Self {
2410 CostSettings {
2411 auto_apply: true,
2412 auto_apply_percent: 25.0,
2413 notice_days: 14,
2414 margin_floor_percent: 10.0,
2415 alert_days: 3,
2416 min_daily_cost_micros: 100_000,
2417 anomaly_factor: 1.0,
2418 anomaly_floor_micros: 1_000_000,
2419 }
2420 }
2421}
2422
2423/// The Costs & margin page.
2424#[derive(Clone, Debug, Default, Serialize, Deserialize)]
2425#[serde(rename_all = "camelCase")]
2426pub struct CostsReport {
2427 /// A token to read Cloudflare's bill is set.
2428 pub configured: bool,
2429 /// When Cloudflare's bill was last read.
2430 pub fetched_at: Option<String>,
2431 /// The days shown, YYYY-MM-DD.
2432 pub since: String,
2433 pub until: String,
2434 pub days: Vec<CostDay>,
2435 pub products: Vec<ProductMargin>,
2436 pub overall: OverallMargin,
2437 pub drift: Vec<CostDrift>,
2438 pub alerts: Vec<MarginAlert>,
2439 pub proposals: Vec<PriceProposal>,
2440 pub versions: Vec<PriceVersion>,
2441 pub top_workspaces: Vec<WorkspaceCost>,
2442 pub lines: Vec<CostLineSummary>,
2443 pub mappings: Vec<CostMapping>,
2444 pub settings: CostSettings,
Spend caps: a monthly budget for comped workspaces and a daily breaker on what g1t pays2445 /// g1t's own spend against its two caps.
2446 #[serde(default)]
2447 pub caps: SpendCaps,
2448}
2449
2450/// What g1t itself pays for, against its caps (billing's `budget`): the
2451/// daily breaker on all of it, and each comped account's monthly budget.
2452/// At cost, never at price. What sudo's Costs page and its red bar show.
2453#[derive(Clone, Debug, Default, Serialize, Deserialize)]
2454#[serde(rename_all = "camelCase")]
2455pub struct SpendCaps {
2456 /// Today (UTC), YYYY-MM-DD, and this month, YYYY-MM.
2457 pub day: String,
2458 pub month: String,
2459 /// What g1t paid for itself today across every workspace: comped work,
2460 /// the trial and open-source pools, free workspaces' overruns, and
2461 /// anything charged without real money behind it.
2462 pub today_micros: i64,
2463 /// `PLATFORM_DAILY_SPEND_CAP_MICROS`. Zero: no breaker.
2464 pub daily_cap_micros: i64,
2465 /// The breaker is open: new hosted-model agent runs that g1t would pay
2466 /// for wait until tomorrow (UTC) or until staff lift it.
2467 pub tripped: bool,
2468 pub tripped_at: Option<String>,
2469 /// Staff lifted it for the rest of the day.
2470 pub lifted_by: Option<String>,
2471 pub lifted_at: Option<String>,
2472 pub lift_note: Option<String>,
2473 /// This month so far, by what paid: `comped`, `trial`, `oss`, `given`,
2474 /// `unpaid`.
2475 pub month_buckets: Vec<SpendBucket>,
2476 /// Each comped account's monthly budget.
2477 pub comped: Vec<CompedBudget>,
2478 /// Free workspaces' share of this month's reconciled costs (git,
2479 /// storage, platform), through yesterday.
2480 pub free_tier_micros: i64,
2481 /// `CLOUDFLARE_FIXED_MONTHLY_MICROS`: Cloudflare subscriptions, an estimate.
2482 pub fixed_monthly_micros: i64,
2483 /// Money in this month, through the last reconciled day.
2484 pub revenue_micros: i64,
2485}
2486
2487#[derive(Clone, Debug, Default, Serialize, Deserialize)]
2488#[serde(rename_all = "camelCase")]
2489pub struct SpendBucket {
2490 pub bucket: String,
2491 pub title: String,
2492 pub micros: i64,
2493}
2494
2495/// A comped account's monthly budget: what its work cost g1t this month.
2496#[derive(Clone, Debug, Default, Serialize, Deserialize)]
2497#[serde(rename_all = "camelCase")]
2498pub struct CompedBudget {
2499 pub account: String,
2500 pub name: String,
2501 pub used_micros: i64,
2502 /// Zero: no budget.
2503 pub ceiling_micros: i64,
2504 /// The ceiling is `COMPED_MONTHLY_CEILING_MICROS`, not the account's own.
2505 pub default_ceiling: bool,
2506 /// 50, 75, 90, 100, or 0.
2507 pub level: u32,
2508}
2509
2510/// `admin_spend_caps`: g1t's own spend against its caps. Returns `SpendCaps`.
2511#[derive(Debug, Default, Serialize, Deserialize)]
2512pub struct AdminSpendCapsArgs {}
2513
2514/// `admin_lift_breaker`: lets hosted-model runs start again for the rest
2515/// of today (UTC), with why. Recorded in the audit log. Returns
2516/// `Outcome<SpendCaps>`.
2517#[derive(Debug, Serialize, Deserialize)]
2518pub struct AdminLiftBreakerArgs {
2519 pub note: String,
2520 pub by: String,
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily2521}
2522
2523/// `admin_cost_alerts`: the open margin alerts, for sudo's banner.
2524/// Returns `Vec<MarginAlert>`.
2525#[derive(Debug, Default, Serialize, Deserialize)]
2526pub struct AdminCostAlertsArgs {}
2527
2528/// `admin_decide_proposal`: approve or reject a price proposal. An
2529/// approved rise takes effect after the notice period. Returns
2530/// `Outcome<PriceProposal>`.
2531#[derive(Debug, Serialize, Deserialize)]
2532pub struct AdminDecideProposalArgs {
2533 pub id: String,
2534 /// `approve` or `reject`.
2535 pub decision: String,
2536 #[serde(default)]
2537 pub note: String,
2538 pub by: String,
2539}
2540
2541/// `admin_set_cost_settings`. Returns `Outcome<CostSettings>`.
2542#[derive(Debug, Serialize, Deserialize)]
2543pub struct AdminSetCostSettingsArgs {
2544 pub settings: CostSettings,
2545 pub by: String,
2546}
2547
2548/// `admin_set_cost_mapping`: adds, changes or (with `remove`) removes a
2549/// mapping row. Returns `Outcome<CostMapping>`.
2550#[derive(Debug, Serialize, Deserialize)]
2551pub struct AdminSetCostMappingArgs {
2552 pub product: String,
2553 pub meter: String,
2554 #[serde(default)]
2555 pub bucket: String,
2556 #[serde(default)]
2557 pub price_meter: Option<String>,
2558 #[serde(default)]
2559 pub own_meter: Option<String>,
2560 #[serde(default)]
2561 pub scale_to_own: bool,
2562 #[serde(default)]
2563 pub drift_percent: Option<f64>,
2564 #[serde(default)]
2565 pub note: String,
2566 #[serde(default)]
2567 pub remove: bool,
2568 pub by: String,
2569}
2570
2571/// `admin_run_costs`: reads Cloudflare's bill and reconciles now, as the
2572/// daily run does. Returns `Outcome<CostsRun>`.
2573#[derive(Debug, Default, Serialize, Deserialize)]
2574pub struct AdminRunCostsArgs {
2575 #[serde(default)]
2576 pub by: String,
2577}
2578
2579#[derive(Clone, Debug, Default, Serialize, Deserialize)]
2580#[serde(rename_all = "camelCase")]
2581pub struct CostsRun {
2582 pub lines: u32,
2583 pub days: u32,
2584 pub proposals: u32,
2585 pub alerts: u32,
2586 /// What could not be read, in words.
2587 pub problems: Vec<String>,
2588}
2589
Models per workspace: several providers, routed by kind of work2590#[cfg(test)]
2591mod tests {
2592 use super::*;
2593
2594 #[test]
Prices are what g1t pays plus 20%, from the first second2595 fn an_account_carries_no_run_fee() {
2596 let account = Account {
2597 workspace: "acme".into(),
2598 balance_micros: 0,
2599 status: Status { enabled: true, live: false, free: false },
2600 margin_percent: 20,
2601 card: None,
2602 };
2603 let json = serde_json::to_value(account).unwrap();
2604 let mut keys: Vec<&str> = json.as_object().unwrap().keys().map(String::as_str).collect();
2605 keys.sort_unstable();
2606 assert_eq!(keys, ["balanceMicros", "card", "marginPercent", "status", "workspace"]);
2607 }
2608
2609 #[test]
2610 fn a_price_change_says_when_the_markup_moved() {
2611 let change = PriceChange {
2612 meter: "sandbox_second".into(),
2613 old_cost_micros: 21.0,
2614 new_cost_micros: 21.0,
2615 markup_percent: 20,
2616 old_markup_percent: Some(138),
2617 reason: "Sandbox time is now charged at cost plus 20% from the first second".into(),
2618 created_at: "2026-10-05T00:00:00Z".into(),
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily2619 effective_at: None,
Prices are what g1t pays plus 20%, from the first second2620 };
2621 assert_eq!(serde_json::to_value(&change).unwrap()["oldMarkupPercent"], 138);
2622 let cost_only = PriceChange { old_markup_percent: None, ..change };
2623 assert!(serde_json::to_value(&cost_only).unwrap().get("oldMarkupPercent").is_none());
2624 }
2625
2626 #[test]
Paid features: a workspace turns on Deployments with a monthly plan2627 fn features_are_named_as_the_site_sends_them() {
2628 assert_eq!(
2629 serde_json::to_value(Feature::Deployments).unwrap(),
2630 serde_json::json!("deployments")
2631 );
2632 assert_eq!(Feature::parse("deployments"), Some(Feature::Deployments));
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look2633 assert_eq!(serde_json::to_value(Feature::Plan).unwrap(), serde_json::json!("plan"));
2634 assert_eq!(Feature::parse("plan"), Some(Feature::Plan));
2635 // Older readers named the plan Team.
2636 assert_eq!(Feature::parse("team"), Some(Feature::Plan));
2637 assert_eq!(serde_json::from_value::<Feature>(serde_json::json!("team")).unwrap(), Feature::Plan);
2638 assert_eq!(Feature::ALL, [Feature::Plan]);
Paid features: a workspace turns on Deployments with a monthly plan2639 assert!(SubscriptionStatus::Canceling.on());
2640 assert!(!SubscriptionStatus::PastDue.on());
2641 }
2642
2643 #[test]
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look2644 fn a_reservation_is_asked_for_and_answered_in_camel_case() {
2645 let asked: ReserveArgs = serde_json::from_value(serde_json::json!({
2646 "workspace": "acme",
2647 "repo": { "namespace": "acme", "name": "web" },
2648 "public": true,
2649 "kind": "check",
2650 "estimateMicros": 2_000_000,
2651 }))
2652 .unwrap();
2653 assert_eq!(asked.kind, ComputeKind::Check);
2654 assert!(asked.kind.open_source_pool());
2655 assert!(!ComputeKind::Agent.open_source_pool());
2656 // Rust callers that write snake_case are read too.
2657 let snake: ReserveArgs = serde_json::from_value(serde_json::json!({
2658 "workspace": "acme",
2659 "repo": { "namespace": "acme", "name": "web" },
2660 "public": false,
2661 "kind": "agent",
2662 "estimate_micros": 1,
2663 }))
2664 .unwrap();
2665 assert_eq!(snake.estimate_micros, 1);
2666 let answer = Reservation { id: "rsv_1".into(), paid_by: PaidBy::OnDemand, held_micros: 5, expires_at: String::new() };
2667 assert_eq!(serde_json::to_value(&answer).unwrap()["paidBy"], "on_demand");
2668 assert_eq!(serde_json::to_value(PlanKind::Internal).unwrap(), "internal");
2669 assert!(!PlanKind::Free.on_demand() && PlanKind::Enterprise.on_demand());
2670 }
2671
2672 #[test]
2673 fn a_refusal_carries_its_own_code() {
2674 let refused: crate::Outcome<Reservation> =
2675 crate::Outcome::fail(crate::FailureCode::OssPoolEmpty, "The open-source pool is spent.");
2676 let json = serde_json::to_value(&refused).unwrap();
2677 assert_eq!(json["error"]["code"], "oss_pool_empty");
2678 assert_eq!(crate::FailureCode::NotPaid.http_status(), 402);
2679 assert_eq!(crate::FailureCode::Paused.http_status(), 409);
2680 }
2681
2682 #[test]
Models per workspace: several providers, routed by kind of work2683 fn who_pays_is_read_as_the_runner_sends_it() {
2684 let run: StartRunArgs = serde_json::from_value(serde_json::json!({
2685 "workspace": "acme",
2686 "repo": { "namespace": "acme", "name": "web" },
2687 "number": 7,
2688 "task": "implement",
2689 "model": "Claude Sonnet 5.5",
2690 "billedTo": "workspace",
2691 }))
2692 .unwrap();
2693 assert_eq!(run.billed_to, "workspace");
2694 }
2695}