agl 40.4.0 → 40.5.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.
Files changed (149) hide show
  1. package/changelog.md +27 -0
  2. package/dist_serve/bundle.js +2228 -2177
  3. package/dist_serve/bundle.js.map +2 -2
  4. package/dist_ts/00_commitinfo_data.js +1 -1
  5. package/dist_ts/aglapi/aglapisurface.document.js +2 -2
  6. package/dist_ts/classes.accountsactions.d.ts +11 -1
  7. package/dist_ts/classes.accountsactions.js +59 -2
  8. package/dist_ts/classes.controller.js +5 -5
  9. package/dist_ts/classes.flexaccountaccess.js +3 -2
  10. package/dist_ts/classes.harnessreleases.d.ts +14 -4
  11. package/dist_ts/classes.harnessreleases.js +28 -4
  12. package/dist_ts/classes.inferencegateway.d.ts +28 -3
  13. package/dist_ts/classes.inferencegateway.js +177 -61
  14. package/dist_ts/classes.inferenceplacement.d.ts +5 -3
  15. package/dist_ts/classes.inferenceplacement.js +2 -2
  16. package/dist_ts/classes.inferencerouter.d.ts +349 -91
  17. package/dist_ts/classes.inferencerouter.js +804 -297
  18. package/dist_ts/classes.inferenceservice.d.ts +14 -2
  19. package/dist_ts/classes.inferenceservice.js +53 -14
  20. package/dist_ts/classes.inferencespend.d.ts +339 -0
  21. package/dist_ts/classes.inferencespend.js +815 -0
  22. package/dist_ts/classes.inferenceusagecache.d.ts +8 -0
  23. package/dist_ts/classes.inferenceusagecache.js +9 -5
  24. package/dist_ts/classes.inferenceusagetap.d.ts +50 -9
  25. package/dist_ts/classes.inferenceusagetap.js +185 -31
  26. package/dist_ts/classes.proxycontrol.d.ts +3 -2
  27. package/dist_ts/classes.proxycontrol.js +1 -2
  28. package/dist_ts/classes.proxydaemon.js +3 -2
  29. package/dist_ts/classes.proxystore.d.ts +6 -0
  30. package/dist_ts/classes.proxystore.js +11 -2
  31. package/dist_ts/fleet/classes.claudeworkers.d.ts +5 -4
  32. package/dist_ts/fleet/classes.claudeworkers.js +10 -9
  33. package/dist_ts/functions.claudecoderelease.d.ts +12 -6
  34. package/dist_ts/functions.claudecoderelease.js +13 -7
  35. package/dist_ts/functions.inferencecli.js +12 -8
  36. package/dist_ts/interfaces.auth.d.ts +1 -1
  37. package/dist_ts/interfaces.auth.js +3 -1
  38. package/dist_ts/plugins.d.ts +3 -1
  39. package/dist_ts/plugins.js +7 -2
  40. package/dist_ts_authswitch/authority-apikeys.d.ts +32 -0
  41. package/dist_ts_authswitch/authority-apikeys.js +65 -0
  42. package/dist_ts_authswitch/authority-contract.d.ts +142 -28
  43. package/dist_ts_authswitch/authority-contract.js +48 -1
  44. package/dist_ts_authswitch/authority-overview.js +8 -1
  45. package/dist_ts_authswitch/authority-placement.d.ts +7 -2
  46. package/dist_ts_authswitch/authority-placement.js +10 -3
  47. package/dist_ts_authswitch/authority-runtime-contract.d.ts +2 -2
  48. package/dist_ts_authswitch/authority-spend.d.ts +103 -0
  49. package/dist_ts_authswitch/authority-spend.js +110 -0
  50. package/dist_ts_authswitch/authority-subscription.d.ts +12 -1
  51. package/dist_ts_authswitch/authority-subscription.js +24 -1
  52. package/dist_ts_authswitch/authority-usagelimit.d.ts +7 -4
  53. package/dist_ts_authswitch/authority-usagelimit.js +89 -39
  54. package/dist_ts_authswitch/authority-usagewindows.d.ts +4 -1
  55. package/dist_ts_authswitch/authority-usagewindows.js +41 -16
  56. package/dist_ts_authswitch/classes.authoritybroker.d.ts +30 -19
  57. package/dist_ts_authswitch/classes.authoritybroker.js +152 -61
  58. package/dist_ts_authswitch/classes.authoritycli.d.ts +9 -4
  59. package/dist_ts_authswitch/classes.authoritycli.js +94 -29
  60. package/dist_ts_authswitch/classes.authorityclient.d.ts +24 -7
  61. package/dist_ts_authswitch/classes.authorityclient.js +31 -11
  62. package/dist_ts_authswitch/classes.authoritydaemon.js +39 -12
  63. package/dist_ts_authswitch/classes.authoritydatabase.d.ts +28 -5
  64. package/dist_ts_authswitch/classes.authoritydatabase.js +171 -9
  65. package/dist_ts_authswitch/classes.authorityimport.js +2 -2
  66. package/dist_ts_authswitch/classes.authoritymodels.d.ts +71 -3
  67. package/dist_ts_authswitch/classes.authoritymodels.js +249 -20
  68. package/dist_ts_authswitch/classes.authorityregistry.js +4 -2
  69. package/dist_ts_authswitch/classes.authorityusage.d.ts +69 -7
  70. package/dist_ts_authswitch/classes.authorityusage.js +118 -4
  71. package/dist_ts_authswitch/classes.claudenative.d.ts +16 -7
  72. package/dist_ts_authswitch/classes.claudenative.js +29 -16
  73. package/dist_ts_authswitch/classes.claudesignin.js +5 -2
  74. package/dist_ts_authswitch/testsupport.d.ts +24 -5
  75. package/dist_ts_authswitch/testsupport.js +56 -12
  76. package/dist_ts_authswitch/ts_migration/0011_account_api_key_fields.d.ts +12 -0
  77. package/dist_ts_authswitch/ts_migration/0011_account_api_key_fields.js +21 -0
  78. package/dist_ts_authswitch/ts_migration/index.js +3 -1
  79. package/dist_ts_interfaces/functions.authorityscope.d.ts +18 -7
  80. package/dist_ts_interfaces/functions.authorityscope.js +35 -8
  81. package/dist_ts_interfaces/interfaces.d.ts +1 -1
  82. package/dist_ts_interfaces/interfaces.js +1 -1
  83. package/dist_ts_interfaces/plugins.d.ts +2 -1
  84. package/dist_ts_interfaces/plugins.js +7 -4
  85. package/dist_ts_interfaces/requests.accounts.d.ts +56 -0
  86. package/dist_ts_interfaces/requests.accounts.js +11 -1
  87. package/dist_ts_interfaces/requests.d.ts +2 -2
  88. package/dist_ts_interfaces/requests.js +1 -1
  89. package/docs/authswitch.md +75 -12
  90. package/package.json +5 -5
  91. package/readme.md +198 -21
  92. package/ts/00_commitinfo_data.ts +1 -1
  93. package/ts/aglapi/aglapisurface.document.ts +2 -2
  94. package/ts/classes.accountsactions.ts +75 -1
  95. package/ts/classes.controller.ts +4 -4
  96. package/ts/classes.flexaccountaccess.ts +2 -1
  97. package/ts/classes.harnessreleases.ts +25 -4
  98. package/ts/classes.inferencegateway.ts +184 -64
  99. package/ts/classes.inferenceplacement.ts +6 -4
  100. package/ts/classes.inferencerouter.ts +1026 -314
  101. package/ts/classes.inferenceservice.ts +56 -13
  102. package/ts/classes.inferencespend.ts +870 -0
  103. package/ts/classes.inferenceusagecache.ts +16 -4
  104. package/ts/classes.inferenceusagetap.ts +159 -34
  105. package/ts/classes.proxycontrol.ts +3 -3
  106. package/ts/classes.proxydaemon.ts +2 -1
  107. package/ts/classes.proxystore.ts +11 -1
  108. package/ts/fleet/classes.claudeworkers.ts +9 -8
  109. package/ts/functions.claudecoderelease.ts +13 -6
  110. package/ts/functions.inferencecli.ts +11 -7
  111. package/ts/interfaces.auth.ts +2 -0
  112. package/ts/plugins.ts +7 -0
  113. package/ts_authswitch/authority-apikeys.ts +85 -0
  114. package/ts_authswitch/authority-contract.ts +167 -29
  115. package/ts_authswitch/authority-overview.ts +7 -0
  116. package/ts_authswitch/authority-placement.ts +12 -4
  117. package/ts_authswitch/authority-runtime-contract.ts +2 -2
  118. package/ts_authswitch/authority-spend.ts +168 -0
  119. package/ts_authswitch/authority-subscription.ts +28 -1
  120. package/ts_authswitch/authority-usagelimit.ts +95 -40
  121. package/ts_authswitch/authority-usagewindows.ts +42 -17
  122. package/ts_authswitch/classes.authoritybroker.ts +161 -68
  123. package/ts_authswitch/classes.authoritycli.ts +108 -32
  124. package/ts_authswitch/classes.authorityclient.ts +41 -10
  125. package/ts_authswitch/classes.authoritydaemon.ts +43 -13
  126. package/ts_authswitch/classes.authoritydatabase.ts +178 -8
  127. package/ts_authswitch/classes.authorityimport.ts +1 -1
  128. package/ts_authswitch/classes.authoritymodels.ts +165 -19
  129. package/ts_authswitch/classes.authorityregistry.ts +3 -0
  130. package/ts_authswitch/classes.authorityusage.ts +171 -10
  131. package/ts_authswitch/classes.claudenative.ts +28 -15
  132. package/ts_authswitch/classes.claudesignin.ts +4 -1
  133. package/ts_authswitch/native-contracts.md +81 -20
  134. package/ts_authswitch/readme.md +1 -1
  135. package/ts_authswitch/testsupport.ts +58 -11
  136. package/ts_authswitch/ts_migration/0011_account_api_key_fields.ts +20 -0
  137. package/ts_authswitch/ts_migration/index.ts +2 -0
  138. package/ts_interfaces/functions.authorityscope.ts +43 -8
  139. package/ts_interfaces/interfaces.ts +1 -1
  140. package/ts_interfaces/plugins.ts +6 -3
  141. package/ts_interfaces/requests.accounts.ts +48 -0
  142. package/ts_interfaces/requests.ts +4 -0
  143. package/ts_web/00_commitinfo_data.ts +1 -1
  144. package/ts_web/accounts.plugins.ts +3 -1
  145. package/ts_web/accounts.templates.ts +20 -11
  146. package/ts_web/classes.accountsreadmodel.ts +322 -70
  147. package/ts_web/elements.accounts.ts +219 -20
  148. package/ts_web/elements.codexconnections.ts +3 -1
  149. package/ts_web/plugins.ts +4 -2
