@clocknext/sdk 0.14.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -15,12 +15,15 @@ type SignalStatus = "SUCCESS" | "FAILURE" | "PENDING";
15
15
  /**
16
16
  * Token counts for a signal. `input` and `output` are required — every metered
17
17
  * call has them, and the server requires them. `cache` (provider-specific
18
- * prompt-cache reads) is optional and defaults to 0 server-side when omitted.
18
+ * prompt-cache reads) and `cacheWrite` (tokens written into the prompt cache,
19
+ * priced at the model's separate cache-write rate) are optional and default to
20
+ * 0 server-side when omitted.
19
21
  */
20
22
  interface Tokens {
21
23
  input: number;
22
24
  output: number;
23
25
  cache?: number;
26
+ cacheWrite?: number;
24
27
  }
25
28
  /**
26
29
  * Groups a signal into one occurrence of a **composite** — a bundle of credits
@@ -56,37 +59,31 @@ interface CompositeTag {
56
59
  /** Your correlation value for this occurrence, stored verbatim. */
57
60
  value: string | number;
58
61
  }
59
- /** The organisation + key behind a request — `cnk.workspace.me()`. */
60
- interface WorkspaceIdentity {
61
- organization: {
62
- id: string;
63
- name: string;
64
- slug: string | null;
65
- /** `sandbox` is a disposable staging twin; `live` bills for real. Check
66
- * this before sending production traffic. */
67
- environment: "sandbox" | "live";
68
- };
69
- apiKey: {
70
- prefix: string;
71
- lastFour: string;
72
- expiresAt: string | null;
73
- } | null;
74
- }
75
- /** One model the org has enabled — `cnk.workspace.models()`. The `modelId` is
76
- * what you put in a signal's `model`. Prices are USD per 1,000,000 tokens. */
77
- interface Model {
78
- modelId: string;
79
- modelName: string;
80
- provider: string;
81
- providerName: string;
82
- isActive: boolean;
83
- inputPrice: number;
84
- outputPrice: number;
85
- cachePrice: number;
86
- }
87
- interface SignalBase {
88
- /** The customer this usage belongs to (required). */
62
+ /**
63
+ * How a request names its customer: by OUR id (`customerId`) or by YOUR id for
64
+ * them (`externalId` — the value set on the customer via
65
+ * `customers.create()` / `customers.update()`). At least one is required.
66
+ *
67
+ * When both are sent, `customerId` wins and `externalId` is ignored — the
68
+ * server does not check that they agree. An `externalId` matching no active
69
+ * customer is a `NotFoundError` (or, on an async signal, leaves it Pending
70
+ * with that reason — retry once the customer exists).
71
+ */
72
+ type CustomerRef = {
73
+ /** Our customer id. Wins over `externalId` when both are sent. */
89
74
  customerId: string;
75
+ externalId?: string;
76
+ } | {
77
+ customerId?: undefined;
78
+ /** Your id for the customer: 1–32 letters, numbers or "-", matched
79
+ * exactly (case-sensitive). */
80
+ externalId: string;
81
+ };
82
+ /** `Omit` that keeps a union a union (plain `Omit` flattens it to the
83
+ * members' shared keys, losing the {@link CustomerRef} either/or). */
84
+ type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
85
+ /** Every signal names its customer — see {@link CustomerRef}. */
86
+ interface SignalFields {
90
87
  /**
91
88
  * The model's catalog id — must be enabled in your ClockNext org
92
89
  * (Settings → Models). Matched case-insensitively against `OrgModel.modelId`.
@@ -108,18 +105,19 @@ interface SignalBase {
108
105
  */
109
106
  idempotencyKey?: string;
110
107
  }
108
+ type SignalBase = CustomerRef & SignalFields;
111
109
  /** Meters a credit, identified by the credit's stable `agentKey`. */
112
- interface CreditSignal extends SignalBase {
110
+ type CreditSignal = SignalBase & {
113
111
  type: "credit";
114
112
  /** The Credit's stable agent key (assigned when the credit was created). */
115
113
  agentKey: string;
116
114
  /** Optional composite this signal belongs to. See {@link CompositeTag}. */
117
115
  composite?: CompositeTag;
118
- }
116
+ };
119
117
  /** Debits the customer's wallet in USD at the model's cost. */
120
- interface WalletSignal extends SignalBase {
118
+ type WalletSignal = SignalBase & {
121
119
  type: "wallet";
122
- }
120
+ };
123
121
  /**
124
122
  * Records one step of a multi-call outcome run. The `agentKey` identifies the
125
123
  * step (and the outcome); `runId` groups every signal of a single run, so a step
@@ -132,7 +130,7 @@ interface WalletSignal extends SignalBase {
132
130
  * carries `complete` — see {@link OutcomeCompletionInput} /
133
131
  * `signals.completeOutcome()`, its own dedicated route.
134
132
  */
135
- interface OutcomeSignal extends SignalBase {
133
+ type OutcomeSignal = SignalBase & {
136
134
  type: "outcome";
137
135
  /** The OutcomeStep's stable agent key — identifies the outcome AND the step. */
138
136
  agentKey: string;
@@ -144,12 +142,12 @@ interface OutcomeSignal extends SignalBase {
144
142
  runId: string;
145
143
  /** Optional composite this signal belongs to. See {@link CompositeTag}. */
146
144
  composite?: CompositeTag;
147
- }
145
+ };
148
146
  type Signal = CreditSignal | WalletSignal | OutcomeSignal;
149
147
  /** Helper input shapes for the per-type convenience methods. */
150
- type CreditInput = Omit<CreditSignal, "type">;
151
- type WalletInput = Omit<WalletSignal, "type">;
152
- type OutcomeInput = Omit<OutcomeSignal, "type">;
148
+ type CreditInput = DistributiveOmit<CreditSignal, "type">;
149
+ type WalletInput = DistributiveOmit<WalletSignal, "type">;
150
+ type OutcomeInput = DistributiveOmit<OutcomeSignal, "type">;
153
151
  /**
154
152
  * Input for `signals.completeOutcome()` — closes ONE outcome run, the outcome
155
153
  * mirror of {@link CompositeCompletionInput}. No `agentKey`, no `usage`: this
@@ -161,17 +159,17 @@ type OutcomeInput = Omit<OutcomeSignal, "type">;
161
159
  * `signals.completeComposite()` — the two completions are independent, and
162
160
  * neither implies the other.
163
161
  */
164
- interface OutcomeCompletionInput {
165
- customerId: string;
162
+ type OutcomeCompletionInput = CustomerRef & {
166
163
  /** The same `runId` the run's step signals were sent with. */
167
164
  runId: string;
168
165
  /** Optional member (email) this completion is attributed to. */
169
166
  member?: string;
170
- /** Idempotency key, auto-generated if omitted. Sending `complete` twice for
171
- * the same run is already a safe no-op server-side, so this only collapses
172
- * a retry into one attempt rather than protecting against a double bill. */
167
+ /** Idempotency key, auto-generated if omitted. Sending this completion twice
168
+ * for the same run is already a safe no-op server-side, so this only
169
+ * collapses a retry into one attempt rather than protecting against a
170
+ * double bill. */
173
171
  idempotencyKey?: string;
174
- }
172
+ };
175
173
  /**
176
174
  * The result of `signals.completeOutcome()`.
177
175
  *
@@ -244,7 +242,10 @@ interface SerializedUsageLog {
244
242
  member: string | null;
245
243
  inputTokens: number;
246
244
  outputTokens: number;
245
+ /** Cache-read tokens. */
247
246
  cacheTokens: number;
247
+ /** Cache-write tokens, priced separately from cache reads. */
248
+ cacheWriteTokens: number;
248
249
  /** Total credits deducted: the call's real per-model provider cost as a
249
250
  * fraction of the credit's base price (i.e. cost + your margin), plus any
250
251
  * credit-rule add-ons; 0 for wallet-money calls. */
@@ -274,7 +275,7 @@ interface SerializedUsageLog {
274
275
  * exhausted allowance is detected by the worker LATER and never surfaces here —
275
276
  * the signal is simply dropped. A `202` therefore means "accepted", never
276
277
  * "recorded". To confirm a signal actually landed, read it back with
277
- * `signals.list({ customerId })`.
278
+ * `signals.usageLog({ customerId })`.
278
279
  *
279
280
  * When the server has no queue configured it prices inline instead and returns
280
281
  * `queued: false` with a populated `usageLog`, validating synchronously.
@@ -296,7 +297,7 @@ interface TrackResult {
296
297
  * and will price it shortly. It can no longer be lost, but
297
298
  * it is not billed yet and `usageLog` is null. A rejection
298
299
  * discovered during pricing will NOT come back to you here,
299
- * nor on `onError`. `signals.list()` shows what got priced;
300
+ * nor on `onError`. `signals.usageLog()` shows what got priced;
300
301
  * the dashboard's signal log — owner-only, by design — is
301
302
  * where an individual rejection says why.
302
303
  * `"recorded"` — the server priced it inline and `usageLog` is populated.
@@ -341,21 +342,6 @@ interface TrackResult {
341
342
  */
342
343
  rawId?: string;
343
344
  }
344
- interface UsageList {
345
- customer: {
346
- id: string;
347
- name: string;
348
- creditAllowance: number;
349
- };
350
- totals: {
351
- count: number;
352
- cost: number;
353
- revenue: number;
354
- profit: number;
355
- creditsUsed: number;
356
- };
357
- logs: SerializedUsageLog[];
358
- }
359
345
  /** A preset time window, or `"custom"` for an explicit `from`/`to` range. */
360
346
  type UsageLogPeriod = "all" | "today" | "7d" | "30d" | "90d" | "custom";
361
347
  interface UsageLogListParams {
@@ -412,7 +398,10 @@ interface UsageLogEntry {
412
398
  usage: {
413
399
  inputTokens: number;
414
400
  outputTokens: number;
401
+ /** Cache-read tokens. */
415
402
  cacheTokens: number;
403
+ /** Cache-write tokens, priced separately from cache reads. */
404
+ cacheWriteTokens: number;
416
405
  };
417
406
  /** Formatted USD strings (e.g. `"$0.0064"`). */
418
407
  cost: {
@@ -445,6 +434,9 @@ interface UsageLogPage {
445
434
  }
446
435
  interface ApiCustomer {
447
436
  id: string;
437
+ /** Your own id for this customer, or `null` when unset. See
438
+ * {@link CustomerProfileInput.externalId}. */
439
+ externalId: string | null;
448
440
  slug: string;
449
441
  name: string;
450
442
  description: string | null;
@@ -460,11 +452,23 @@ interface ApiCustomer {
460
452
  taxId: string | null;
461
453
  currencyCode: string;
462
454
  creditAllowance: number;
455
+ recurringTransactionEmail: boolean;
456
+ autoRecurring: boolean;
463
457
  createdAt: string;
464
458
  updatedAt: string;
465
459
  }
466
460
  /** Writable customer profile fields. `null` clears a column; omit to leave it. */
467
461
  interface CustomerProfileInput {
462
+ /**
463
+ * The id YOUR product uses for this customer: 1–32 letters, numbers or "-",
464
+ * case-sensitive. Unique among the org's active customers (a clash is a
465
+ * `ConflictError`; an archived customer's id can be reused). Once set,
466
+ * signals and `purchases.create()` can take `externalId` instead of
467
+ * `customerId`, and `customers.getByExternalId()` / `updateByExternalId()` /
468
+ * `updateRecurringGrantByExternalId()` address the customer by it. `null`
469
+ * clears it on update.
470
+ */
471
+ externalId?: string | null;
468
472
  name?: string;
469
473
  description?: string | null;
470
474
  email?: string | null;
@@ -479,6 +483,10 @@ interface CustomerProfileInput {
479
483
  taxId?: string | null;
480
484
  /** ISO 4217 (3 letters); must be enabled for the org. */
481
485
  currencyCode?: string;
486
+ /** Send the invoice, payment receipt and card-payment-failed emails for recurring invoices. Defaults to `true` on create. */
487
+ recurringTransactionEmail?: boolean;
488
+ /** Issue every recurring invoice as `AUTO_CLOSED` (applied as if paid, never payable). Defaults to `false` on create. */
489
+ autoRecurring?: boolean;
482
490
  }
483
491
  /** `name` and `email` are required on create; every other field is optional. */
484
492
  type CreateCustomerInput = CustomerProfileInput & {
@@ -510,7 +518,7 @@ interface OutcomeBalance {
510
518
  remaining: number;
511
519
  /** Each step's `agentKey` is what `signals.outcome()` and the outcome adjust
512
520
  * API use to address this outcome at runtime. The outcome also has its own
513
- * separate key ({@link Outcome.agentKey}), but neither of those APIs accepts
521
+ * separate key (the outcome's own `agentKey`), but neither of those APIs accepts
514
522
  * it — it identifies the outcome in the catalogue, not in a signal. */
515
523
  steps: {
516
524
  id: string;
@@ -528,8 +536,25 @@ interface UnitBalance {
528
536
  granted: number;
529
537
  remaining: number;
530
538
  }
531
- /** Wallet / credit / outcome / unit balances for a customer's active plan
532
- * (`customers.balances()`). */
539
+ /** One prepaid (ADVANCE) composite pool on a customer's plan. */
540
+ interface CompositeBalance {
541
+ compositeId: string;
542
+ /** The tag signals send in their `composite` block. */
543
+ refId: string;
544
+ name: string;
545
+ /** The pool size the plan grants this cycle. */
546
+ granted: number;
547
+ /** Slots claimed this cycle — one per distinct tag value. */
548
+ used: number;
549
+ /** `granted - used` plus this cycle's manual adjustments. May be negative:
550
+ * running past the pool is allowed and carries into the next cycle. */
551
+ remaining: number;
552
+ /** What `granted` was before the pool was ever resized for this customer;
553
+ * `null` if it never was. */
554
+ originalGranted: number | null;
555
+ }
556
+ /** Wallet / credit / outcome / unit balances and composite pools for a
557
+ * customer's active plan (`customers.balances()`). */
533
558
  interface CustomerBalances {
534
559
  customerId: string;
535
560
  currency: {
@@ -537,12 +562,21 @@ interface CustomerBalances {
537
562
  rateUsd: number;
538
563
  };
539
564
  hasPlan: boolean;
565
+ /** Both wallet balances, in USD. Always present. */
540
566
  wallet: {
541
- balanceUsd: number;
542
- } | null;
567
+ /** The ordinary wallet — always reported, also when the plan has no
568
+ * Wallet component or there's no plan. May be negative. */
569
+ balance: number;
570
+ /** The Reserved Wallet; absent when the org hasn't enabled it, otherwise
571
+ * present whether or not the plan has a Wallet. Never negative. */
572
+ reservedBalance?: number;
573
+ };
543
574
  credits: CreditBalance[];
544
575
  outcomes: OutcomeBalance[];
545
576
  units: UnitBalance[];
577
+ /** ADVANCE composite pools. A composite billed in ARREAR has no pool and
578
+ * isn't listed. */
579
+ composites: CompositeBalance[];
546
580
  }
547
581
  /** The customer's active plan (the `plan` field of `customers.plan()`);
548
582
  * `null` when the customer is unsubscribed. */
@@ -586,11 +620,10 @@ interface PortalToken {
586
620
  /** Seconds until expiry. */
587
621
  expiresIn: number;
588
622
  }
589
- /** How often a plan bills. `FREE` is a one-time grant; `EVERY_5_MIN` is a test cadence. */
590
- type BillingCycle = "MONTHLY" | "QUARTERLY" | "SEMI_ANNUAL" | "YEARLY" | "EVERY_5_MIN" | "FREE";
623
+ /** How often a plan bills. `FREE` is a one-time grant. */
624
+ type BillingCycle = "MONTHLY" | "QUARTERLY" | "SEMI_ANNUAL" | "YEARLY" | "FREE";
591
625
  type PlanType = "WALLET" | "BUNDLE";
592
626
  type PlanKind = "FLAT_PRICE" | "PAY_AS_YOU_GO" | "PAY_PER_SEAT";
593
- /** A plan component's meter type. */
594
627
  /**
595
628
  * A plan component's kind.
596
629
  *
@@ -602,138 +635,31 @@ type PlanKind = "FLAT_PRICE" | "PAY_AS_YOU_GO" | "PAY_PER_SEAT";
602
635
  type ComponentType = "WALLET" | "CREDIT" | "OUTCOME" | "UNIT" | "FLAT" | "PRICING_METRIC";
603
636
  /** ADVANCE bills up-front for the cycle; ARREAR bills for what was consumed. */
604
637
  type BillingMode = "ADVANCE" | "ARREAR";
605
- /** Prepaid USD wallet. `amount` is the funded balance (required). Max one
606
- * wallet component per plan. */
607
- interface WalletComponentInput {
608
- type: "WALLET";
609
- billingMode: BillingMode;
610
- amount: number;
611
- }
612
- /** A one-off flat fee — `amount` is required. Max one flat component per plan;
613
- * not allowed on FREE plans. */
614
- interface FlatComponentInput {
615
- type: "FLAT";
616
- billingMode: BillingMode;
617
- amount: number;
618
- }
619
- /** A credit entitlement, referenced by `creditId`. Billed ADVANCE it needs a
620
- * granted `quantity`; billed ARREAR it meters usage with no upfront grant. */
621
- type CreditComponentInput = {
622
- type: "CREDIT";
623
- billingMode: "ADVANCE";
624
- creditId: string;
625
- quantity: number;
626
- } | {
627
- type: "CREDIT";
628
- billingMode: "ARREAR";
629
- creditId: string;
630
- quantity?: number | null;
631
- };
632
- /** An outcome entitlement, referenced by `outcomeId`. ADVANCE needs a granted
633
- * `quantity`; ARREAR meters usage. */
634
- type OutcomeComponentInput = {
635
- type: "OUTCOME";
636
- billingMode: "ADVANCE";
637
- outcomeId: string;
638
- quantity: number;
639
- } | {
640
- type: "OUTCOME";
641
- billingMode: "ARREAR";
642
- outcomeId: string;
643
- quantity?: number | null;
644
- };
645
- /** A unit entitlement, referenced by `unitId`. ADVANCE needs a granted
646
- * `quantity`; ARREAR meters usage. */
647
- type UnitComponentInput = {
648
- type: "UNIT";
649
- billingMode: "ADVANCE";
650
- unitId: string;
651
- quantity: number;
652
- } | {
653
- type: "UNIT";
654
- billingMode: "ARREAR";
655
- unitId: string;
656
- quantity?: number | null;
657
- };
658
- /**
659
- * A COMPOSITE sold on the plan, referenced by `pricingMetricId` (the id from
660
- * `composites.list()`). This is the line that makes a composite bill: the
661
- * catalogue entry on its own charges nobody, and this component is what turns
662
- * it into money — `quantity × the composite's price`, frozen into the purchase
663
- * snapshot at buy time.
664
- *
665
- * The two billing modes differ in what `quantity` means:
666
- * - **ADVANCE** — a PREPAID POOL of `quantity` flat-rate slots, shared
667
- * across whichever credits / outcomes / units the composite wraps. Each
668
- * distinct tag value claims one slot on completion; repeat signals under a
669
- * value reuse the slot they already claimed, at no extra cost. Once every
670
- * slot is claimed, further occurrences are refused rather than billed.
671
- * - **ARREAR** — nothing prepaid; completed occurrences are counted on the
672
- * cycle-end line.
673
- *
674
- * `type` is the wire value `"PRICING_METRIC"`, not `"COMPOSITE"`: the product
675
- * word changed but the stored enum did not, and the API still speaks the old
676
- * one. That mismatch is the server's, and it is surfaced rather than hidden so
677
- * a response and a request read the same.
678
- */
679
- type CompositeComponentInput = {
680
- type: "PRICING_METRIC";
681
- billingMode: "ADVANCE";
682
- pricingMetricId: string;
683
- quantity: number;
684
- } | {
685
- type: "PRICING_METRIC";
686
- billingMode: "ARREAR";
687
- pricingMetricId: string;
688
- quantity?: number | null;
689
- };
690
- /**
691
- * One entitlement line in a plan — a discriminated union on `type` (and, where
692
- * it matters, `billingMode`) so the per-type fields the server requires are
693
- * enforced at compile time instead of surfacing as runtime 422s:
694
- * - CREDIT / OUTCOME / UNIT require their matching id;
695
- * - PRICING_METRIC (a composite) requires `pricingMetricId`;
696
- * - CREDIT / OUTCOME / UNIT / PRICING_METRIC require `quantity` when billed
697
- * ADVANCE;
698
- * - WALLET / FLAT require `amount`.
699
- */
700
- type PlanComponentInput = WalletComponentInput | FlatComponentInput | CreditComponentInput | OutcomeComponentInput | UnitComponentInput | CompositeComponentInput;
701
- interface CreatePlanInput {
702
- name: string;
703
- description?: string | null;
704
- billingCycle: BillingCycle;
705
- /** Carry an unused balance into the next cycle. Default true. */
706
- carryForward?: boolean;
707
- /** ISO 4217 (3 letters). Default "USD". */
708
- currencyCode?: string;
709
- isActive?: boolean;
710
- /** At least one component. FREE plans must be ADVANCE-only with no FLAT component. */
711
- components: PlanComponentInput[];
712
- }
713
- /** A full-rewrite update carries the complete plan (same shape as create). */
714
- type UpdatePlanInput = CreatePlanInput;
715
- interface PlanComponent {
638
+ /** One line of a plan (`plan.entitlements[]`). */
639
+ interface PlanEntitlement {
716
640
  id: string;
717
641
  type: ComponentType;
718
642
  billingMode: BillingMode;
719
643
  creditId: string | null;
720
644
  outcomeId: string | null;
721
645
  unitId: string | null;
722
- /** The composite this component sells, on a `PRICING_METRIC` component.
723
- * Without it a plan read back could not be written back: the write shape
724
- * ({@link CompositeComponentInput}) requires this id, so a read-modify-write
725
- * silently dropped every composite component. */
726
- pricingMetricId: string | null;
646
+ /** The id of the composite this component sells, on a `PRICING_METRIC`
647
+ * component. */
648
+ compositeId: string | null;
727
649
  targetName: string | null;
728
650
  quantity: number | null;
729
651
  amount: number | null;
652
+ /** ADVANCE credit / outcome / composite / wallet components: what's left at
653
+ * the end of a cycle carries into the next one instead of resetting.
654
+ * Always false for unit, flat and ARREAR components and on FREE plans. */
655
+ rollover: boolean;
730
656
  }
657
+ /** @deprecated Renamed to {@link PlanEntitlement} — a plan's lines are `entitlements` now. */
658
+ type PlanComponent = PlanEntitlement;
731
659
  interface Plan {
732
660
  id: string;
733
661
  name: string;
734
662
  description: string | null;
735
- type: PlanType;
736
- kind: PlanKind;
737
663
  billingCycle: BillingCycle;
738
664
  cost: number;
739
665
  /** Signed adjustment applied to the plan's headline price (default 0). */
@@ -741,26 +667,256 @@ interface Plan {
741
667
  /** When true, ARREAR consumption is funded from the customer's wallet as it
742
668
  * happens instead of being invoiced at cycle end. All-or-nothing per plan. */
743
669
  walletFundedArrear: boolean;
670
+ /** The workspace's primary currency when the plan was created. */
744
671
  currencyCode: string;
745
672
  isActive: boolean;
746
- components: PlanComponent[];
673
+ createdAt: string;
674
+ updatedAt: string;
675
+ /** The plan's lines — what a customer on it is granted or metered for. */
676
+ entitlements: PlanEntitlement[];
677
+ }
678
+ /** One line of a plan, as you send it to `plans.create()` / `plans.update()`.
679
+ * Set the id that matches `type`: `creditId` (CREDIT), `outcomeId`
680
+ * (OUTCOME), `unitId` (UNIT) or `compositeId` (PRICING_METRIC — a
681
+ * composite). The lines `plans.get()` returns can be sent back as they are. */
682
+ interface PlanEntitlementInput {
683
+ type: ComponentType;
684
+ billingMode: BillingMode;
685
+ creditId?: string | null;
686
+ outcomeId?: string | null;
687
+ unitId?: string | null;
688
+ compositeId?: string | null;
689
+ /** ADVANCE credit / outcome / unit / composite: granted each cycle (0 allowed). */
690
+ quantity?: number | null;
691
+ /** WALLET (ADVANCE prepaid balance, $0 allowed) or FLAT (fee, above $0), in USD. */
692
+ amount?: number | null;
693
+ /** ADVANCE credit / outcome / composite / wallet: carry leftovers into the next cycle. */
694
+ rollover?: boolean;
695
+ }
696
+ /** `plans.create()` body. The plan's currency is the workspace's primary
697
+ * currency — it can't be chosen. A new plan is active; retire it with
698
+ * `plans.archive()`. */
699
+ interface CreatePlanInput {
700
+ name: string;
701
+ billingCycle: BillingCycle;
702
+ description?: string | null;
703
+ /** Pay ARREAR usage from the prepaid wallet as it happens. Needs an ADVANCE
704
+ * WALLET line and at least one ARREAR credit / outcome / unit / composite. */
705
+ walletFundedArrear?: boolean;
706
+ /** Signed rounding nudge (USD) on the due-at-purchase total. */
707
+ priceAdjustment?: number;
708
+ /** At least one line. At most one WALLET and one FLAT. */
709
+ entitlements: PlanEntitlementInput[];
710
+ }
711
+ /** `plans.update()` body — a PARTIAL update: only the fields you send change.
712
+ * `entitlements`, when sent, is the complete new list. */
713
+ type UpdatePlanInput = Partial<CreatePlanInput>;
714
+ /** One model line of a credit's / outcome step's pricing bundle, as returned. */
715
+ interface ModelBundleLine {
716
+ /** The workspace's model row id (`id` from the Models API). */
717
+ orgModelId: string;
718
+ /** The model's display name, filled in by the server. */
719
+ modelName: string;
720
+ /** Average tokens one LLM call uses on this model. */
721
+ averageTokensPerLLMCall: number;
722
+ /** Whole-percent split of those tokens; the four add up to 100. */
723
+ input: number;
724
+ output: number;
725
+ cache: number;
726
+ /** 0 on a model with no cache-write price. */
727
+ cacheWrite: number;
728
+ }
729
+ /** One model line as you send it. Several lines (one per model) are allowed;
730
+ * the price is the sum of their costs, worked out on the server from the
731
+ * models' live prices. */
732
+ interface ModelBundleLineInput {
733
+ orgModelId: string;
734
+ /** Above 0. */
735
+ averageTokensPerLLMCall: number;
736
+ input: number;
737
+ output: number;
738
+ cache: number;
739
+ /** Default 0. Only on a model that has a cache-write price. */
740
+ cacheWrite?: number;
741
+ }
742
+ /** A credit — a token-metered entitlement your product draws down by its
743
+ * `agentKey`. */
744
+ interface Credit {
745
+ id: string;
746
+ name: string;
747
+ /** What a credit signal names; unique in the workspace. */
748
+ agentKey: string;
749
+ description: string | null;
750
+ /** Sum of the bundle lines' tokens (display figure). */
751
+ tokensPerCredit: number;
752
+ /** Cost of one credit, worked out from `modelBundle`. */
753
+ basePrice: number;
754
+ modelBundle: ModelBundleLine[];
755
+ marginPercent: number;
756
+ /** `basePrice` plus the margin — what a customer pays per credit. */
757
+ pricePerCredit: number;
758
+ isActive: boolean;
759
+ createdAt: string;
760
+ updatedAt: string;
761
+ }
762
+ /** `credits.create()` body. The price is always worked out on the server from
763
+ * `modelBundle` — it is never typed in. */
764
+ interface CreateCreditInput {
765
+ name: string;
766
+ agentKey: string;
767
+ /** -100 or more. */
768
+ marginPercent: number;
769
+ /** At least one line. */
770
+ modelBundle: ModelBundleLineInput[];
771
+ description?: string | null;
772
+ }
773
+ /** `credits.update()` body — PARTIAL. Send `modelBundle` to re-price; leave it
774
+ * out to keep the stored base price (a new margin is applied on top). */
775
+ type UpdateCreditInput = Partial<CreateCreditInput>;
776
+ /** An outcome — a multi-step deliverable billed per completed outcome. */
777
+ interface Outcome {
778
+ id: string;
779
+ name: string;
780
+ /** The outcome's own key (unique in the workspace) — not what a step signal
781
+ * names; each step has its own `agentKey`. */
782
+ agentKey: string;
783
+ description: string | null;
784
+ isActive: boolean;
785
+ /** Sum of the steps' base prices. */
786
+ basePrice: number;
787
+ marginPercent: number;
788
+ pricePerOutcome: number;
789
+ createdAt: string;
790
+ updatedAt: string;
791
+ }
792
+ /** One step of an outcome. */
793
+ interface OutcomeStep {
794
+ /** Send it back on `outcomes.update()` to keep this step. */
795
+ id: string;
796
+ name: string;
797
+ /** What an outcome step signal names; unique in the workspace. */
798
+ agentKey: string;
799
+ order: number;
800
+ basePrice: number;
801
+ modelBundle: ModelBundleLine[];
802
+ }
803
+ /** `outcomes.get()` — the outcome with its steps in full. */
804
+ interface OutcomeWithSteps extends Outcome {
805
+ steps: OutcomeStep[];
806
+ }
807
+ /** One step as you send it. */
808
+ interface OutcomeStepInput {
809
+ /** An existing step's id, to keep that step (update only). A step sent
810
+ * without an id but with an existing step's `agentKey` is that step too. */
811
+ id?: string;
812
+ name: string;
813
+ agentKey: string;
814
+ /** Required for a new step. Leave it out on an existing step to keep its
815
+ * price. */
816
+ modelBundle?: ModelBundleLineInput[];
817
+ }
818
+ /** `outcomes.create()` body. */
819
+ interface CreateOutcomeInput {
820
+ name: string;
821
+ agentKey: string;
822
+ /** -100 or more. */
823
+ marginPercent: number;
824
+ /** 1–50 steps; names and agent keys unique. */
825
+ steps: OutcomeStepInput[];
826
+ description?: string | null;
827
+ }
828
+ /** `outcomes.update()` body — PARTIAL. Leave `steps` out to leave the steps
829
+ * alone; send it and it is the complete step list (stored steps left out are
830
+ * removed). */
831
+ type UpdateOutcomeInput = Partial<CreateOutcomeInput>;
832
+ /** How a unit is priced. */
833
+ type UnitPricingType = "FLAT" | "SLAB" | "VOLUME";
834
+ /** One price band of a SLAB / VOLUME unit. */
835
+ interface UnitTier {
836
+ id: string;
837
+ /** Inclusive upper bound; `null` on the last tier ("and above"). */
838
+ upTo: number | null;
839
+ /** Per-unit price for this band. */
840
+ price: number;
841
+ order: number;
747
842
  }
748
- /** The richer plan returned by `plans.get()` (adds aggregate stats). */
749
- interface PlanDetail extends Plan {
843
+ /** A unit — a fixed-price, non-LLM event (an upload, a seat, an API call). */
844
+ interface Unit {
845
+ id: string;
846
+ name: string;
847
+ /** What a unit signal names; unique in the workspace. */
848
+ agentKey: string;
849
+ description: string | null;
850
+ pricingType: UnitPricingType;
851
+ /** FLAT only. */
852
+ flatPrice: number;
853
+ /** SLAB / VOLUME only. */
854
+ tiers: UnitTier[];
855
+ isActive: boolean;
750
856
  createdAt: string;
857
+ updatedAt: string;
751
858
  createdByName: string | null;
752
- customerCount: number;
753
- invoiceCount: number;
754
- openInvoiceCount: number;
755
- stats: {
756
- totalInvoiced: number;
757
- totalCollected: number;
758
- openBalance: number;
859
+ }
860
+ /** `units.create()` body. */
861
+ interface CreateUnitInput {
862
+ name: string;
863
+ agentKey: string;
864
+ pricingType: UnitPricingType;
865
+ /** FLAT only. */
866
+ flatPrice?: number;
867
+ /** SLAB / VOLUME: 1–50 tiers, `upTo` rising; the last one `upTo: null`. */
868
+ tiers?: {
869
+ upTo: number | null;
870
+ price: number;
871
+ }[];
872
+ description?: string | null;
873
+ }
874
+ /** `units.update()` body — PARTIAL. `tiers`, when sent, is the complete list. */
875
+ type UpdateUnitInput = Partial<CreateUnitInput>;
876
+ /** A catalogue item a composite wraps. */
877
+ interface CompositeItem {
878
+ id: string;
879
+ name: string;
880
+ agentKey: string;
881
+ }
882
+ /** A composite — several credits / outcomes / units grouped under one tag and
883
+ * billed as ONE thing, per completed occurrence, once a plan sells it. */
884
+ interface Composite {
885
+ id: string;
886
+ name: string;
887
+ /** The tag your signals send in their `composite` block. */
888
+ refId: string;
889
+ description: string | null;
890
+ /** USD per completed occurrence, once a plan sells it. */
891
+ price: number;
892
+ isActive: boolean;
893
+ createdAt: string;
894
+ updatedAt: string;
895
+ entitlements: {
896
+ credits: CompositeItem[];
897
+ outcomes: CompositeItem[];
898
+ units: CompositeItem[];
899
+ };
900
+ }
901
+ /** `composites.create()` body. */
902
+ interface CreateCompositeInput {
903
+ name: string;
904
+ refId: string;
905
+ price: number;
906
+ description?: string | null;
907
+ /** At least one id across the three lists. Every item must be active, and a
908
+ * unit must be FLAT-priced. */
909
+ entitlements: {
910
+ creditIds?: string[];
911
+ outcomeIds?: string[];
912
+ unitIds?: string[];
759
913
  };
760
914
  }
915
+ /** `composites.update()` body — PARTIAL. `entitlements`, when sent, is the
916
+ * complete new set. */
917
+ type UpdateCompositeInput = Partial<CreateCompositeInput>;
761
918
  type PurchaseStatus = "SCHEDULED" | "ACTIVE" | "CANCELLED";
762
- interface CreatePurchaseInput {
763
- customerId: string;
919
+ type CreatePurchaseInput = CustomerRef & {
764
920
  planId: string;
765
921
  /** `YYYY-MM-DD`. Defaults to today; must be a valid non-past date. */
766
922
  billingDate?: string;
@@ -768,7 +924,7 @@ interface CreatePurchaseInput {
768
924
  autoPayment?: boolean;
769
925
  /** Auto-void the purchase if unpaid after N minutes. */
770
926
  voidAfterMinutes?: number;
771
- }
927
+ };
772
928
  interface Purchase {
773
929
  id: string;
774
930
  purchaseNumber: string;
@@ -826,7 +982,9 @@ interface PurchaseDetail {
826
982
  paidCount: number;
827
983
  };
828
984
  }
829
- type InvoiceStatus = "OPEN" | "PAID" | "VOID";
985
+ /** `AUTO_CLOSED` — a recurring invoice for a customer with `autoRecurring` on:
986
+ * applied as if paid, but never payable. */
987
+ type InvoiceStatus = "OPEN" | "PAID" | "VOID" | "AUTO_CLOSED";
830
988
  /** Trimmed row from `invoices.list()`. */
831
989
  interface InvoiceListRow {
832
990
  id: string;
@@ -990,64 +1148,78 @@ interface UpdateMemberInput {
990
1148
  /** Must be unique (case-insensitively) among the customer's active members. */
991
1149
  email?: string;
992
1150
  }
993
- type WalletTransactionType = "CREDIT" | "DEBIT";
994
- /** What produced a wallet entry. `null` on rows written before the column
995
- * existed. */
996
- type WalletTransactionSource = "TOPUP" | "USAGE" | "SETTLE" | "ADJUSTMENT";
997
- /** The entitlement kinds a wallet-funded metering debit can name. */
998
- type WalletEntitlementKind = "CREDIT" | "OUTCOME" | "UNIT";
999
- interface WalletTransaction {
1000
- id: string;
1001
- type: WalletTransactionType;
1002
- /** What produced the entry. Null on rows older than the column. */
1003
- source: WalletTransactionSource | null;
1004
- amount: number;
1005
- amountUsd: number;
1006
- currencyCode: string;
1007
- currencyRateUsd: number;
1008
- notes: string | null;
1009
- batchId: string | null;
1010
- createdAt: string;
1011
- createdByName: string | null;
1012
- /** Set only on a wallet-funded metering debit: which kind of entitlement was
1013
- * consumed. Null on top-ups and manual adjustments. */
1014
- entitlementType: WalletEntitlementKind | null;
1015
- /** Id of the credit / outcome / unit consumed. Null unless
1016
- * `entitlementType` is set. */
1017
- targetId: string | null;
1018
- /** Its name at the time of the debit. */
1019
- targetName: string | null;
1020
- /** The signal this debit paid for (credit / outcome). In wallet-funded mode
1021
- * no invoice exists, so this is the only trail from a charge to its cause. */
1022
- usageLogId: string | null;
1023
- /** The unit event this debit paid for. */
1024
- unitUsageLogId: string | null;
1025
- }
1026
- interface WalletList {
1027
- balanceUsd: number;
1028
- transactions: WalletTransaction[];
1029
- }
1030
- interface WalletEntryInput {
1031
- /** DEBIT spends, CREDIT tops up. */
1032
- type: WalletTransactionType;
1033
- /** Always positive; the sign comes from `type`. */
1034
- amount: number;
1151
+ /**
1152
+ * Which of a customer's two wallet balances an entry moves: `"main"` (the
1153
+ * ordinary wallet) or `"reserved"` (the Reserved Wallet — an org-gated second
1154
+ * balance behind it; see {@link WalletAdjustInput.pool}). Lowercase only —
1155
+ * the API refuses `"MAIN"` / `"RESERVED"`.
1156
+ */
1157
+ type WalletPool = "main" | "reserved";
1158
+ /** Top up (positive) or draw down (negative) a customer's wallet. `delta` is
1159
+ * a non-zero amount in USD (cents allowed); absolute value ≤ 10,000,000. No
1160
+ * `agentKey` — a customer has exactly one wallet. The wallet can always be
1161
+ * adjusted, whatever the customer's plan (even with no plan). A draw-down is
1162
+ * never rejected or floored for going below 0 — the wallet may read negative. */
1163
+ interface WalletAdjustInput {
1164
+ /** Signed change in USD: positive tops up, negative draws down. */
1165
+ delta: number;
1035
1166
  notes?: string;
1167
+ /**
1168
+ * Which balance to move. Default `"main"`, the ordinary wallet (leave it
1169
+ * out; `null` is refused).
1170
+ *
1171
+ * `"reserved"` moves the Reserved Wallet instead — a second balance behind
1172
+ * the wallet that a wallet-funded Arrear charge draws on once the wallet
1173
+ * runs out (Wallet → Reserved down to 0 → Wallet goes negative). It must be
1174
+ * switched on for the org (Settings → Organisation → "Enable Reserved
1175
+ * balance in wallet"), else this is a `PlanError`. It never goes negative:
1176
+ * a reduce below zero is refused (an `AllowanceError`), not capped — drawing
1177
+ * down to exactly 0 is fine. `remaining` is then the Reserved balance. A
1178
+ * `"main"` adjustment never touches it.
1179
+ */
1180
+ pool?: WalletPool;
1181
+ /**
1182
+ * Optional idempotency key (1–255 characters) that makes this adjustment
1183
+ * safe to retry. The first call with a key adjusts; any repeat with the
1184
+ * same key and the same request adjusts nothing and comes back with
1185
+ * `replayed: true` (and when the original happened, `adjustedAt`). The same
1186
+ * key with a different request is a `ConflictError`. Keys are unique per
1187
+ * workspace and per adjust endpoint. **Auto-generated (UUID v4) if
1188
+ * omitted** and reused across every retry of this call, so a network blip
1189
+ * never adjusts twice — same as signals. Supply your own (e.g. your order
1190
+ * id) to also dedupe your OWN retries, across restarts or redelivery.
1191
+ */
1192
+ idempotencyKey?: string;
1036
1193
  }
1037
1194
  /** Grant (positive) or claw back (negative) a credit balance. `delta` must be a
1038
- * non-zero whole number. The credit is addressed by its stable `agentKey`. A
1039
- * reduce is never rejected or floored for going below 0 — the resulting
1040
- * balance may read negative, same as a real-usage overdraft already can. */
1195
+ * non-zero whole number. The credit is addressed by its stable `agentKey`,
1196
+ * and must be a prepaid (ADVANCE) part of the customer's current plan — else
1197
+ * a `PlanError` ("… is not part of this customer's plan"). A reduce is never
1198
+ * rejected or floored for going below 0 — the resulting balance may read
1199
+ * negative, same as a real-usage overdraft already can. */
1041
1200
  interface CreditAdjustInput {
1042
1201
  /** The credit's stable agent key (the same key used to record usage). */
1043
1202
  agentKey: string;
1044
1203
  delta: number;
1045
1204
  notes?: string;
1205
+ /**
1206
+ * Optional idempotency key (1–255 characters) that makes this adjustment
1207
+ * safe to retry. The first call with a key adjusts; any repeat with the
1208
+ * same key and the same request adjusts nothing and comes back with
1209
+ * `replayed: true` (and when the original happened, `adjustedAt`). The same
1210
+ * key with a different request is a `ConflictError`. Keys are unique per
1211
+ * workspace and per adjust endpoint. **Auto-generated (UUID v4) if
1212
+ * omitted** and reused across every retry of this call, so a network blip
1213
+ * never adjusts twice — same as signals. Supply your own (e.g. your order
1214
+ * id) to also dedupe your OWN retries, across restarts or redelivery.
1215
+ */
1216
+ idempotencyKey?: string;
1046
1217
  }
1047
1218
  /** Grant/claw an outcome balance. `delta` is a non-zero whole number. The
1048
1219
  * outcome is addressed here by a STEP's `agentKey`, which resolves to its
1049
- * parent outcome — NOT by the outcome's own `agentKey` ({@link Outcome.agentKey}),
1050
- * which this endpoint does not accept. A reduce is never rejected or floored
1220
+ * parent outcome — NOT by the outcome's own `agentKey`,
1221
+ * which this endpoint does not accept. The outcome must be a prepaid
1222
+ * (ADVANCE) part of the customer's current plan — else a `PlanError`. A reduce is never rejected or floored
1051
1223
  * for going below 0 — the resulting balance may read negative, same as a
1052
1224
  * real-usage overdraft already can. */
1053
1225
  interface OutcomeAdjustInput {
@@ -1056,16 +1228,41 @@ interface OutcomeAdjustInput {
1056
1228
  agentKey: string;
1057
1229
  delta: number;
1058
1230
  notes?: string;
1231
+ /**
1232
+ * Optional idempotency key (1–255 characters) that makes this adjustment
1233
+ * safe to retry. The first call with a key adjusts; any repeat with the
1234
+ * same key and the same request adjusts nothing and comes back with
1235
+ * `replayed: true` (and when the original happened, `adjustedAt`). The same
1236
+ * key with a different request is a `ConflictError`. Keys are unique per
1237
+ * workspace and per adjust endpoint. **Auto-generated (UUID v4) if
1238
+ * omitted** and reused across every retry of this call, so a network blip
1239
+ * never adjusts twice — same as signals. Supply your own (e.g. your order
1240
+ * id) to also dedupe your OWN retries, across restarts or redelivery.
1241
+ */
1242
+ idempotencyKey?: string;
1059
1243
  }
1060
1244
  /** Grant/claw a unit balance. `delta` is non-zero (fractional allowed). The
1061
- * unit is addressed by its stable `agentKey`. A reduce is never rejected or
1062
- * floored for going below 0 — the resulting balance may read negative, same
1063
- * as a real-usage overdraft already can. */
1245
+ * unit is addressed by its stable `agentKey`, and must be a prepaid
1246
+ * (ADVANCE) part of the customer's current plan — else a `PlanError`. A
1247
+ * reduce is never rejected or floored for going below 0 — the resulting
1248
+ * balance may read negative, same as a real-usage overdraft already can. */
1064
1249
  interface UnitAdjustInput {
1065
1250
  /** The unit's stable agent key (the same key used to record usage). */
1066
1251
  agentKey: string;
1067
1252
  delta: number;
1068
1253
  notes?: string;
1254
+ /**
1255
+ * Optional idempotency key (1–255 characters) that makes this adjustment
1256
+ * safe to retry. The first call with a key adjusts; any repeat with the
1257
+ * same key and the same request adjusts nothing and comes back with
1258
+ * `replayed: true` (and when the original happened, `adjustedAt`). The same
1259
+ * key with a different request is a `ConflictError`. Keys are unique per
1260
+ * workspace and per adjust endpoint. **Auto-generated (UUID v4) if
1261
+ * omitted** and reused across every retry of this call, so a network blip
1262
+ * never adjusts twice — same as signals. Supply your own (e.g. your order
1263
+ * id) to also dedupe your OWN retries, across restarts or redelivery.
1264
+ */
1265
+ idempotencyKey?: string;
1069
1266
  }
1070
1267
  /**
1071
1268
  * Grant (positive) or claw back (negative) slots on a customer's ADVANCE
@@ -1077,7 +1274,7 @@ interface UnitAdjustInput {
1077
1274
  */
1078
1275
  interface CompositeAdjustInput {
1079
1276
  /**
1080
- * The composite's stable identifier — its `refId` (see {@link Composite.refId}),
1277
+ * The composite's stable identifier — its `refId`,
1081
1278
  * the same value signals tag it with, NOT `agentKey` (a composite has no
1082
1279
  * `agentKey` column of its own). Named `agentKey` on the wire only so the
1083
1280
  * four adjust endpoints share one request shape.
@@ -1085,248 +1282,66 @@ interface CompositeAdjustInput {
1085
1282
  agentKey: string;
1086
1283
  delta: number;
1087
1284
  notes?: string;
1088
- }
1089
- /** A per-model token bundle attached to a credit or outcome step. */
1090
- interface ModelBundleEntry {
1091
- orgModelId: string;
1092
- /** Display label; the server defaults it from the model when omitted. */
1093
- modelName?: string;
1094
- tokens: number;
1095
- input: number;
1096
- output: number;
1097
- cache: number;
1098
- }
1099
- /** One point on a cost-over-time analytics series. */
1100
- interface CostPoint {
1101
- /** UTC day, `YYYY-MM-DD`. */
1102
- dateIso: string;
1103
- /** Short display label, e.g. "Jun 24". */
1104
- label: string;
1105
- /** Average cost that day, or `null` on days with no usage. */
1106
- cost: number | null;
1107
- reqs: number;
1108
- }
1109
- /** Summary stats across a cost-over-time series. */
1110
- interface CostStats {
1111
- activeDays: number;
1112
- avgCost: number | null;
1113
- peakCost: number | null;
1114
- troughCost: number | null;
1115
- deviationPct: number | null;
1116
- }
1117
- /** Cost-over-time analytics for a credit (`credits.get().analytics`). */
1118
- interface CreditAnalytics {
1119
- basePrice: number;
1120
- pricePerCredit: number;
1121
- marginPercent: number;
1122
- points: CostPoint[];
1123
- stats: CostStats;
1124
- }
1125
- /** Cost-over-time analytics for an outcome (`outcomes.get().analytics`).
1126
- * Each point adds `completions` (workflows finished that day). */
1127
- interface OutcomeAnalytics {
1128
- basePrice: number;
1129
- pricePerOutcome: number;
1130
- marginPercent: number;
1131
- points: (CostPoint & {
1132
- completions: number;
1133
- })[];
1134
- stats: CostStats;
1135
- }
1136
- interface Credit {
1137
- id: string;
1138
- name: string;
1139
- agentKey: string;
1140
- description: string | null;
1141
- tokensPerCredit: number;
1142
- basePrice: number;
1143
- marginPercent: number;
1144
- pricePerCredit: number;
1145
- isActive: boolean;
1146
- createdAt: string;
1147
- }
1148
- /** `credits.get()` — adds the model bundle plus usage stats/analytics. */
1149
- interface CreditDetail extends Credit {
1150
- modelBundle: ModelBundleEntry[];
1151
- createdByName: string;
1152
- stats: {
1153
- customerCount: number;
1154
- planCount: number;
1155
- totalGranted: number;
1156
- totalUsed: number;
1157
- revenue: number;
1158
- usageLogCount: number;
1159
- };
1160
- analytics: CreditAnalytics;
1161
- }
1162
- interface CreateCreditInput {
1163
- name: string;
1164
- /** Lowercased stable key used by `signals.credit({ agentKey })`. */
1165
- agentKey: string;
1166
- basePrice: number;
1167
- marginPercent: number;
1168
- pricePerCredit: number;
1169
- description?: string;
1170
- tokensPerCredit?: number;
1171
- modelBundle?: ModelBundleEntry[];
1172
- }
1173
- type UpdateCreditInput = CreateCreditInput;
1174
- interface OutcomeStepInput {
1175
- id?: string;
1176
- name: string;
1177
- /** Lowercased stable key used by `signals.outcome({ agentKey })`. */
1178
- agentKey: string;
1179
- basePrice: number;
1180
- modelBundle?: ModelBundleEntry[];
1181
- }
1182
- interface Outcome {
1183
- id: string;
1184
- name: string;
1185
- /**
1186
- * The OUTCOME's own stable agent key — its durable identity, mirroring
1187
- * {@link Credit.agentKey}. Lowercased `[a-z0-9._-]`, max 80 chars, unique per
1188
- * organisation. A rename never changes it.
1189
- *
1190
- * Distinct from each step's `agentKey` in `steps`, and in a SEPARATE
1191
- * namespace: usage is always reported against a STEP's key
1192
- * (`signals.outcome({ agentKey })`), never this one. This key identifies the
1193
- * outcome itself when creating or updating it.
1194
- */
1195
- agentKey: string;
1196
- description: string | null;
1197
- isActive: boolean;
1198
- marginPercent: number;
1199
- pricePerOutcome: number;
1200
- }
1201
- /** `outcomes.get()` — adds steps plus in-flight/completed stats. */
1202
- interface OutcomeDetail extends Outcome {
1203
- /** Only the DETAIL row carries these — `outcomes.list()` returns neither.
1204
- * They were previously declared on {@link Outcome} itself, where
1205
- * `createdAt` was typed as a required `string` that is always `undefined`
1206
- * in practice. */
1207
- createdAt: string;
1208
- createdByName: string | null;
1209
- steps: {
1210
- name: string;
1211
- agentKey: string;
1212
- }[];
1213
- stats: {
1214
- stepCount: number;
1215
- customerCount: number;
1216
- inFlight: number;
1217
- completed: number;
1218
- totalRemaining: number;
1219
- };
1220
- analytics: OutcomeAnalytics;
1221
- }
1222
- interface CreateOutcomeInput {
1223
- name: string;
1224
1285
  /**
1225
- * The OUTCOME's own stable agent key — REQUIRED. Lowercased `[a-z0-9._-]`,
1226
- * max 80 chars, unique per organisation (the server lowercases and trims it).
1227
- *
1228
- * Separate namespace from `steps[].agentKey`: this names the outcome, a step
1229
- * key names a step and is what `signals.outcome()` reports against. Omitting
1230
- * it is rejected with a `ValidationError` (400).
1286
+ * Optional idempotency key (1–255 characters) that makes this adjustment
1287
+ * safe to retry. The first call with a key adjusts; any repeat with the
1288
+ * same key and the same request adjusts nothing and comes back with
1289
+ * `replayed: true` (and when the original happened, `adjustedAt`). The same
1290
+ * key with a different request is a `ConflictError`. Keys are unique per
1291
+ * workspace and per adjust endpoint. **Auto-generated (UUID v4) if
1292
+ * omitted** and reused across every retry of this call, so a network blip
1293
+ * never adjusts twice — same as signals. Supply your own (e.g. your order
1294
+ * id) to also dedupe your OWN retries, across restarts or redelivery.
1231
1295
  */
1232
- agentKey: string;
1233
- basePrice: number;
1234
- marginPercent: number;
1235
- pricePerOutcome: number;
1236
- description?: string | null;
1237
- isActive?: boolean;
1238
- /** 1–50 steps; step names and agent keys must be unique. */
1239
- steps: OutcomeStepInput[];
1240
- }
1241
- type UpdateOutcomeInput = CreateOutcomeInput;
1242
- type UnitPricingType = "FLAT" | "SLAB" | "VOLUME";
1243
- /** A tier for SLAB/VOLUME pricing; only the last tier may have `upTo: null`. */
1244
- interface UnitTierInput {
1245
- id?: string;
1246
- upTo: number | null;
1247
- price: number;
1248
- }
1249
- interface UnitTier {
1250
- id: string;
1251
- upTo: number | null;
1252
- price: number;
1253
- order: number;
1254
- }
1255
- interface Unit {
1256
- id: string;
1257
- /** Stable per-org report key — what `signals.unit({ agentKey })` sends.
1258
- * The ONLY identifier accepted when reporting unit consumption. */
1259
- agentKey: string;
1260
- name: string;
1261
- description: string | null;
1262
- pricingType: UnitPricingType;
1263
- flatPrice: number;
1264
- tiers: UnitTier[];
1265
- isActive: boolean;
1266
- createdAt: string;
1267
- createdByName: string | null;
1296
+ idempotencyKey?: string;
1268
1297
  }
1269
- /** One row in a unit's linked-customer sample (`units.get().customers`). */
1270
- interface UnitCustomerRow {
1271
- customerId: string;
1272
- name: string;
1273
- legalName: string | null;
1274
- slug: string;
1275
- logoUrl: string | null;
1276
- granted: number;
1277
- used: number;
1298
+ /**
1299
+ * What every adjust call returns.
1300
+ *
1301
+ * `replayed: true` means this call adjusted NOTHING: an earlier call with the
1302
+ * same `idempotencyKey` already did, at `adjustedAt`. `remaining` is always
1303
+ * the balance as it is now. `customerArchived` is true when the customer is
1304
+ * archived — archived customers follow the same rules (archiving cancels
1305
+ * their plan, so usually only the wallet can still move).
1306
+ */
1307
+ interface AdjustResult {
1278
1308
  remaining: number;
1279
- currentlyMetered: boolean;
1280
- }
1281
- /** `units.get()` — adds linked-customer sample plus stats.
1282
- * `createdByName` is inherited from `Unit`. */
1283
- interface UnitDetail extends Unit {
1284
- stats: {
1285
- planCount: number;
1286
- customerCount: number;
1287
- totalRemaining: number;
1288
- totalUsed: number;
1289
- };
1290
- /** First page (≤10) of customers currently metered on this unit. */
1291
- customers: UnitCustomerRow[];
1292
- }
1293
- /** Flat per-event pricing — a single `flatPrice` (defaults to 0), no tiers. */
1294
- interface FlatUnitInput {
1295
- name: string;
1296
- /** Stable per-org report key (`signals.unit({ agentKey })`); `[a-z0-9._-]`. */
1297
- agentKey: string;
1298
- pricingType: "FLAT";
1299
- /** Price per event; defaults to 0. */
1300
- flatPrice?: number;
1301
- description?: string | null;
1302
- isActive?: boolean;
1303
- }
1304
- /** Tiered pricing (SLAB or VOLUME) — at least one tier is required. */
1305
- interface TieredUnitInput {
1306
- name: string;
1307
- /** Stable per-org report key (`signals.unit({ agentKey })`); `[a-z0-9._-]`. */
1308
- agentKey: string;
1309
- pricingType: "SLAB" | "VOLUME";
1310
- /** At least one tier (≤50). Only the last tier may have `upTo: null`. */
1311
- tiers: UnitTierInput[];
1312
- description?: string | null;
1313
- isActive?: boolean;
1309
+ replayed: boolean;
1310
+ /** Set only on a replay: when the original adjustment happened (ISO 8601). */
1311
+ adjustedAt?: string;
1312
+ customerArchived: boolean;
1314
1313
  }
1315
1314
  /**
1316
- * Create a unit type — a discriminated union on `pricingType`: `FLAT` takes an
1317
- * optional `flatPrice` (defaults to 0); `SLAB`/`VOLUME` require `tiers`, so the
1318
- * server's "add at least one tier" rule is enforced at compile time.
1315
+ * Change how much a customer is granted every billing cycle. The difference is
1316
+ * applied to the current balance immediately (a shrink is never floored — the
1317
+ * balance may read negative). `quantity` is USD for the wallet and a whole
1318
+ * number for everything else. `agentKey` resolves the same way as the adjust
1319
+ * endpoints: a credit's or unit's `agentKey`, an outcome STEP's `agentKey`, or
1320
+ * a composite's `refId`. The wallet needs none — a customer has at most one.
1319
1321
  */
1320
- type CreateUnitInput = FlatUnitInput | TieredUnitInput;
1321
- type UpdateUnitInput = CreateUnitInput;
1322
+ type RecurringGrantInput = {
1323
+ kind: "wallet";
1324
+ quantity: number;
1325
+ } | {
1326
+ kind: "credit" | "outcome" | "unit" | "composite";
1327
+ agentKey: string;
1328
+ quantity: number;
1329
+ };
1330
+ /** Result of `customers.updateRecurringGrant()`. */
1331
+ interface RecurringGrantResult {
1332
+ kind: RecurringGrantInput["kind"];
1333
+ /** The new per-cycle amount. */
1334
+ quantity: number;
1335
+ /** The wallet balance after the change — only present for `kind: "wallet"`. */
1336
+ balanceUsd?: number;
1337
+ }
1322
1338
  /**
1323
1339
  * Record one unit-metered event. The unit is addressed by its `agentKey` (the
1324
1340
  * stable key set when the unit was created) — the ONLY accepted identifier;
1325
1341
  * the display name is deliberately not accepted, so a rename can never redirect
1326
1342
  * a live integration. Keys are matched exactly (they are stored lowercased).
1327
1343
  */
1328
- interface UnitInput {
1329
- customerId: string;
1344
+ type UnitInput = CustomerRef & {
1330
1345
  agentKey: string;
1331
1346
  member?: string;
1332
1347
  /**
@@ -1357,7 +1372,7 @@ interface UnitInput {
1357
1372
  * auto key cannot survive.
1358
1373
  */
1359
1374
  idempotencyKey?: string;
1360
- }
1375
+ };
1361
1376
  /**
1362
1377
  * The result of `signals.unit()`.
1363
1378
  *
@@ -1385,8 +1400,7 @@ interface UnitTrackResult {
1385
1400
  * Input for `signals.completeComposite()` — closes ONE occurrence of a
1386
1401
  * composite, which is the moment it is billed.
1387
1402
  */
1388
- interface CompositeCompletionInput {
1389
- customerId: string;
1403
+ type CompositeCompletionInput = CustomerRef & {
1390
1404
  /** Which occurrence to close: the composite's `refId` and the correlation
1391
1405
  * value the signals were tagged with. */
1392
1406
  composite: CompositeTag;
@@ -1394,71 +1408,7 @@ interface CompositeCompletionInput {
1394
1408
  * safe no-op, so this only collapses retries into one recorded attempt
1395
1409
  * rather than protecting against a double charge. */
1396
1410
  idempotencyKey?: string;
1397
- }
1398
- /** One catalogue item a composite is restricted to. `agentKey` is what a
1399
- * signal names, so it is the field you actually integrate against. */
1400
- interface CompositeCatalogueRef {
1401
- id: string;
1402
- name: string;
1403
- agentKey: string;
1404
- }
1405
- /** One composite in the org's catalogue — `cnk.composites.list()`. */
1406
- interface Composite {
1407
- id: string;
1408
- name: string;
1409
- /** The stable identifier you put in a signal's `composite` block as `ref`. */
1410
- refId: string;
1411
- description: string | null;
1412
- /** USD charged per occurrence WHEN A PLAN SELLS THIS as a composite
1413
- * component (`quantity × price`, frozen into the purchase at buy time). The
1414
- * catalogue row alone bills nothing. */
1415
- price: number;
1416
- /** False once archived. An archived composite stops NEW signals resolving to
1417
- * it but keeps every row it already owns. */
1418
- isActive: boolean;
1419
- createdAt: string;
1420
- /**
1421
- * The credits / outcomes / units this composite is restricted to — only
1422
- * signals naming one of these may carry its tag.
1423
- *
1424
- * All three lists empty means UNRESTRICTED (it accepts any of the org's
1425
- * traffic under this tag). Nothing created through the API can be
1426
- * unrestricted, but rows predating that rule exist — so don't assume
1427
- * non-empty.
1428
- */
1429
- entitlements: {
1430
- credits: CompositeCatalogueRef[];
1431
- outcomes: CompositeCatalogueRef[];
1432
- units: CompositeCatalogueRef[];
1433
- };
1434
- }
1435
- /** Input for `cnk.composites.create()`. */
1436
- interface CreateCompositeInput {
1437
- name: string;
1438
- /**
1439
- * The tag identifier. Lowercased, and restricted to the same characters as
1440
- * an `agentKey` — but validated harder than one, because it may not collide
1441
- * with a field the ingest schemas already own (`customerId`, `usage`,
1442
- * `agentKey`, `runId`, `member`, `custom`, `composite`, …). A colliding
1443
- * `refId` is refused at create time rather than silently ignored at ingest.
1444
- */
1445
- refId: string;
1446
- /** USD per occurrence once a plan sells it. Required — an unpriced composite
1447
- * put on a plan would bill 0, which is a money bug that is hard to see. */
1448
- price: number;
1449
- description?: string | null;
1450
- /**
1451
- * What the composite wraps. At least one id across the three lists is
1452
- * REQUIRED: a composite restricted to nothing would accept every signal in
1453
- * the org. Get the ids from `credits.list()`, `outcomes.list()` and
1454
- * `units.list()`.
1455
- */
1456
- entitlements: {
1457
- creditIds?: string[];
1458
- outcomeIds?: string[];
1459
- unitIds?: string[];
1460
- };
1461
- }
1411
+ };
1462
1412
  /**
1463
1413
  * The result of `signals.completeComposite()`.
1464
1414
  *
@@ -1494,8 +1444,7 @@ interface CompositeCompletionResult {
1494
1444
  /** The durable inbox id — see {@link TrackResult.rawId}. */
1495
1445
  rawId?: string;
1496
1446
  }
1497
- /** One serialized unit-consumption event — the result of `signals.unit()` and
1498
- * each element of `UnitUsageList.events`. */
1447
+ /** One serialized unit-consumption event — the result of `signals.unit()`. */
1499
1448
  interface SerializedUnitUsage {
1500
1449
  id: string;
1501
1450
  customerId: string;
@@ -1510,42 +1459,6 @@ interface SerializedUnitUsage {
1510
1459
  member: string | null;
1511
1460
  createdAt: string;
1512
1461
  }
1513
- interface UnitUsageRow {
1514
- unit: string;
1515
- /** The unit's stable agent key — what to send to report against it. */
1516
- agentKey: string | null;
1517
- billingMode: BillingMode;
1518
- granted?: number;
1519
- used: number;
1520
- remaining?: number;
1521
- }
1522
- interface UnitUsageList {
1523
- customer: {
1524
- id: string;
1525
- name: string;
1526
- };
1527
- units: UnitUsageRow[];
1528
- events: SerializedUnitUsage[];
1529
- }
1530
- type ThresholdKind = "CREDIT" | "OUTCOME" | "WALLET";
1531
- interface Webhook {
1532
- id: string;
1533
- kind: ThresholdKind;
1534
- threshold: number;
1535
- url: string;
1536
- isActive: boolean;
1537
- createdAt: string;
1538
- updatedAt: string;
1539
- createdByName: string | null;
1540
- }
1541
- interface UpsertWebhookInput {
1542
- kind: ThresholdKind;
1543
- /** Fire when the balance crosses this value. */
1544
- threshold: number;
1545
- /** http(s) URL to POST the alert to. */
1546
- url: string;
1547
- isActive?: boolean;
1548
- }
1549
1462
  type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
1550
1463
  interface Logger {
1551
1464
  debug?: (...args: unknown[]) => void;
@@ -1678,65 +1591,77 @@ declare class Transport {
1678
1591
  }
1679
1592
 
1680
1593
  /**
1681
- * The `composites` resource — manage the org's composite *catalogue*: the
1682
- * bundles of credits / outcomes / units that are grouped under one tag and
1683
- * sold on a plan as a single thing. `/api/v1/composites`.
1594
+ * The `composites` resource — several credits / outcomes / units grouped under
1595
+ * one tag (`refId`) and billed as ONE thing per completed occurrence.
1596
+ * `/api/v1/composites`.
1684
1597
  *
1685
- * Two things live elsewhere, deliberately:
1686
- * • Tagging a signal into a composite occurrence is `composite: { ref, value }`
1687
- * on the signal itself (see `signals.credit()` / `.outcome()` / `.unit()`).
1688
- * • Closing an occurrence — the moment it is billed — is
1689
- * `signals.completeComposite()`.
1598
+ * Creating a composite charges nobody: it only bills once a plan sells it as
1599
+ * a `PRICING_METRIC` entitlement (`plans.create()` with its `compositeId`).
1690
1600
  *
1691
- * This resource only defines what composites EXIST. Creating one prices it but
1692
- * charges nobody: an invoice is built from plan components, never from a
1693
- * catalogue entry, so a composite starts costing money only once a plan sells
1694
- * it (`quantity × price`, frozen into the purchase at buy time).
1601
+ * There is no `delete()` — the API never deletes catalogue items. Retire a
1602
+ * composite with `archive()` (new signals stop resolving to it; its history is
1603
+ * kept); `unarchive()` brings it back.
1695
1604
  */
1696
1605
  declare class Composites {
1697
1606
  private readonly transport;
1698
1607
  constructor(transport: Transport);
1699
- /** List composites. Pass `{ active: true }` for only the ones a signal can
1700
- * still be tagged with — the default list INCLUDES archived ones, which
1701
- * keep every row they already own.
1702
- * `{ active: false }` returns only archived ones; omitting it returns
1703
- * both. See `activeQuery` — the API itself only supports `true`. */
1608
+ /** List them. `{ active: true }` returns only active ones, `{ active: false }`
1609
+ * only archived ones; omit it for both. */
1704
1610
  list(params?: {
1705
1611
  active?: boolean;
1706
1612
  }): Promise<Composite[]>;
1707
- /** Create a composite. `POST /api/v1/composites`. */
1613
+ /** One composite's configuration. */
1614
+ get(id: string): Promise<Composite>;
1615
+ /** Create one. It starts active. Not retried on failure — a retry could
1616
+ * create a second row. */
1708
1617
  create(input: CreateCompositeInput): Promise<Composite>;
1618
+ /** PARTIAL update: only the fields you send change. `entitlements`, when
1619
+ * sent, is the complete new set. Renaming `refId` cuts live traffic over at
1620
+ * once — ship the new tag to your callers first. */
1621
+ update(id: string, input: UpdateCompositeInput): Promise<Composite>;
1622
+ /** Retire it (`isActive` → false). Nothing is deleted. Safe to retry. */
1623
+ archive(id: string): Promise<Composite>;
1624
+ /** Bring an archived one back (`isActive` → true). Safe to retry. */
1625
+ unarchive(id: string): Promise<Composite>;
1709
1626
  }
1710
1627
 
1711
1628
  /**
1712
- * The `credits` resource — manage the org's credit *types* (the catalog). A
1713
- * credit's stable `agentKey` is what you pass to `signals.credit()` when
1714
- * recording usage against it. `/api/v1/credits`.
1629
+ * The `credits` resource — the token-metered credits your product draws down
1630
+ * by `agentKey`. `/api/v1/credits`.
1631
+ *
1632
+ * Pricing is never typed in: `create()` takes a `modelBundle` (one line per
1633
+ * model, each with `averageTokensPerLLMCall` and its input / output / cache /
1634
+ * cacheWrite split) and the server works out `basePrice` and
1635
+ * `pricePerCredit` from the models' live prices.
1636
+ *
1637
+ * There is no `delete()` — the API never deletes catalogue items. Retire a
1638
+ * credit with `archive()`; `unarchive()` brings it back unchanged.
1715
1639
  */
1716
1640
  declare class Credits {
1717
1641
  private readonly transport;
1718
1642
  constructor(transport: Transport);
1719
- /** List credit types. Pass `{ active: true }` to only return active ones.
1720
- * `{ active: false }` returns only archived ones; omitting it returns
1721
- * both. See `activeQuery` — the API itself only supports `true`. */
1643
+ /** List them. `{ active: true }` returns only active ones, `{ active: false }`
1644
+ * only archived ones; omit it for both. */
1722
1645
  list(params?: {
1723
1646
  active?: boolean;
1724
1647
  }): Promise<Credit[]>;
1725
- /** Create a credit type; returns the created credit. `POST /api/v1/credits`. */
1648
+ /** One credit's configuration. */
1649
+ get(id: string): Promise<Credit>;
1650
+ /** Create one. It starts active. Not retried on failure — a retry could
1651
+ * create a second row. */
1726
1652
  create(input: CreateCreditInput): Promise<Credit>;
1727
- /** Fetch one credit type with usage stats. `GET /api/v1/credits/:id`. */
1728
- get(id: string): Promise<CreditDetail>;
1729
- /** Update a credit type's definition; returns the updated credit. `PATCH /api/v1/credits/:id`. */
1653
+ /** PARTIAL update: only the fields you send change. Send `modelBundle` to
1654
+ * re-price; leave it out to keep the stored base price. */
1730
1655
  update(id: string, input: UpdateCreditInput): Promise<Credit>;
1731
- /** Activate or deactivate a credit type. */
1732
- setActive(id: string, isActive: boolean): Promise<Credit>;
1733
- /** Delete a credit type. Refused while a customer is linked to it. */
1734
- delete(id: string): Promise<void>;
1656
+ /** Retire it (`isActive` → false). Nothing is deleted. Safe to retry. */
1657
+ archive(id: string): Promise<Credit>;
1658
+ /** Bring an archived one back (`isActive` → true). Safe to retry. */
1659
+ unarchive(id: string): Promise<Credit>;
1735
1660
  }
1736
1661
 
1737
1662
  /**
1738
1663
  * The `customers` resource — full CRUD over the org's customers plus the
1739
- * read-only insight endpoints (usage / balances / plan). Every call is scoped
1664
+ * read-only insight endpoints (balances / plan). Every call is scoped
1740
1665
  * to the API key's organisation server-side; a customer in another org
1741
1666
  * resolves as a NotFoundError.
1742
1667
  */
@@ -1763,14 +1688,25 @@ declare class Customers {
1763
1688
  get(id: string): Promise<ApiCustomer>;
1764
1689
  /** Update a customer (partial). `PATCH /api/v1/customers/:id`. */
1765
1690
  update(id: string, input: CustomerProfileInput): Promise<ApiCustomer>;
1691
+ /**
1692
+ * Fetch one customer by YOUR id for them (its `externalId`), instead of
1693
+ * ours. Same result as {@link get}. `GET /api/v1/customers/ext/:externalId`.
1694
+ * An unknown external id is a `NotFoundError`; only active customers match.
1695
+ */
1696
+ getByExternalId(externalId: string): Promise<ApiCustomer>;
1697
+ /** Update a customer (partial), addressed by its `externalId`. Same body as
1698
+ * {@link update}. `PATCH /api/v1/customers/ext/:externalId`. */
1699
+ updateByExternalId(externalId: string, input: CustomerProfileInput): Promise<ApiCustomer>;
1700
+ /** {@link delete}, addressing the customer by its `externalId`.
1701
+ * `DELETE /api/v1/customers/ext/:externalId`. */
1702
+ deleteByExternalId(externalId: string): Promise<void>;
1766
1703
  /** Delete a customer (members, invitations, usage logs cascade). */
1767
1704
  delete(id: string): Promise<void>;
1768
- /** A customer's usage history. `GET /api/v1/usage?customerId=`. */
1769
- usage(id: string, params?: {
1770
- limit?: number;
1771
- }): Promise<UsageList>;
1772
1705
  /** Wallet / credit / outcome / unit balances. `GET …/:id/balances`. */
1773
1706
  balances(id: string): Promise<CustomerBalances>;
1707
+ /** {@link balances}, addressing the customer by its `externalId`.
1708
+ * `GET /api/v1/customers/ext/:externalId/balances`. */
1709
+ balancesByExternalId(externalId: string): Promise<CustomerBalances>;
1774
1710
  /**
1775
1711
  * One credit balance for a customer, matched by `creditId` or `creditName`;
1776
1712
  * `null` when the customer has no plan or no matching credit. Convenience
@@ -1798,6 +1734,9 @@ declare class Customers {
1798
1734
  }): Promise<UnitBalance | null>;
1799
1735
  /** The customer's current plan. `GET …/:id/plan`. */
1800
1736
  plan(id: string): Promise<CustomerPlan>;
1737
+ /** {@link plan}, addressing the customer by its `externalId`.
1738
+ * `GET /api/v1/customers/ext/:externalId/plan`. */
1739
+ planByExternalId(externalId: string): Promise<CustomerPlan>;
1801
1740
  /** List a customer's members. `GET …/:id/members`. */
1802
1741
  listMembers(id: string): Promise<Member[]>;
1803
1742
  /** Add a member to a customer. Duplicate `email` → ConflictError. */
@@ -1806,39 +1745,63 @@ declare class Customers {
1806
1745
  updateMember(id: string, memberId: string, input: UpdateMemberInput): Promise<MemberProfile>;
1807
1746
  /** Remove a member from a customer, returning who was removed. `DELETE …/:id/members/:memberId`. */
1808
1747
  removeMember(id: string, memberId: string): Promise<RemovedMember>;
1809
- /** The customer's wallet balance + transactions. `GET …/:id/wallet`. */
1810
- wallet(id: string, params?: {
1811
- limit?: number;
1812
- }): Promise<WalletList>;
1748
+ /** Grant or claw back a credit balance. The credit must be a prepaid part of
1749
+ * the customer's current plan. Pass `idempotencyKey` to make it safe to
1750
+ * retry. `POST …/:id/credits/adjust`. */
1751
+ adjustCredit(id: string, input: CreditAdjustInput): Promise<AdjustResult>;
1752
+ /** Grant or claw back an outcome balance. The outcome must be a prepaid part
1753
+ * of the customer's current plan. `POST …/:id/outcomes/adjust`. */
1754
+ adjustOutcome(id: string, input: OutcomeAdjustInput): Promise<AdjustResult>;
1755
+ /** Grant or claw back a unit balance. The unit must be a prepaid part of the
1756
+ * customer's current plan. `POST …/:id/units/adjust`. */
1757
+ adjustUnit(id: string, input: UnitAdjustInput): Promise<AdjustResult>;
1758
+ /** Grant or claw back slots on a customer's ADVANCE composite pool for the
1759
+ * current billing cycle. `remaining` is the resulting slot count.
1760
+ * `POST …/:id/composites/adjust`. */
1761
+ adjustComposite(id: string, input: CompositeAdjustInput): Promise<AdjustResult>;
1813
1762
  /**
1814
- * Record a manual wallet entry (top-up or deduction). `amount` is always
1815
- * positive; the sign comes from `type`. `POST …/:id/wallet`.
1763
+ * Top up (positive `delta`) or draw down (negative `delta`) a customer's
1764
+ * wallet, in USD — allowed whatever the customer's plan. `remaining` is the
1765
+ * resulting USD balance. No `agentKey` — a customer has exactly one wallet.
1766
+ * Pass `pool: "reserved"` to move the Reserved Wallet instead (then
1767
+ * `remaining` is its balance). `POST …/:id/wallet/adjust`.
1816
1768
  */
1817
- addWalletEntry(id: string, input: WalletEntryInput): Promise<{
1818
- transaction: WalletTransaction;
1819
- balanceUsd: number;
1820
- }>;
1821
- /** Grant or claw back a credit balance. Returns the remaining balance.
1822
- * `POST …/:id/credits/adjust`. */
1823
- adjustCredit(id: string, input: CreditAdjustInput): Promise<{
1824
- remaining: number;
1825
- }>;
1826
- /** Grant or claw back an outcome balance. Returns the remaining balance. */
1827
- adjustOutcome(id: string, input: OutcomeAdjustInput): Promise<{
1828
- remaining: number;
1829
- }>;
1830
- /** Grant or claw back a unit balance. Returns the remaining balance. */
1831
- adjustUnit(id: string, input: UnitAdjustInput): Promise<{
1832
- remaining: number;
1833
- }>;
1769
+ adjustWallet(id: string, input: WalletAdjustInput): Promise<AdjustResult>;
1770
+ /** {@link adjustCredit}, addressing the customer by its `externalId` (`id`
1771
+ * here). `POST /api/v1/customers/ext/:externalId/credits/adjust`. */
1772
+ adjustCreditByExternalId(id: string, input: CreditAdjustInput): Promise<AdjustResult>;
1773
+ /** {@link adjustOutcome}, addressing the customer by its `externalId` (`id`
1774
+ * here). `POST /api/v1/customers/ext/:externalId/outcomes/adjust`. */
1775
+ adjustOutcomeByExternalId(id: string, input: OutcomeAdjustInput): Promise<AdjustResult>;
1776
+ /** {@link adjustUnit}, addressing the customer by its `externalId` (`id`
1777
+ * here). `POST /api/v1/customers/ext/:externalId/units/adjust`. */
1778
+ adjustUnitByExternalId(id: string, input: UnitAdjustInput): Promise<AdjustResult>;
1779
+ /** {@link adjustComposite}, addressing the customer by its `externalId`
1780
+ * (`id` here). `POST /api/v1/customers/ext/:externalId/composites/adjust`. */
1781
+ adjustCompositeByExternalId(id: string, input: CompositeAdjustInput): Promise<AdjustResult>;
1782
+ /** {@link adjustWallet}, addressing the customer by its `externalId` (`id`
1783
+ * here). `POST /api/v1/customers/ext/:externalId/wallet/adjust`. */
1784
+ adjustWalletByExternalId(id: string, input: WalletAdjustInput): Promise<AdjustResult>;
1785
+ /**
1786
+ * The one body behind all ten adjust calls.
1787
+ *
1788
+ * Every adjustment carries an idempotency key — the caller's, or one
1789
+ * generated here ONCE per call, exactly like signals. The server
1790
+ * deduplicates on it, so a transient failure is safe to retry: the same key
1791
+ * rides every attempt, and a retry of one that already landed comes back as
1792
+ * `replayed: true` instead of adjusting again. The key is also copied onto
1793
+ * any thrown error (`error.idempotencyKey`) so the caller can replay safely.
1794
+ */
1795
+ private adjust;
1834
1796
  /**
1835
- * Grant or claw back slots on a customer's ADVANCE composite pool for the
1836
- * current billing cycle. Returns the resulting `remaining` slot count.
1837
- * `POST …/:id/composites/adjust`.
1797
+ * Change how much a customer is granted every billing cycle (wallet top-up,
1798
+ * credits, outcomes, units or a composite pool). Any increase or decrease
1799
+ * applies to their current balance immediately. `PUT …/:id/recurring-grant`.
1838
1800
  */
1839
- adjustComposite(id: string, input: CompositeAdjustInput): Promise<{
1840
- remaining: number;
1841
- }>;
1801
+ updateRecurringGrant(id: string, input: RecurringGrantInput): Promise<RecurringGrantResult>;
1802
+ /** {@link updateRecurringGrant}, addressing the customer by its
1803
+ * `externalId`. `PUT /api/v1/customers/ext/:externalId/recurring-grant`. */
1804
+ updateRecurringGrantByExternalId(externalId: string, input: RecurringGrantInput): Promise<RecurringGrantResult>;
1842
1805
  }
1843
1806
 
1844
1807
  /**
@@ -1858,42 +1821,44 @@ declare class Invoices {
1858
1821
  /** Fetch one full invoice + its plan snapshot. `GET /api/v1/invoices/:id`. */
1859
1822
  get(id: string): Promise<InvoiceDetail>;
1860
1823
  /**
1861
- * Mint a hosted pay link for an OPEN invoice. PAID/VOID invoices are rejected
1824
+ * Mint a hosted pay link for an OPEN invoice. PAID/VOID/AUTO_CLOSED invoices are rejected
1862
1825
  * with a `ConflictError`. `GET /api/v1/invoices/:id/pay-link`.
1863
1826
  */
1864
1827
  payLink(id: string): Promise<PayLink>;
1865
1828
  }
1866
1829
 
1867
1830
  /**
1868
- * The `outcomes` resource — manage the org's outcome *types* (the catalog). An
1869
- * outcome is a multi-step workflow. `/api/v1/outcomes`.
1831
+ * The `outcomes` resource — multi-step deliverables billed per completed
1832
+ * outcome. `/api/v1/outcomes`.
1833
+ *
1834
+ * `list()` and every write return the outcome without its steps; `get()`
1835
+ * returns it with every step in full (ids included). Each new step is priced
1836
+ * from its own `modelBundle`, on the server.
1870
1837
  *
1871
- * Two distinct kinds of agent key, in separate namespaces, each unique per
1872
- * organisation — do not conflate them:
1873
- * - the OUTCOME's own `agentKey`, REQUIRED on `create()` and `update()`, which
1874
- * names the outcome itself in the catalogue;
1875
- * - each STEP's `agentKey`, which is what you pass to `signals.outcome()` to
1876
- * report usage and to the outcome-adjust API.
1838
+ * There is no `delete()` — the API never deletes catalogue items. Retire an
1839
+ * outcome with `archive()`; `unarchive()` brings it back unchanged.
1877
1840
  */
1878
1841
  declare class Outcomes {
1879
1842
  private readonly transport;
1880
1843
  constructor(transport: Transport);
1881
- /** List outcome types. Pass `{ active: true }` to only return active ones.
1882
- * `{ active: false }` returns only archived ones; omitting it returns
1883
- * both. See `activeQuery` — the API itself only supports `true`. */
1844
+ /** List them. `{ active: true }` returns only active ones, `{ active: false }`
1845
+ * only archived ones; omit it for both. */
1884
1846
  list(params?: {
1885
1847
  active?: boolean;
1886
1848
  }): Promise<Outcome[]>;
1887
- /** Create an outcome type with its steps. `POST /api/v1/outcomes`. */
1849
+ /** One outcome's configuration, with every step in full. */
1850
+ get(id: string): Promise<OutcomeWithSteps>;
1851
+ /** Create one. It starts active. Not retried on failure — a retry could
1852
+ * create a second row. */
1888
1853
  create(input: CreateOutcomeInput): Promise<Outcome>;
1889
- /** Fetch one outcome type with steps + stats. `GET /api/v1/outcomes/:id`. */
1890
- get(id: string): Promise<OutcomeDetail>;
1891
- /** Update an outcome type's definition. `PATCH /api/v1/outcomes/:id`. */
1854
+ /** PARTIAL update: only the fields you send change. Leave `steps` out to
1855
+ * leave the steps alone; send it and it is the complete list — pass each
1856
+ * existing step's `id` (or its same `agentKey`) to keep it. */
1892
1857
  update(id: string, input: UpdateOutcomeInput): Promise<Outcome>;
1893
- /** Activate or deactivate an outcome type; returns the updated outcome. */
1894
- setActive(id: string, isActive: boolean): Promise<Outcome>;
1895
- /** Delete an outcome type. */
1896
- delete(id: string): Promise<void>;
1858
+ /** Retire it (`isActive` → false). Nothing is deleted. Safe to retry. */
1859
+ archive(id: string): Promise<Outcome>;
1860
+ /** Bring an archived one back (`isActive` → true). Safe to retry. */
1861
+ unarchive(id: string): Promise<Outcome>;
1897
1862
  }
1898
1863
 
1899
1864
  /**
@@ -1913,9 +1878,14 @@ declare class Payments {
1913
1878
  }
1914
1879
 
1915
1880
  /**
1916
- * The `plans` resource — define and manage the billing plans customers
1917
- * subscribe to. Each plan is a set of entitlement components (wallet / credit /
1918
- * outcome / unit / flat) billed on a cycle. `/api/v1/plans`.
1881
+ * The `plans` resource — the billing plans customers subscribe to. Each plan
1882
+ * is a set of `entitlements` (wallet / credit / outcome / unit / composite /
1883
+ * flat lines) billed on a cycle. `/api/v1/plans`.
1884
+ *
1885
+ * A plan's currency is the workspace's primary currency; it can't be chosen.
1886
+ * There is no `delete()` — the API never deletes plans, so customers already
1887
+ * on one keep what they bought. Retire a plan with `archive()`; `unarchive()`
1888
+ * makes it purchasable again.
1919
1889
  */
1920
1890
  declare class Plans {
1921
1891
  private readonly transport;
@@ -1926,16 +1896,20 @@ declare class Plans {
1926
1896
  list(params?: {
1927
1897
  active?: boolean;
1928
1898
  }): Promise<Plan[]>;
1929
- /** Create a plan. `POST /api/v1/plans`. */
1899
+ /** One plan's configuration. */
1900
+ get(id: string): Promise<Plan>;
1901
+ /** Create a plan. It starts active. Not retried on failure — a retry could
1902
+ * create a second plan. */
1930
1903
  create(input: CreatePlanInput): Promise<Plan>;
1931
- /** Fetch one plan with aggregate subscriber/invoice stats. `GET /api/v1/plans/:id`. */
1932
- get(id: string): Promise<PlanDetail>;
1933
- /** Replace a plan's definition (components + settings). `PATCH /api/v1/plans/:id`. */
1904
+ /** PARTIAL update: only the fields you send change. `entitlements`, when
1905
+ * sent, is the complete new list — the list `get()` returned can be sent
1906
+ * back as it is. Changes apply to new purchases only. */
1934
1907
  update(id: string, input: UpdatePlanInput): Promise<Plan>;
1935
- /** Activate or deactivate a plan without rewriting it. */
1936
- setActive(id: string, isActive: boolean): Promise<Plan>;
1937
- /** Delete a plan. Refused once any customer has purchased it. */
1938
- delete(id: string): Promise<void>;
1908
+ /** Retire a plan (`isActive` → false): it can't be bought any more; customers
1909
+ * already on it are unaffected. Safe to retry. */
1910
+ archive(id: string): Promise<Plan>;
1911
+ /** Make an archived plan purchasable again (`isActive` → true). Safe to retry. */
1912
+ unarchive(id: string): Promise<Plan>;
1939
1913
  }
1940
1914
 
1941
1915
  /**
@@ -2144,19 +2118,6 @@ declare class Signals {
2144
2118
  * not a safe no-op — see {@link OutcomeCompletionResult}.
2145
2119
  */
2146
2120
  completeOutcome(input: OutcomeCompletionInput): Promise<OutcomeCompletionResult>;
2147
- /**
2148
- * Recent usage logs + totals for a customer. `GET /api/v1/usage`.
2149
- *
2150
- * Still the legacy path, deliberately. The `/api/v1/signal/*` family is
2151
- * POST-only — it replaced how usage is INGESTED, not how it is read — so
2152
- * `GET /api/v1/usage` has no successor and is not deprecated. It is also the
2153
- * only way to prove a signal landed, which matters more now that ingestion
2154
- * answers `202` for everything.
2155
- */
2156
- list(params: {
2157
- customerId: string;
2158
- limit?: number;
2159
- }): Promise<UsageList>;
2160
2121
  /**
2161
2122
  * Record one unit-metered event (a fixed-price meter with no tokens),
2162
2123
  * addressed to a catalog unit by its `agentKey`. Sent immediately — unit
@@ -2196,16 +2157,6 @@ declare class Signals {
2196
2157
  * rather than failing it.
2197
2158
  */
2198
2159
  completeComposite(input: CompositeCompletionInput): Promise<CompositeCompletionResult>;
2199
- /**
2200
- * A customer's unit balances + recent unit events. `GET /api/v1/units`.
2201
- *
2202
- * Legacy path for the same reason as {@link list}: the signal family is
2203
- * POST-only, so the read side has no successor and is not deprecated.
2204
- */
2205
- unitUsage(params: {
2206
- customerId: string;
2207
- limit?: number;
2208
- }): Promise<UnitUsageList>;
2209
2160
  /**
2210
2161
  * One customer's usage history, merged from every meter kind — credit,
2211
2162
  * outcome, unit, wallet, and completed composite occurrences — into one
@@ -2227,63 +2178,32 @@ declare class Signals {
2227
2178
  }
2228
2179
 
2229
2180
  /**
2230
- * The `units` resource — manage the org's unit *types* (the catalog): named,
2231
- * quantity-priced meters (FLAT / SLAB / VOLUME). Record consumption against a
2232
- * unit with `signals.unit()`. `/api/v1/units-catalog`.
2181
+ * The `units` resource — fixed-price, non-LLM events (uploads, seats, API
2182
+ * calls), priced FLAT, SLAB or VOLUME. `/api/v1/units`.
2183
+ *
2184
+ * There is no `delete()` — the API never deletes catalogue items. Retire a
2185
+ * unit with `archive()`; `unarchive()` brings it back unchanged.
2233
2186
  */
2234
2187
  declare class Units {
2235
2188
  private readonly transport;
2236
2189
  constructor(transport: Transport);
2237
- /** List unit types. Pass `{ active: true }` to only return active ones.
2238
- * `{ active: false }` returns only archived ones; omitting it returns
2239
- * both. See `activeQuery` — the API itself only supports `true`. */
2190
+ /** List them. `{ active: true }` returns only active ones, `{ active: false }`
2191
+ * only archived ones; omit it for both. */
2240
2192
  list(params?: {
2241
2193
  active?: boolean;
2242
2194
  }): Promise<Unit[]>;
2243
- /** Create a unit type. `POST /api/v1/units-catalog`. */
2195
+ /** One unit's configuration. */
2196
+ get(id: string): Promise<Unit>;
2197
+ /** Create one. It starts active. Not retried on failure — a retry could
2198
+ * create a second row. */
2244
2199
  create(input: CreateUnitInput): Promise<Unit>;
2245
- /** Fetch one unit type with stats. `GET /api/v1/units-catalog/:id`. */
2246
- get(id: string): Promise<UnitDetail>;
2247
- /** Update a unit type's definition. `PATCH /api/v1/units-catalog/:id`. */
2200
+ /** PARTIAL update: only the fields you send change. `tiers`, when sent, is
2201
+ * the complete new tier list. */
2248
2202
  update(id: string, input: UpdateUnitInput): Promise<Unit>;
2249
- /** Activate or deactivate a unit type. */
2250
- setActive(id: string, isActive: boolean): Promise<Unit>;
2251
- /** Delete a unit type. */
2252
- delete(id: string): Promise<void>;
2253
- }
2254
-
2255
- /**
2256
- * The `webhooks` resource — threshold alerts. At most one webhook per kind
2257
- * (CREDIT / OUTCOME / WALLET); posting a kind again upserts it. `/api/v1/webhooks`.
2258
- */
2259
- declare class Webhooks {
2260
- private readonly transport;
2261
- constructor(transport: Transport);
2262
- /** List configured webhooks. `GET /api/v1/webhooks`. */
2263
- list(): Promise<Webhook[]>;
2264
- /** Create or replace the webhook for a kind. `POST /api/v1/webhooks`. */
2265
- upsert(input: UpsertWebhookInput): Promise<Webhook>;
2266
- /** Delete the webhook for a kind (idempotent). `DELETE /api/v1/webhooks/:kind`. */
2267
- delete(kind: ThresholdKind): Promise<void>;
2268
- }
2269
-
2270
- /**
2271
- * The `workspace` resource — read-only introspection of the org behind the API
2272
- * key. Grounds an integration (which workspace, and is it `sandbox` or `live`?)
2273
- * and lists the models it may meter against. `/api/v1/me`, `/api/v1/models`.
2274
- */
2275
- declare class Workspace {
2276
- private readonly transport;
2277
- constructor(transport: Transport);
2278
- /** Identify the org + key behind the request, incl. `sandbox` | `live`. */
2279
- me(): Promise<WorkspaceIdentity>;
2280
- /** The org's enabled models with live prices. `{ active: true }` returns only
2281
- * the models that can be metered right now.
2282
- * `{ active: false }` returns only archived ones; omitting it returns
2283
- * both. See `activeQuery` — the API itself only supports `true`. */
2284
- models(params?: {
2285
- active?: boolean;
2286
- }): Promise<Model[]>;
2203
+ /** Retire it (`isActive` → false). Nothing is deleted. Safe to retry. */
2204
+ archive(id: string): Promise<Unit>;
2205
+ /** Bring an archived one back (`isActive` → true). Safe to retry. */
2206
+ unarchive(id: string): Promise<Unit>;
2287
2207
  }
2288
2208
 
2289
2209
  /**
@@ -2304,32 +2224,28 @@ declare class Workspace {
2304
2224
  * ```
2305
2225
  */
2306
2226
  declare class ClockNext {
2307
- /** Record + read usage signals (credit / wallet / outcome / unit). */
2227
+ /** Record usage signals (credit / wallet / outcome / unit) and read the usage log. */
2308
2228
  readonly signals: Signals;
2309
- /** Manage customers, their members, wallet, and balances. */
2229
+ /** Manage customers, their members, and balances. */
2310
2230
  readonly customers: Customers;
2311
- /** Define and manage billing plans. */
2231
+ /** Billing plans: list, get, create, update, archive, unarchive. */
2312
2232
  readonly plans: Plans;
2233
+ /** Credits: list, get, create, update, archive, unarchive (no delete). */
2234
+ readonly credits: Credits;
2235
+ /** Outcomes: list, get, create, update, archive, unarchive (no delete). */
2236
+ readonly outcomes: Outcomes;
2237
+ /** Units: list, get, create, update, archive, unarchive (no delete). */
2238
+ readonly units: Units;
2239
+ /** Composites: list, get, create, update, archive, unarchive (no delete). */
2240
+ readonly composites: Composites;
2313
2241
  /** Subscribe customers to plans (purchases). */
2314
2242
  readonly purchases: Purchases;
2315
2243
  /** Read invoices and mint hosted pay links. */
2316
2244
  readonly invoices: Invoices;
2317
2245
  /** Read payments (paid invoices). */
2318
2246
  readonly payments: Payments;
2319
- /** Manage the credit-type catalog. */
2320
- readonly credits: Credits;
2321
- /** Manage the composite catalog — bundles billed as one thing. */
2322
- readonly composites: Composites;
2323
- /** Manage the outcome-type catalog. */
2324
- readonly outcomes: Outcomes;
2325
- /** Manage the unit-type catalog. */
2326
- readonly units: Units;
2327
- /** Configure threshold webhooks. */
2328
- readonly webhooks: Webhooks;
2329
2247
  /** Mint customer-portal embed tokens. */
2330
2248
  readonly portal: Portal;
2331
- /** Identify the workspace (sandbox/live) + list its models. `/me`, `/models`. */
2332
- readonly workspace: Workspace;
2333
2249
  private readonly cfg;
2334
2250
  private readonly flusher;
2335
2251
  constructor(config: ClockNextConfig);
@@ -2417,4 +2333,4 @@ declare class NetworkError extends ClockNextError {
2417
2333
  });
2418
2334
  }
2419
2335
 
2420
- export { type AddMemberInput, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ClockNextErrorCode, type ComponentType, type Composite, type CompositeAdjustInput, type CompositeCatalogueRef, type CompositeCompletionInput, type CompositeCompletionResult, type CompositeComponentInput, type CompositeTag, ConflictError, type CostPoint, type CostStats, type CreateCompositeInput, type CreateCreditInput, type CreateCustomerInput, type CreateOutcomeInput, type CreatePlanInput, type CreatePurchaseInput, type CreateUnitInput, type Credit, type CreditAdjustInput, type CreditAnalytics, type CreditBalance, type CreditComponentInput, type CreditDetail, type CreditInput, type CreditSignal, type CustomerBalances, type CustomerList, type CustomerPlan, type CustomerPlanDetails, type CustomerProfileInput, type DropReason, type FetchLike, type FlatComponentInput, type FlatUnitInput, ForbiddenError, type Invoice, type InvoiceDetail, type InvoiceLineItem, type InvoiceListRow, type InvoiceParty, type InvoicePlanSnapshot, type InvoiceStatus, type Logger, type Member, type MemberProfile, type Model, type ModelBundleEntry, NetworkError, NotFoundError, type Outcome, type OutcomeAdjustInput, type OutcomeAnalytics, type OutcomeBalance, type OutcomeCompletionInput, type OutcomeCompletionResult, type OutcomeComponentInput, type OutcomeDetail, type OutcomeInput, type OutcomeSignal, type OutcomeStepInput, type PayLink, type PaymentDetail, type PaymentRow, type Plan, type PlanComponent, type PlanComponentInput, type PlanDetail, PlanError, type PlanKind, type PlanRef, type PlanType, type PortalToken, type PortalTokenInput, type Purchase, type PurchaseDetail, type PurchaseStatus, RateLimitError, type RemovedMember, type SerializedOutcomeAttribution, type SerializedRuleApplication, type SerializedUnitUsage, type SerializedUsageLog, ServerError, type Signal, type SignalDelivery, type SignalStatus, type SignalType, type ThresholdKind, type TieredUnitInput, type Tokens, type TrackResult, type Unit, type UnitAdjustInput, type UnitBalance, type UnitComponentInput, type UnitCustomerRow, type UnitDetail, type UnitInput, type UnitPricingType, type UnitTier, type UnitTierInput, type UnitTrackResult, type UnitUsageList, type UnitUsageRow, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateUnitInput, type UpsertWebhookInput, type UsageBalance, type UsageList, type UsageLogAppliedRule, type UsageLogEntry, type UsageLogListParams, type UsageLogOutcomeAttribution, type UsageLogPage, type UsageLogPeriod, ValidationError, type WalletComponentInput, type WalletEntitlementKind, type WalletEntryInput, type WalletInput, type WalletList, type WalletSignal, type WalletTransaction, type WalletTransactionSource, type WalletTransactionType, type Webhook, type WorkspaceIdentity, signalToWire };
2336
+ export { type AddMemberInput, type AdjustResult, AllowanceError, type ApiCustomer, AuthError, type BillingCycle, type BillingMode, ClockNext, type ClockNextConfig, ClockNextError, type ClockNextErrorCode, type ComponentType, type Composite, type CompositeAdjustInput, type CompositeBalance, type CompositeCompletionInput, type CompositeCompletionResult, type CompositeItem, type CompositeTag, ConflictError, type CreateCompositeInput, type CreateCreditInput, type CreateCustomerInput, type CreateOutcomeInput, type CreatePlanInput, type CreatePurchaseInput, type CreateUnitInput, type Credit, type CreditAdjustInput, type CreditBalance, type CreditInput, type CreditSignal, type CustomerBalances, type CustomerList, type CustomerPlan, type CustomerPlanDetails, type CustomerProfileInput, type CustomerRef, type DropReason, type FetchLike, ForbiddenError, type Invoice, type InvoiceDetail, type InvoiceLineItem, type InvoiceListRow, type InvoiceParty, type InvoicePlanSnapshot, type InvoiceStatus, type Logger, type Member, type MemberProfile, type ModelBundleLine, type ModelBundleLineInput, NetworkError, NotFoundError, type Outcome, type OutcomeAdjustInput, type OutcomeBalance, type OutcomeCompletionInput, type OutcomeCompletionResult, type OutcomeInput, type OutcomeSignal, type OutcomeStep, type OutcomeStepInput, type OutcomeWithSteps, type PayLink, type PaymentDetail, type PaymentRow, type Plan, type PlanComponent, type PlanEntitlement, type PlanEntitlementInput, PlanError, type PlanKind, type PlanRef, type PlanType, type PortalToken, type PortalTokenInput, type Purchase, type PurchaseDetail, type PurchaseStatus, RateLimitError, type RecurringGrantInput, type RecurringGrantResult, type RemovedMember, type SerializedOutcomeAttribution, type SerializedRuleApplication, type SerializedUnitUsage, type SerializedUsageLog, ServerError, type Signal, type SignalDelivery, type SignalStatus, type SignalType, type Tokens, type TrackResult, type Unit, type UnitAdjustInput, type UnitBalance, type UnitInput, type UnitPricingType, type UnitTier, type UnitTrackResult, type UpdateCompositeInput, type UpdateCreditInput, type UpdateMemberInput, type UpdateOutcomeInput, type UpdatePlanInput, type UpdateUnitInput, type UsageBalance, type UsageLogAppliedRule, type UsageLogEntry, type UsageLogListParams, type UsageLogOutcomeAttribution, type UsageLogPage, type UsageLogPeriod, ValidationError, type WalletAdjustInput, type WalletInput, type WalletPool, type WalletSignal, signalToWire };