@@ -1,5 +1,5 @@
1
1
  import * as plugins from './plugins.js';
2
- import { AuthSwitchAuthorityAccountModel, AuthSwitchAuthorityBindingModel, AuthSwitchAuthorityClaudeContainerHomeModel, AuthSwitchAuthorityClaudeHandoffModel, AuthSwitchAuthorityClaudeHomeModel, AuthSwitchAuthorityCodexHandoffModel, AuthSwitchAuthorityCodexHomeModel, AuthSwitchAuthorityCodexHostHomeModel, AuthSwitchAuthorityEnrollmentModel, AuthSwitchAuthorityEventModel, AuthSwitchAuthorityGrantModel, AuthSwitchAuthorityHandoffModel, AuthSwitchAuthorityMetaModel, AuthSwitchAuthorityMigrationLedgerModel, AuthSwitchAuthorityOperationModel, AuthSwitchAuthorityUsageEstimateModel, AuthSwitchAuthorityUsageModel, } from './classes.authoritymodels.js';
2
+ import { AuthSwitchAuthorityAccountModel, AuthSwitchAuthorityBindingModel, AuthSwitchAuthorityClaudeContainerHomeModel, AuthSwitchAuthorityClaudeHandoffModel, AuthSwitchAuthorityClaudeHomeModel, AuthSwitchAuthorityCodexHandoffModel, AuthSwitchAuthorityCodexHomeModel, AuthSwitchAuthorityCodexHostHomeModel, AuthSwitchAuthorityEnrollmentModel, AuthSwitchAuthorityEventModel, AuthSwitchAuthorityGrantModel, AuthSwitchAuthorityHandoffModel, AuthSwitchAuthorityMetaModel, AuthSwitchAuthorityMigrationLedgerModel, AuthSwitchAuthorityOperationModel, AuthSwitchAuthoritySpendEntryModel, AuthSwitchAuthoritySpendPeriodModel, AuthSwitchAuthorityUsageEstimateModel, AuthSwitchAuthorityUsageModel, } from './classes.authoritymodels.js';
3
3
  const define = (name, model) => Object.freeze({
4
4
  name,
5
5
  initialize: async (db) => {
@@ -25,6 +25,8 @@ export const authorityModelRegistry = Object.freeze([
25
25
  define('authswitch_authority_meta', AuthSwitchAuthorityMetaModel),
26
26
  define('authswitch_authority_migration_ledger', AuthSwitchAuthorityMigrationLedgerModel),
27
27
  define('authswitch_authority_operations', AuthSwitchAuthorityOperationModel),
28
+ define('authswitch_authority_spend_entries', AuthSwitchAuthoritySpendEntryModel),
29
+ define('authswitch_authority_spend_periods', AuthSwitchAuthoritySpendPeriodModel),
28
30
  define('authswitch_authority_usage', AuthSwitchAuthorityUsageModel),
29
31
  define('authswitch_authority_usage_estimates', AuthSwitchAuthorityUsageEstimateModel),
30
32
  ]);
@@ -33,4 +35,4 @@ for (let index = 1; index < authorityModelRegistry.length; index++) {
33
35
  throw new Error('Authority model registry must be unique and sorted.');
34
36
  }
35
37
  }
36
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xhc3Nlcy5hdXRob3JpdHlyZWdpc3RyeS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3RzX2F1dGhzd2l0Y2gvY2xhc3Nlcy5hdXRob3JpdHlyZWdpc3RyeS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssT0FBTyxNQUFNLGNBQWMsQ0FBQztBQUN4QyxPQUFPLEVBQ0wsK0JBQStCLEVBQUUsK0JBQStCLEVBQUUsMkNBQTJDLEVBQzdHLHFDQUFxQyxFQUNyQyxrQ0FBa0MsRUFBRSxvQ0FBb0MsRUFBRSxpQ0FBaUMsRUFDM0cscUNBQXFD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GLENBQUMsQ0FBQztBQUVILEtBQUssSUFBSSxLQUFLLEdBQUcsQ0FBQyxFQUFFLEtBQUssR0FBRyxzQkFBc0IsQ0FBQyxNQUFNLEVBQUUsS0FBSyxFQUFFLEVBQUUsQ0FBQztJQUNuRSxJQUFJLHNCQUFzQixDQUFDLEtBQUssR0FBRyxDQUFDLENBQUMsQ0FBQyxJQUFJLElBQUksc0JBQXNCLENBQUMsS0FBSyxDQUFDLENBQUMsSUFBSSxFQUFFLENBQUM7UUFDakYsTUFBTSxJQUFJLEtBQUssQ0FBQyxxREFBcUQsQ0FBQyxDQUFDO0lBQ3pFLENBQUM7QUFDSCxDQUFDIn0=
@@ -3,14 +3,16 @@ import type { IOpenAiAccountRateLimits } from './interfaces.openai.js';
3
3
  import type { IClaudeLogin, IClaudeStatusRead, IClaudeSubscription } from './classes.claudestatus.js';
4
4
  import { type TAuthSwitchUsageObservation } from './authority-usageheaders.js';
5
5
  import type { IAuthSwitchTokenUsage } from './authority-usagetokens.js';
6
+ import { type IAuthSwitchSpendReading } from './authority-spend.js';
7
+ import type { IAuthSwitchSpendAnswer, TAuthSwitchPaymentProblemCause as TCause } from './authority-contract.js';
6
8
  import { type IAuthSwitchUsageEstimateState, type IAuthSwitchUsageEstimatorOptions, type TAuthSwitchEstimateBasis } from './classes.authorityusageestimate.js';
7
9
  type TRateLimits = IOpenAiAccountRateLimits;
8
10
  /**
9
11
  * Why a usage reading is missing or incomplete. `held_in_container`: the Claude login runs in a registered container
10
12
  * home, whose files are the container's; the authority reads its usage again once the login is moved out. `pending`:
11
- * the account's first read has not finished yet.
13
+ * the account's first read has not finished yet. `spend_unavailable`: an API key's spend ledger could not be read.
12
14
  */
13
- export type TAuthSwitchUsageProblem = 'none' | 'unsupported' | 'access_unavailable' | 'provider_unavailable' | 'provider_rejected' | 'profile_unavailable' | 'usage_unavailable' | 'context_changed' | 'expired' | 'held_in_container' | 'pending';
15
+ export type TAuthSwitchUsageProblem = 'none' | 'unsupported' | 'access_unavailable' | 'provider_unavailable' | 'provider_rejected' | 'profile_unavailable' | 'usage_unavailable' | 'context_changed' | 'expired' | 'held_in_container' | 'pending' | 'spend_unavailable';
14
16
  export interface IAuthSwitchNativeUsageSource {
15
17
  homeId: string;
16
18
  credentialDigest: string;
@@ -72,13 +74,22 @@ export interface IAuthSwitchClaudeStatus {
72
74
  retryAt: string | null;
73
75
  } | null;
74
76
  }
75
- export type TAuthSwitchUsageReading = {
77
+ /** A usage reading the authority reads from a provider for a subscription sign-in, and stores between its runs. */
78
+ export type TAuthSwitchProviderUsageReading = {
76
79
  kind: 'openai';
77
80
  rateLimits: TRateLimits;
78
81
  } | {
79
82
  kind: 'anthropic';
80
83
  status: IAuthSwitchClaudeStatus;
81
84
  };
85
+ /**
86
+ * A login's usage reading: a subscription sign-in's, as its provider stated it, or an API key's monthly spend
87
+ * (`spend`), which the authority answers from what AGL's inference proxy reported and never reads from a provider.
88
+ */
89
+ export type TAuthSwitchUsageReading = TAuthSwitchProviderUsageReading | {
90
+ kind: 'spend';
91
+ spend: IAuthSwitchSpendReading;
92
+ };
82
93
  export interface IAuthSwitchUsageAccess {
83
94
  accessToken: string;
84
95
  accountId: string;
@@ -101,9 +112,31 @@ export interface IAuthSwitchUsageAccess {
101
112
  export interface IAuthSwitchPaymentProblem {
102
113
  at: string;
103
114
  subscription: IClaudeSubscription | null;
115
+ /**
116
+ * What the provider refused for (`TAuthSwitchPaymentProblemCause`), present only for `spend_cap` and `quota`, which
117
+ * only an API key's login is held with; absent, the cause is `billing`, on a Claude login and an API key alike. A
118
+ * problem with a cause has no subscription.
119
+ */
120
+ cause?: Exclude<TAuthSwitchPaymentProblemCause, 'billing'>;
121
+ /**
122
+ * When a `spend_cap` lifts by itself: the end of the month in UTC `at` falls in (`authSwitchSpendPeriod(at).end`),
123
+ * present exactly for that cause; once it passed the problem holds nothing (`authSwitchPaymentProblemHeld`). Every
124
+ * other problem holds until it is cleared: a Claude login's by a read, an API key's by a re-check (`usage.recheck`).
125
+ */
126
+ until?: string;
104
127
  }
105
128
  /**
106
- * How a re-check's read went (`AuthSwitchAuthorityUsage.recheck`): `healthy` -- the profile was found, the sign-in
129
+ * Why a provider refused inference on an API key for money, as AGL's inference proxy read the refusal: `billing`, the
130
+ * organization's billing (Anthropic HTTP 402 `billing_error`, and every Claude sign-in's payment problem); `spend_cap`,
131
+ * the monthly spend cap of the key's usage tier, which lifts at 00:00 UTC on the first of the next month (Anthropic 429
132
+ * `enforced_spend_limit_reached`); `quota`, the organization's or project's credit or spend limit (OpenAI 429
133
+ * `insufficient_quota`).
134
+ */
135
+ export type TAuthSwitchPaymentProblemCause = 'billing' | 'spend_cap' | 'quota';
136
+ /**
137
+ * How a re-check went (`AuthSwitchAuthorityUsage.recheck`). `cleared`: the login is an API key, whose hold a re-check
138
+ * lifts without asking the provider, which states no billing or quota on a model list; the next request shows whether the
139
+ * provider takes the key again. Every other outcome is a Claude login's read: `healthy` -- the profile was found, the sign-in
107
140
  * accepted and the identity matched -- clears a payment problem; every other outcome clears nothing. `credential_rejected`:
108
141
  * Anthropic rejected the sign-in, renewed too. `token_unusable`: no access token usable for a profile read (it could not
109
142
  * be resolved, is not fresh enough, or lacks the `user:profile` scope). `profile_missing`: the profile read failed or its
@@ -111,7 +144,7 @@ export interface IAuthSwitchPaymentProblem {
111
144
  * run or publish -- the login changed or is not read, its record could not be written, or the usage service's retry time
112
145
  * lies ahead.
113
146
  */
114
- export type TAuthSwitchRecheckOutcome = 'healthy' | 'credential_rejected' | 'token_unusable' | 'profile_missing' | 'mismatch' | 'read_failed';
147
+ export type TAuthSwitchRecheckOutcome = 'healthy' | 'credential_rejected' | 'token_unusable' | 'profile_missing' | 'mismatch' | 'read_failed' | 'cleared';
115
148
  /** A re-check's answer: the usage the authority holds once its read finished, and how that read went. */
116
149
  export interface IAuthSwitchUsageRecheck {
117
150
  usage: IAuthSwitchUsageSnapshot;
@@ -121,7 +154,7 @@ export interface IAuthSwitchUsageRecheck {
121
154
  export interface IAuthSwitchStoredUsage {
122
155
  context: IAuthSwitchUsageContext;
123
156
  updateId: string;
124
- reading: TAuthSwitchUsageReading | null;
157
+ reading: TAuthSwitchProviderUsageReading | null;
125
158
  observedAt: string | null;
126
159
  currentUntil: string | null;
127
160
  staleUntil: string | null;
@@ -265,6 +298,14 @@ export interface IAuthSwitchAuthorityUsageOptions {
265
298
  estimate?: IAuthSwitchUsageEstimatorOptions;
266
299
  /** Where the reader's notes go, one line each: standard error, the service's journal, unless set. */
267
300
  log?: (lineArg: string) => void;
301
+ /**
302
+ * An API key's spend ledger: its month's reading at `nowArg`, and a spend report recorded in one transaction
303
+ * (`AuthSwitchAuthorityDatabase.readSpend`, `.recordSpend`). Without it the authority answers no key's usage.
304
+ */
305
+ spend?: {
306
+ read(accountId: string, loginId: string, nowArg: number): Promise<IAuthSwitchSpendReading>;
307
+ record(accountId: string, loginId: string, answers: readonly IAuthSwitchSpendAnswer[], nowArg: number): Promise<IAuthSwitchSpendReading>;
308
+ };
268
309
  }
269
310
  /** What a client that served requests on a login reports about the account: see `report`. */
270
311
  export interface IAuthSwitchUsageReport {
@@ -358,7 +399,7 @@ export declare class AuthSwitchAuthorityUsage {
358
399
  * carries it. Refused for any login but a Claude login the authority renews, and for one with no usage record of its
359
400
  * sign-in yet, which the proxy never routed to. The provider is not asked.
360
401
  */
361
- reportPaymentProblem(accountId: string, loginId: string, observedAt: string): Promise<IAuthSwitchUsageSnapshot>;
402
+ reportPaymentProblem(accountId: string, loginId: string, observedAt: string, cause?: TCause): Promise<IAuthSwitchUsageSnapshot>;
362
403
  /**
363
404
  * Reads the login at once, as `requestRead` does, and answers how that read went with the usage held once it finished
364
405
  * (`IAuthSwitchUsageRecheck`). It is a re-check: a read that finds the profile, its sign-in accepted and its identity
@@ -367,6 +408,27 @@ export declare class AuthSwitchAuthorityUsage {
367
408
  * than `recheckWaitMs` is not waited for: the answer is then `read_failed`, and the next read is no re-check.
368
409
  */
369
410
  recheck(accountId: string, loginId: string): Promise<IAuthSwitchUsageRecheck>;
411
+ /**
412
+ * Records what answers relayed on an API key's login cost (`authswitch.authority.usage.spend`) and answers the key's
413
+ * usage once the report committed. A removed key's spend is recorded too; its usage then answers unavailable.
414
+ */
415
+ recordSpend(accountId: string, loginId: string, answers: readonly IAuthSwitchSpendAnswer[]): Promise<IAuthSwitchUsageSnapshot>;
416
+ /**
417
+ * An API key's usage: its month's spend from the ledger, current as of now, which stays current until the month ends
418
+ * or a report or a limit change moves it, and the payment problem it is held with, while it holds.
419
+ */
420
+ private spendAnswer;
421
+ /**
422
+ * Holds an API key with a payment problem on its usage record, which holds nothing else: when it was seen -- a time
423
+ * ahead of the authority's clock counts as now -- and its cause; `billing` is written as no cause, and a `spend_cap`
424
+ * lifts at the end of the month it was seen in. False when another write of the record landed first.
425
+ */
426
+ private holdApiKey;
427
+ /**
428
+ * A re-check of an API key: lifts the payment problem it is held with, without asking the provider, whose model list
429
+ * states no billing or quota; the next request shows whether the provider takes the key again.
430
+ */
431
+ private clearApiKey;
370
432
  /** Logs a Claude subscription status the first time this run reads it, up to `maximumLoggedSubscriptionStatuses`. */
371
433
  private noteSubscriptionStatus;
372
434
  /**