@oxy.so/contracts 1.0.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 (147) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +16 -0
  3. package/dist/cjs/.tsbuildinfo +1 -0
  4. package/dist/cjs/accountGraph.js +489 -0
  5. package/dist/cjs/agency.js +439 -0
  6. package/dist/cjs/browserHub.js +215 -0
  7. package/dist/cjs/civic.js +163 -0
  8. package/dist/cjs/commonsSignIn.js +59 -0
  9. package/dist/cjs/deviceBoot.js +50 -0
  10. package/dist/cjs/deviceDirectory.js +189 -0
  11. package/dist/cjs/devicePairing.js +138 -0
  12. package/dist/cjs/deviceSession.js +164 -0
  13. package/dist/cjs/emailAgentContext.js +32 -0
  14. package/dist/cjs/followGraph.js +28 -0
  15. package/dist/cjs/identity.js +258 -0
  16. package/dist/cjs/inboxPush.js +24 -0
  17. package/dist/cjs/index.js +618 -0
  18. package/dist/cjs/inference/accountBilling.js +334 -0
  19. package/dist/cjs/inference/aliaModelRelease.js +262 -0
  20. package/dist/cjs/inference/attribution.js +106 -0
  21. package/dist/cjs/inference/catalogue.js +487 -0
  22. package/dist/cjs/inference/entitlement.js +217 -0
  23. package/dist/cjs/inference/errors.js +309 -0
  24. package/dist/cjs/inference/identifiers.js +224 -0
  25. package/dist/cjs/inference/inbox.js +105 -0
  26. package/dist/cjs/inference/modelDocumentation.js +433 -0
  27. package/dist/cjs/inference/money.js +188 -0
  28. package/dist/cjs/inference/priceVersion.js +110 -0
  29. package/dist/cjs/inference/providerConnection.js +455 -0
  30. package/dist/cjs/inference/request.js +477 -0
  31. package/dist/cjs/inference/routingPolicy.js +318 -0
  32. package/dist/cjs/inference/streamEvents.js +258 -0
  33. package/dist/cjs/inference/usage.js +329 -0
  34. package/dist/cjs/inference/version.js +105 -0
  35. package/dist/cjs/keyRecovery.js +91 -0
  36. package/dist/cjs/keyRotation.js +75 -0
  37. package/dist/cjs/links.js +68 -0
  38. package/dist/cjs/moderationReputation.js +298 -0
  39. package/dist/cjs/oauth.js +66 -0
  40. package/dist/cjs/oxyRecordTypes.js +71 -0
  41. package/dist/cjs/protocol.js +53 -0
  42. package/dist/cjs/recommendations.js +168 -0
  43. package/dist/cjs/reputation.js +297 -0
  44. package/dist/cjs/sessionStatus.js +121 -0
  45. package/dist/cjs/transparency.js +89 -0
  46. package/dist/cjs/updates.js +252 -0
  47. package/dist/cjs/userInvalidation.js +89 -0
  48. package/dist/cjs/userResponse.js +245 -0
  49. package/dist/cjs/username.js +290 -0
  50. package/dist/cjs/webauthn.js +71 -0
  51. package/dist/esm/.tsbuildinfo +1 -0
  52. package/dist/esm/accountGraph.js +480 -0
  53. package/dist/esm/agency.js +436 -0
  54. package/dist/esm/browserHub.js +212 -0
  55. package/dist/esm/civic.js +160 -0
  56. package/dist/esm/commonsSignIn.js +56 -0
  57. package/dist/esm/deviceBoot.js +47 -0
  58. package/dist/esm/deviceDirectory.js +186 -0
  59. package/dist/esm/devicePairing.js +135 -0
  60. package/dist/esm/deviceSession.js +161 -0
  61. package/dist/esm/emailAgentContext.js +29 -0
  62. package/dist/esm/followGraph.js +27 -0
  63. package/dist/esm/identity.js +255 -0
  64. package/dist/esm/inboxPush.js +21 -0
  65. package/dist/esm/index.js +172 -0
  66. package/dist/esm/inference/accountBilling.js +331 -0
  67. package/dist/esm/inference/aliaModelRelease.js +259 -0
  68. package/dist/esm/inference/attribution.js +103 -0
  69. package/dist/esm/inference/catalogue.js +484 -0
  70. package/dist/esm/inference/entitlement.js +214 -0
  71. package/dist/esm/inference/errors.js +306 -0
  72. package/dist/esm/inference/identifiers.js +221 -0
  73. package/dist/esm/inference/inbox.js +102 -0
  74. package/dist/esm/inference/modelDocumentation.js +430 -0
  75. package/dist/esm/inference/money.js +185 -0
  76. package/dist/esm/inference/priceVersion.js +107 -0
  77. package/dist/esm/inference/providerConnection.js +452 -0
  78. package/dist/esm/inference/request.js +474 -0
  79. package/dist/esm/inference/routingPolicy.js +315 -0
  80. package/dist/esm/inference/streamEvents.js +255 -0
  81. package/dist/esm/inference/usage.js +326 -0
  82. package/dist/esm/inference/version.js +102 -0
  83. package/dist/esm/keyRecovery.js +88 -0
  84. package/dist/esm/keyRotation.js +72 -0
  85. package/dist/esm/links.js +65 -0
  86. package/dist/esm/moderationReputation.js +295 -0
  87. package/dist/esm/oauth.js +63 -0
  88. package/dist/esm/oxyRecordTypes.js +68 -0
  89. package/dist/esm/protocol.js +50 -0
  90. package/dist/esm/recommendations.js +165 -0
  91. package/dist/esm/reputation.js +293 -0
  92. package/dist/esm/sessionStatus.js +118 -0
  93. package/dist/esm/transparency.js +86 -0
  94. package/dist/esm/updates.js +249 -0
  95. package/dist/esm/userInvalidation.js +85 -0
  96. package/dist/esm/userResponse.js +240 -0
  97. package/dist/esm/username.js +283 -0
  98. package/dist/esm/webauthn.js +68 -0
  99. package/dist/types/.tsbuildinfo +1 -0
  100. package/dist/types/accountGraph.d.ts +378 -0
  101. package/dist/types/agency.d.ts +2162 -0
  102. package/dist/types/browserHub.d.ts +856 -0
  103. package/dist/types/civic.d.ts +338 -0
  104. package/dist/types/commonsSignIn.d.ts +58 -0
  105. package/dist/types/deviceBoot.d.ts +74 -0
  106. package/dist/types/deviceDirectory.d.ts +1317 -0
  107. package/dist/types/devicePairing.d.ts +130 -0
  108. package/dist/types/deviceSession.d.ts +411 -0
  109. package/dist/types/emailAgentContext.d.ts +248 -0
  110. package/dist/types/followGraph.d.ts +150 -0
  111. package/dist/types/identity.d.ts +402 -0
  112. package/dist/types/inboxPush.d.ts +30 -0
  113. package/dist/types/index.d.ts +100 -0
  114. package/dist/types/inference/accountBilling.d.ts +738 -0
  115. package/dist/types/inference/aliaModelRelease.d.ts +609 -0
  116. package/dist/types/inference/attribution.d.ts +176 -0
  117. package/dist/types/inference/catalogue.d.ts +1618 -0
  118. package/dist/types/inference/entitlement.d.ts +519 -0
  119. package/dist/types/inference/errors.d.ts +242 -0
  120. package/dist/types/inference/identifiers.d.ts +182 -0
  121. package/dist/types/inference/inbox.d.ts +374 -0
  122. package/dist/types/inference/modelDocumentation.d.ts +1603 -0
  123. package/dist/types/inference/money.d.ts +185 -0
  124. package/dist/types/inference/priceVersion.d.ts +182 -0
  125. package/dist/types/inference/providerConnection.d.ts +968 -0
  126. package/dist/types/inference/request.d.ts +2800 -0
  127. package/dist/types/inference/routingPolicy.d.ts +616 -0
  128. package/dist/types/inference/streamEvents.d.ts +950 -0
  129. package/dist/types/inference/usage.d.ts +1164 -0
  130. package/dist/types/inference/version.d.ts +102 -0
  131. package/dist/types/keyRecovery.d.ts +138 -0
  132. package/dist/types/keyRotation.d.ts +103 -0
  133. package/dist/types/links.d.ts +96 -0
  134. package/dist/types/moderationReputation.d.ts +487 -0
  135. package/dist/types/oauth.d.ts +86 -0
  136. package/dist/types/oxyRecordTypes.d.ts +62 -0
  137. package/dist/types/protocol.d.ts +86 -0
  138. package/dist/types/recommendations.d.ts +542 -0
  139. package/dist/types/reputation.d.ts +457 -0
  140. package/dist/types/sessionStatus.d.ts +231 -0
  141. package/dist/types/transparency.d.ts +392 -0
  142. package/dist/types/updates.d.ts +545 -0
  143. package/dist/types/userInvalidation.d.ts +94 -0
  144. package/dist/types/userResponse.d.ts +1706 -0
  145. package/dist/types/username.d.ts +265 -0
  146. package/dist/types/webauthn.d.ts +77 -0
  147. package/package.json +87 -0
@@ -0,0 +1,1164 @@
1
+ /**
2
+ * The reserve → settle → refund protocol.
3
+ *
4
+ * Four records, in the order they happen:
5
+ *
6
+ * 1. **Reservation** — before a request enters the data plane, Oxy holds the
7
+ * MAXIMUM the request could cost (input units + maximum output + the
8
+ * allowed route's price ceiling). A request whose account cannot cover that
9
+ * hold is rejected before anything is spent upstream.
10
+ * 2. **Usage report** — the data plane's technical account of what was
11
+ * consumed. Units and route, never money: the data plane measures, the
12
+ * control plane prices.
13
+ * 3. **Receipt** — the immutable settlement. Carries the exact units, a COPY
14
+ * of the prices they were charged at, and the amount booked. It is never
15
+ * edited afterwards.
16
+ * 4. **Refund/reversal** — an equally immutable entry that releases an unused
17
+ * hold or reverses a settled charge. Settled history is compensated, never
18
+ * rewritten, because an invoice a customer already received must remain
19
+ * reconstructible.
20
+ *
21
+ * Every one of them is keyed by an idempotency key, so a retried call, a
22
+ * redelivered event or a duplicated webhook produces the same record rather than
23
+ * a second charge.
24
+ *
25
+ * Money is an exact decimal string throughout (ADR 0009 — never integer minor
26
+ * units, never a float), and unit counts are carried separately from it (see
27
+ * `money.ts`).
28
+ *
29
+ * Decided in: docs/adr/0009-usage-reservation-and-settlement.md.
30
+ */
31
+ import { z } from 'zod';
32
+ /**
33
+ * Ask the ledger to hold the maximum a request could cost.
34
+ *
35
+ * `maxAmount` is the number the balance check is made against, and it is
36
+ * computed from the three inputs beside it rather than guessed: the units
37
+ * already known (the prompt), the ceiling on units still to come
38
+ * (`maxOutputTokens`), and the most expensive route the policy allows. Sizing a
39
+ * hold from a typical response rather than the worst allowed one is how a
40
+ * balance goes negative on a long generation.
41
+ */
42
+ export declare const usageReservationRequestSchema: z.ZodObject<{
43
+ /** See `version.ts`: exchanged between the edge and the ledger on its own. */
44
+ schemaVersion: z.ZodLiteral<1>;
45
+ idempotencyKey: z.ZodString;
46
+ attribution: z.ZodObject<{
47
+ principal: z.ZodObject<{
48
+ billing: z.ZodObject<{
49
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
50
+ }, "strict", z.ZodTypeAny, {
51
+ accountId: string & z.BRAND<"OxyAccountId">;
52
+ }, {
53
+ accountId: string;
54
+ }>;
55
+ applicationId: z.ZodString;
56
+ credentialId: z.ZodString;
57
+ environment: z.ZodEnum<["development", "staging", "production"]>;
58
+ inferenceScopes: z.ZodArray<z.ZodEnum<["inference:invoke", "inference:models:read", "inference:usage:read", "inference:routing:read", "inference:routing:write", "inference:providers:read", "inference:providers:write"]>, "many">;
59
+ }, "strip", z.ZodTypeAny, {
60
+ environment: "development" | "staging" | "production";
61
+ applicationId: string;
62
+ credentialId: string;
63
+ billing: {
64
+ accountId: string & z.BRAND<"OxyAccountId">;
65
+ };
66
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
67
+ }, {
68
+ environment: "development" | "staging" | "production";
69
+ applicationId: string;
70
+ credentialId: string;
71
+ billing: {
72
+ accountId: string;
73
+ };
74
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
75
+ }>;
76
+ userId: z.ZodOptional<z.ZodBranded<z.ZodString, "DelegatedUserId">>;
77
+ requestId: z.ZodString;
78
+ generationId: z.ZodOptional<z.ZodString>;
79
+ }, "strip", z.ZodTypeAny, {
80
+ requestId: string;
81
+ principal: {
82
+ environment: "development" | "staging" | "production";
83
+ applicationId: string;
84
+ credentialId: string;
85
+ billing: {
86
+ accountId: string & z.BRAND<"OxyAccountId">;
87
+ };
88
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
89
+ };
90
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
91
+ generationId?: string | undefined;
92
+ }, {
93
+ requestId: string;
94
+ principal: {
95
+ environment: "development" | "staging" | "production";
96
+ applicationId: string;
97
+ credentialId: string;
98
+ billing: {
99
+ accountId: string;
100
+ };
101
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
102
+ };
103
+ userId?: string | undefined;
104
+ generationId?: string | undefined;
105
+ }>;
106
+ /** Units already determined by the request itself, e.g. input tokens. */
107
+ knownUnits: z.ZodDefault<z.ZodArray<z.ZodObject<{
108
+ unit: z.ZodEnum<["input_tokens", "cached_input_tokens", "output_tokens", "reasoning_tokens", "requests", "images", "audio_input_milliseconds", "audio_output_milliseconds", "video_milliseconds", "characters", "embeddings"]>;
109
+ quantity: z.ZodNumber;
110
+ }, "strict", z.ZodTypeAny, {
111
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
112
+ quantity: number;
113
+ }, {
114
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
115
+ quantity: number;
116
+ }>, "many">>;
117
+ /** The ceiling on generated output, when the request set one. */
118
+ maxOutputTokens: z.ZodOptional<z.ZodNumber>;
119
+ /** The price version of the most expensive route the policy permits. */
120
+ ceilingPriceVersionId: z.ZodString;
121
+ maxAmount: z.ZodBranded<z.ZodString, "ExactDecimal">;
122
+ currency: z.ZodString;
123
+ expiresInSeconds: z.ZodNumber;
124
+ }, "strip", z.ZodTypeAny, {
125
+ schemaVersion: 1;
126
+ currency: string;
127
+ attribution: {
128
+ requestId: string;
129
+ principal: {
130
+ environment: "development" | "staging" | "production";
131
+ applicationId: string;
132
+ credentialId: string;
133
+ billing: {
134
+ accountId: string & z.BRAND<"OxyAccountId">;
135
+ };
136
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
137
+ };
138
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
139
+ generationId?: string | undefined;
140
+ };
141
+ idempotencyKey: string;
142
+ knownUnits: {
143
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
144
+ quantity: number;
145
+ }[];
146
+ ceilingPriceVersionId: string;
147
+ maxAmount: string & z.BRAND<"ExactDecimal">;
148
+ expiresInSeconds: number;
149
+ maxOutputTokens?: number | undefined;
150
+ }, {
151
+ schemaVersion: 1;
152
+ currency: string;
153
+ attribution: {
154
+ requestId: string;
155
+ principal: {
156
+ environment: "development" | "staging" | "production";
157
+ applicationId: string;
158
+ credentialId: string;
159
+ billing: {
160
+ accountId: string;
161
+ };
162
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
163
+ };
164
+ userId?: string | undefined;
165
+ generationId?: string | undefined;
166
+ };
167
+ idempotencyKey: string;
168
+ ceilingPriceVersionId: string;
169
+ maxAmount: string;
170
+ expiresInSeconds: number;
171
+ maxOutputTokens?: number | undefined;
172
+ knownUnits?: {
173
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
174
+ quantity: number;
175
+ }[] | undefined;
176
+ }>;
177
+ /** Lifecycle of a hold. Terminal states are `settled`, `released`, `expired`. */
178
+ export declare const usageReservationStatusSchema: z.ZodEnum<["held", "settled", "released", "expired"]>;
179
+ /**
180
+ * A hold placed against an account's balance.
181
+ *
182
+ * Reserved amounts are shown to customers distinctly from settled charges: a
183
+ * reservation is not money spent, and presenting the two as one number makes a
184
+ * balance appear to drop and then recover for every request.
185
+ */
186
+ export declare const usageReservationSchema: z.ZodEffects<z.ZodObject<{
187
+ /** See `version.ts`: read back by the edge and the Console on its own. */
188
+ schemaVersion: z.ZodLiteral<1>;
189
+ reservationId: z.ZodString;
190
+ idempotencyKey: z.ZodString;
191
+ attribution: z.ZodObject<{
192
+ principal: z.ZodObject<{
193
+ billing: z.ZodObject<{
194
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
195
+ }, "strict", z.ZodTypeAny, {
196
+ accountId: string & z.BRAND<"OxyAccountId">;
197
+ }, {
198
+ accountId: string;
199
+ }>;
200
+ applicationId: z.ZodString;
201
+ credentialId: z.ZodString;
202
+ environment: z.ZodEnum<["development", "staging", "production"]>;
203
+ inferenceScopes: z.ZodArray<z.ZodEnum<["inference:invoke", "inference:models:read", "inference:usage:read", "inference:routing:read", "inference:routing:write", "inference:providers:read", "inference:providers:write"]>, "many">;
204
+ }, "strip", z.ZodTypeAny, {
205
+ environment: "development" | "staging" | "production";
206
+ applicationId: string;
207
+ credentialId: string;
208
+ billing: {
209
+ accountId: string & z.BRAND<"OxyAccountId">;
210
+ };
211
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
212
+ }, {
213
+ environment: "development" | "staging" | "production";
214
+ applicationId: string;
215
+ credentialId: string;
216
+ billing: {
217
+ accountId: string;
218
+ };
219
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
220
+ }>;
221
+ userId: z.ZodOptional<z.ZodBranded<z.ZodString, "DelegatedUserId">>;
222
+ requestId: z.ZodString;
223
+ generationId: z.ZodOptional<z.ZodString>;
224
+ }, "strip", z.ZodTypeAny, {
225
+ requestId: string;
226
+ principal: {
227
+ environment: "development" | "staging" | "production";
228
+ applicationId: string;
229
+ credentialId: string;
230
+ billing: {
231
+ accountId: string & z.BRAND<"OxyAccountId">;
232
+ };
233
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
234
+ };
235
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
236
+ generationId?: string | undefined;
237
+ }, {
238
+ requestId: string;
239
+ principal: {
240
+ environment: "development" | "staging" | "production";
241
+ applicationId: string;
242
+ credentialId: string;
243
+ billing: {
244
+ accountId: string;
245
+ };
246
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
247
+ };
248
+ userId?: string | undefined;
249
+ generationId?: string | undefined;
250
+ }>;
251
+ status: z.ZodEnum<["held", "settled", "released", "expired"]>;
252
+ reservedAmount: z.ZodBranded<z.ZodString, "ExactDecimal">;
253
+ currency: z.ZodString;
254
+ ceilingPriceVersionId: z.ZodString;
255
+ createdAt: z.ZodString;
256
+ expiresAt: z.ZodString;
257
+ /** The receipt that consumed this hold. Present exactly when `settled`. */
258
+ settledReceiptId: z.ZodOptional<z.ZodString>;
259
+ }, "strip", z.ZodTypeAny, {
260
+ status: "expired" | "held" | "settled" | "released";
261
+ expiresAt: string;
262
+ createdAt: string;
263
+ schemaVersion: 1;
264
+ currency: string;
265
+ reservationId: string;
266
+ reservedAmount: string & z.BRAND<"ExactDecimal">;
267
+ attribution: {
268
+ requestId: string;
269
+ principal: {
270
+ environment: "development" | "staging" | "production";
271
+ applicationId: string;
272
+ credentialId: string;
273
+ billing: {
274
+ accountId: string & z.BRAND<"OxyAccountId">;
275
+ };
276
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
277
+ };
278
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
279
+ generationId?: string | undefined;
280
+ };
281
+ idempotencyKey: string;
282
+ ceilingPriceVersionId: string;
283
+ settledReceiptId?: string | undefined;
284
+ }, {
285
+ status: "expired" | "held" | "settled" | "released";
286
+ expiresAt: string;
287
+ createdAt: string;
288
+ schemaVersion: 1;
289
+ currency: string;
290
+ reservationId: string;
291
+ reservedAmount: string;
292
+ attribution: {
293
+ requestId: string;
294
+ principal: {
295
+ environment: "development" | "staging" | "production";
296
+ applicationId: string;
297
+ credentialId: string;
298
+ billing: {
299
+ accountId: string;
300
+ };
301
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
302
+ };
303
+ userId?: string | undefined;
304
+ generationId?: string | undefined;
305
+ };
306
+ idempotencyKey: string;
307
+ ceilingPriceVersionId: string;
308
+ settledReceiptId?: string | undefined;
309
+ }>, {
310
+ status: "expired" | "held" | "settled" | "released";
311
+ expiresAt: string;
312
+ createdAt: string;
313
+ schemaVersion: 1;
314
+ currency: string;
315
+ reservationId: string;
316
+ reservedAmount: string & z.BRAND<"ExactDecimal">;
317
+ attribution: {
318
+ requestId: string;
319
+ principal: {
320
+ environment: "development" | "staging" | "production";
321
+ applicationId: string;
322
+ credentialId: string;
323
+ billing: {
324
+ accountId: string & z.BRAND<"OxyAccountId">;
325
+ };
326
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
327
+ };
328
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
329
+ generationId?: string | undefined;
330
+ };
331
+ idempotencyKey: string;
332
+ ceilingPriceVersionId: string;
333
+ settledReceiptId?: string | undefined;
334
+ }, {
335
+ status: "expired" | "held" | "settled" | "released";
336
+ expiresAt: string;
337
+ createdAt: string;
338
+ schemaVersion: 1;
339
+ currency: string;
340
+ reservationId: string;
341
+ reservedAmount: string;
342
+ attribution: {
343
+ requestId: string;
344
+ principal: {
345
+ environment: "development" | "staging" | "production";
346
+ applicationId: string;
347
+ credentialId: string;
348
+ billing: {
349
+ accountId: string;
350
+ };
351
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
352
+ };
353
+ userId?: string | undefined;
354
+ generationId?: string | undefined;
355
+ };
356
+ idempotencyKey: string;
357
+ ceilingPriceVersionId: string;
358
+ settledReceiptId?: string | undefined;
359
+ }>;
360
+ /** How a request ended, from the data plane's point of view. */
361
+ export declare const inferenceRequestOutcomeSchema: z.ZodEnum<["completed", "partial", "cancelled", "failed"]>;
362
+ /**
363
+ * The data plane's technical account of one request, and the ONLY shape a
364
+ * settlement is written from.
365
+ *
366
+ * `inferenceStreamUsageEventSchema` is not a narrower version of this one that
367
+ * could be widened into it — see that event's own comment. Its units are exact
368
+ * and settleable; the record around them is not inferable, so an edge settling
369
+ * from a stream event supplies the outcome itself and never promotes the event.
370
+ *
371
+ * No money and no price: the data plane measures units and names the route it
372
+ * used, and the control plane decides what that costs. Keeping the two apart is
373
+ * what allows a price to be corrected after the fact without re-running or
374
+ * re-measuring anything.
375
+ *
376
+ * `usageSource` is load-bearing when a provider returns no usage at all: the
377
+ * report still arrives, marked `estimated`, so settlement can apply the
378
+ * estimation policy knowingly instead of treating a reconstruction as fact.
379
+ *
380
+ * `units` is a PARTITION of what the request consumed, not a set of totals with
381
+ * details hanging off them — see `USAGE_UNITS` in `money.ts`. Reporting a provider's
382
+ * nested `prompt_tokens`/`completion_tokens` verbatim charges the cached and
383
+ * reasoning tokens twice, so subtracting the children out is part of what
384
+ * "normalized" means in this shape's name.
385
+ *
386
+ * **A `completed` report carries at least one unit, and the other outcomes need
387
+ * not.** `completed` is the one outcome that asserts the customer received the
388
+ * whole answer, so "delivered in full, consumed nothing measurable" is a
389
+ * contradiction — and it is one that BILLS NOTHING: settlement prices every
390
+ * reported unit and sums, so an empty list is a free request produced by a
391
+ * provider that simply omitted its usage block. The refinement makes that shape
392
+ * unparseable, and the policy behind it is refuse-and-release: the report is
393
+ * rejected and the hold is released, never estimated and charged.
394
+ *
395
+ * The three other outcomes legitimately carry none, which is why the rule is
396
+ * conditional rather than a `.min(1)` on the field. In the reference data plane
397
+ * `failed` is DERIVED from having no units — `outcomeFor` in
398
+ * Kaana's `internal/kaana/executor.go` returns `partial` when units exist and `failed`
399
+ * when they do not — and `cancelled` is reported for a client that stopped
400
+ * before anything was measured. An unconditional minimum would refuse those
401
+ * reports, and a refused report is a request that ran, cost money upstream and
402
+ * can never be settled or refunded.
403
+ */
404
+ export declare const normalizedUsageReportSchema: z.ZodEffects<z.ZodObject<{
405
+ /** See `version.ts`: emitted by the data plane as a whole message. */
406
+ schemaVersion: z.ZodLiteral<2>;
407
+ requestId: z.ZodString;
408
+ generationId: z.ZodOptional<z.ZodString>;
409
+ attribution: z.ZodObject<{
410
+ principal: z.ZodObject<{
411
+ billing: z.ZodObject<{
412
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
413
+ }, "strict", z.ZodTypeAny, {
414
+ accountId: string & z.BRAND<"OxyAccountId">;
415
+ }, {
416
+ accountId: string;
417
+ }>;
418
+ applicationId: z.ZodString;
419
+ credentialId: z.ZodString;
420
+ environment: z.ZodEnum<["development", "staging", "production"]>;
421
+ inferenceScopes: z.ZodArray<z.ZodEnum<["inference:invoke", "inference:models:read", "inference:usage:read", "inference:routing:read", "inference:routing:write", "inference:providers:read", "inference:providers:write"]>, "many">;
422
+ }, "strip", z.ZodTypeAny, {
423
+ environment: "development" | "staging" | "production";
424
+ applicationId: string;
425
+ credentialId: string;
426
+ billing: {
427
+ accountId: string & z.BRAND<"OxyAccountId">;
428
+ };
429
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
430
+ }, {
431
+ environment: "development" | "staging" | "production";
432
+ applicationId: string;
433
+ credentialId: string;
434
+ billing: {
435
+ accountId: string;
436
+ };
437
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
438
+ }>;
439
+ userId: z.ZodOptional<z.ZodBranded<z.ZodString, "DelegatedUserId">>;
440
+ requestId: z.ZodString;
441
+ generationId: z.ZodOptional<z.ZodString>;
442
+ }, "strip", z.ZodTypeAny, {
443
+ requestId: string;
444
+ principal: {
445
+ environment: "development" | "staging" | "production";
446
+ applicationId: string;
447
+ credentialId: string;
448
+ billing: {
449
+ accountId: string & z.BRAND<"OxyAccountId">;
450
+ };
451
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
452
+ };
453
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
454
+ generationId?: string | undefined;
455
+ }, {
456
+ requestId: string;
457
+ principal: {
458
+ environment: "development" | "staging" | "production";
459
+ applicationId: string;
460
+ credentialId: string;
461
+ billing: {
462
+ accountId: string;
463
+ };
464
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
465
+ };
466
+ userId?: string | undefined;
467
+ generationId?: string | undefined;
468
+ }>;
469
+ outcome: z.ZodEnum<["completed", "partial", "cancelled", "failed"]>;
470
+ units: z.ZodArray<z.ZodObject<{
471
+ unit: z.ZodEnum<["input_tokens", "cached_input_tokens", "output_tokens", "reasoning_tokens", "requests", "images", "audio_input_milliseconds", "audio_output_milliseconds", "video_milliseconds", "characters", "embeddings"]>;
472
+ quantity: z.ZodNumber;
473
+ }, "strict", z.ZodTypeAny, {
474
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
475
+ quantity: number;
476
+ }, {
477
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
478
+ quantity: number;
479
+ }>, "many">;
480
+ usageSource: z.ZodEnum<["provider_reported", "oxy_measured", "estimated"]>;
481
+ resolvedModelReference: z.ZodString;
482
+ servingProvider: z.ZodString;
483
+ /** Exact Kaana deployment that attempted the request; never inferred from names. */
484
+ deploymentId: z.ZodString;
485
+ /** How many allowed route switches occurred while serving this request. */
486
+ routeSwitches: z.ZodNumber;
487
+ startedAt: z.ZodString;
488
+ completedAt: z.ZodString;
489
+ timeToFirstTokenMs: z.ZodOptional<z.ZodNumber>;
490
+ }, "strip", z.ZodTypeAny, {
491
+ schemaVersion: 2;
492
+ requestId: string;
493
+ outcome: "failed" | "cancelled" | "completed" | "partial";
494
+ resolvedModelReference: string;
495
+ servingProvider: string;
496
+ attribution: {
497
+ requestId: string;
498
+ principal: {
499
+ environment: "development" | "staging" | "production";
500
+ applicationId: string;
501
+ credentialId: string;
502
+ billing: {
503
+ accountId: string & z.BRAND<"OxyAccountId">;
504
+ };
505
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
506
+ };
507
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
508
+ generationId?: string | undefined;
509
+ };
510
+ deploymentId: string;
511
+ completedAt: string;
512
+ startedAt: string;
513
+ units: {
514
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
515
+ quantity: number;
516
+ }[];
517
+ usageSource: "provider_reported" | "oxy_measured" | "estimated";
518
+ routeSwitches: number;
519
+ generationId?: string | undefined;
520
+ timeToFirstTokenMs?: number | undefined;
521
+ }, {
522
+ schemaVersion: 2;
523
+ requestId: string;
524
+ outcome: "failed" | "cancelled" | "completed" | "partial";
525
+ resolvedModelReference: string;
526
+ servingProvider: string;
527
+ attribution: {
528
+ requestId: string;
529
+ principal: {
530
+ environment: "development" | "staging" | "production";
531
+ applicationId: string;
532
+ credentialId: string;
533
+ billing: {
534
+ accountId: string;
535
+ };
536
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
537
+ };
538
+ userId?: string | undefined;
539
+ generationId?: string | undefined;
540
+ };
541
+ deploymentId: string;
542
+ completedAt: string;
543
+ startedAt: string;
544
+ units: {
545
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
546
+ quantity: number;
547
+ }[];
548
+ usageSource: "provider_reported" | "oxy_measured" | "estimated";
549
+ routeSwitches: number;
550
+ generationId?: string | undefined;
551
+ timeToFirstTokenMs?: number | undefined;
552
+ }>, {
553
+ schemaVersion: 2;
554
+ requestId: string;
555
+ outcome: "failed" | "cancelled" | "completed" | "partial";
556
+ resolvedModelReference: string;
557
+ servingProvider: string;
558
+ attribution: {
559
+ requestId: string;
560
+ principal: {
561
+ environment: "development" | "staging" | "production";
562
+ applicationId: string;
563
+ credentialId: string;
564
+ billing: {
565
+ accountId: string & z.BRAND<"OxyAccountId">;
566
+ };
567
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
568
+ };
569
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
570
+ generationId?: string | undefined;
571
+ };
572
+ deploymentId: string;
573
+ completedAt: string;
574
+ startedAt: string;
575
+ units: {
576
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
577
+ quantity: number;
578
+ }[];
579
+ usageSource: "provider_reported" | "oxy_measured" | "estimated";
580
+ routeSwitches: number;
581
+ generationId?: string | undefined;
582
+ timeToFirstTokenMs?: number | undefined;
583
+ }, {
584
+ schemaVersion: 2;
585
+ requestId: string;
586
+ outcome: "failed" | "cancelled" | "completed" | "partial";
587
+ resolvedModelReference: string;
588
+ servingProvider: string;
589
+ attribution: {
590
+ requestId: string;
591
+ principal: {
592
+ environment: "development" | "staging" | "production";
593
+ applicationId: string;
594
+ credentialId: string;
595
+ billing: {
596
+ accountId: string;
597
+ };
598
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
599
+ };
600
+ userId?: string | undefined;
601
+ generationId?: string | undefined;
602
+ };
603
+ deploymentId: string;
604
+ completedAt: string;
605
+ startedAt: string;
606
+ units: {
607
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
608
+ quantity: number;
609
+ }[];
610
+ usageSource: "provider_reported" | "oxy_measured" | "estimated";
611
+ routeSwitches: number;
612
+ generationId?: string | undefined;
613
+ timeToFirstTokenMs?: number | undefined;
614
+ }>;
615
+ /**
616
+ * The immutable record of what a request was actually charged.
617
+ *
618
+ * `priceSnapshot` is a COPY of the unit prices applied, not just the id of the
619
+ * price version they came from, so the arithmetic on this receipt can be
620
+ * checked years later without depending on any other record still existing.
621
+ *
622
+ * `platformFeeOnly` marks a BYOK request: the upstream provider billed the
623
+ * customer's own account directly, and `billedAmount` is Oxy's service fee
624
+ * rather than the cost of the tokens. Without the flag, the two look identical
625
+ * and a BYOK customer appears to have been charged twice for one request.
626
+ */
627
+ export declare const usageReceiptSchema: z.ZodEffects<z.ZodObject<{
628
+ /** See `version.ts`: returned to customers by `GET /v1/generations/:id`. */
629
+ schemaVersion: z.ZodLiteral<1>;
630
+ receiptId: z.ZodString;
631
+ /** The hold this settled against. Absent for a charge with no reservation. */
632
+ reservationId: z.ZodOptional<z.ZodString>;
633
+ idempotencyKey: z.ZodString;
634
+ attribution: z.ZodObject<{
635
+ principal: z.ZodObject<{
636
+ billing: z.ZodObject<{
637
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
638
+ }, "strict", z.ZodTypeAny, {
639
+ accountId: string & z.BRAND<"OxyAccountId">;
640
+ }, {
641
+ accountId: string;
642
+ }>;
643
+ applicationId: z.ZodString;
644
+ credentialId: z.ZodString;
645
+ environment: z.ZodEnum<["development", "staging", "production"]>;
646
+ inferenceScopes: z.ZodArray<z.ZodEnum<["inference:invoke", "inference:models:read", "inference:usage:read", "inference:routing:read", "inference:routing:write", "inference:providers:read", "inference:providers:write"]>, "many">;
647
+ }, "strip", z.ZodTypeAny, {
648
+ environment: "development" | "staging" | "production";
649
+ applicationId: string;
650
+ credentialId: string;
651
+ billing: {
652
+ accountId: string & z.BRAND<"OxyAccountId">;
653
+ };
654
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
655
+ }, {
656
+ environment: "development" | "staging" | "production";
657
+ applicationId: string;
658
+ credentialId: string;
659
+ billing: {
660
+ accountId: string;
661
+ };
662
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
663
+ }>;
664
+ userId: z.ZodOptional<z.ZodBranded<z.ZodString, "DelegatedUserId">>;
665
+ requestId: z.ZodString;
666
+ generationId: z.ZodOptional<z.ZodString>;
667
+ }, "strip", z.ZodTypeAny, {
668
+ requestId: string;
669
+ principal: {
670
+ environment: "development" | "staging" | "production";
671
+ applicationId: string;
672
+ credentialId: string;
673
+ billing: {
674
+ accountId: string & z.BRAND<"OxyAccountId">;
675
+ };
676
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
677
+ };
678
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
679
+ generationId?: string | undefined;
680
+ }, {
681
+ requestId: string;
682
+ principal: {
683
+ environment: "development" | "staging" | "production";
684
+ applicationId: string;
685
+ credentialId: string;
686
+ billing: {
687
+ accountId: string;
688
+ };
689
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
690
+ };
691
+ userId?: string | undefined;
692
+ generationId?: string | undefined;
693
+ }>;
694
+ outcome: z.ZodEnum<["completed", "partial", "cancelled", "failed"]>;
695
+ units: z.ZodArray<z.ZodObject<{
696
+ unit: z.ZodEnum<["input_tokens", "cached_input_tokens", "output_tokens", "reasoning_tokens", "requests", "images", "audio_input_milliseconds", "audio_output_milliseconds", "video_milliseconds", "characters", "embeddings"]>;
697
+ quantity: z.ZodNumber;
698
+ }, "strict", z.ZodTypeAny, {
699
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
700
+ quantity: number;
701
+ }, {
702
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
703
+ quantity: number;
704
+ }>, "many">;
705
+ usageSource: z.ZodEnum<["provider_reported", "oxy_measured", "estimated"]>;
706
+ priceSnapshot: z.ZodObject<{
707
+ priceVersionId: z.ZodString;
708
+ currency: z.ZodString;
709
+ unitPrices: z.ZodArray<z.ZodObject<{
710
+ unit: z.ZodEnum<["input_tokens", "cached_input_tokens", "output_tokens", "reasoning_tokens", "requests", "images", "audio_input_milliseconds", "audio_output_milliseconds", "video_milliseconds", "characters", "embeddings"]>;
711
+ amount: z.ZodBranded<z.ZodString, "ExactDecimal">;
712
+ per: z.ZodNumber;
713
+ currency: z.ZodString;
714
+ }, "strict", z.ZodTypeAny, {
715
+ currency: string;
716
+ amount: string & z.BRAND<"ExactDecimal">;
717
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
718
+ per: number;
719
+ }, {
720
+ currency: string;
721
+ amount: string;
722
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
723
+ per: number;
724
+ }>, "many">;
725
+ }, "strict", z.ZodTypeAny, {
726
+ currency: string;
727
+ priceVersionId: string;
728
+ unitPrices: {
729
+ currency: string;
730
+ amount: string & z.BRAND<"ExactDecimal">;
731
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
732
+ per: number;
733
+ }[];
734
+ }, {
735
+ currency: string;
736
+ priceVersionId: string;
737
+ unitPrices: {
738
+ currency: string;
739
+ amount: string;
740
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
741
+ per: number;
742
+ }[];
743
+ }>;
744
+ billedAmount: z.ZodBranded<z.ZodString, "ExactDecimal">;
745
+ currency: z.ZodString;
746
+ platformFeeOnly: z.ZodBoolean;
747
+ resolvedModelReference: z.ZodString;
748
+ servingProvider: z.ZodString;
749
+ settledAt: z.ZodString;
750
+ }, "strip", z.ZodTypeAny, {
751
+ schemaVersion: 1;
752
+ receiptId: string;
753
+ settledAt: string;
754
+ billedAmount: string & z.BRAND<"ExactDecimal">;
755
+ currency: string;
756
+ outcome: "failed" | "cancelled" | "completed" | "partial";
757
+ resolvedModelReference: string;
758
+ servingProvider: string;
759
+ platformFeeOnly: boolean;
760
+ attribution: {
761
+ requestId: string;
762
+ principal: {
763
+ environment: "development" | "staging" | "production";
764
+ applicationId: string;
765
+ credentialId: string;
766
+ billing: {
767
+ accountId: string & z.BRAND<"OxyAccountId">;
768
+ };
769
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
770
+ };
771
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
772
+ generationId?: string | undefined;
773
+ };
774
+ idempotencyKey: string;
775
+ units: {
776
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
777
+ quantity: number;
778
+ }[];
779
+ usageSource: "provider_reported" | "oxy_measured" | "estimated";
780
+ priceSnapshot: {
781
+ currency: string;
782
+ priceVersionId: string;
783
+ unitPrices: {
784
+ currency: string;
785
+ amount: string & z.BRAND<"ExactDecimal">;
786
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
787
+ per: number;
788
+ }[];
789
+ };
790
+ reservationId?: string | undefined;
791
+ }, {
792
+ schemaVersion: 1;
793
+ receiptId: string;
794
+ settledAt: string;
795
+ billedAmount: string;
796
+ currency: string;
797
+ outcome: "failed" | "cancelled" | "completed" | "partial";
798
+ resolvedModelReference: string;
799
+ servingProvider: string;
800
+ platformFeeOnly: boolean;
801
+ attribution: {
802
+ requestId: string;
803
+ principal: {
804
+ environment: "development" | "staging" | "production";
805
+ applicationId: string;
806
+ credentialId: string;
807
+ billing: {
808
+ accountId: string;
809
+ };
810
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
811
+ };
812
+ userId?: string | undefined;
813
+ generationId?: string | undefined;
814
+ };
815
+ idempotencyKey: string;
816
+ units: {
817
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
818
+ quantity: number;
819
+ }[];
820
+ usageSource: "provider_reported" | "oxy_measured" | "estimated";
821
+ priceSnapshot: {
822
+ currency: string;
823
+ priceVersionId: string;
824
+ unitPrices: {
825
+ currency: string;
826
+ amount: string;
827
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
828
+ per: number;
829
+ }[];
830
+ };
831
+ reservationId?: string | undefined;
832
+ }>, {
833
+ schemaVersion: 1;
834
+ receiptId: string;
835
+ settledAt: string;
836
+ billedAmount: string & z.BRAND<"ExactDecimal">;
837
+ currency: string;
838
+ outcome: "failed" | "cancelled" | "completed" | "partial";
839
+ resolvedModelReference: string;
840
+ servingProvider: string;
841
+ platformFeeOnly: boolean;
842
+ attribution: {
843
+ requestId: string;
844
+ principal: {
845
+ environment: "development" | "staging" | "production";
846
+ applicationId: string;
847
+ credentialId: string;
848
+ billing: {
849
+ accountId: string & z.BRAND<"OxyAccountId">;
850
+ };
851
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
852
+ };
853
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
854
+ generationId?: string | undefined;
855
+ };
856
+ idempotencyKey: string;
857
+ units: {
858
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
859
+ quantity: number;
860
+ }[];
861
+ usageSource: "provider_reported" | "oxy_measured" | "estimated";
862
+ priceSnapshot: {
863
+ currency: string;
864
+ priceVersionId: string;
865
+ unitPrices: {
866
+ currency: string;
867
+ amount: string & z.BRAND<"ExactDecimal">;
868
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
869
+ per: number;
870
+ }[];
871
+ };
872
+ reservationId?: string | undefined;
873
+ }, {
874
+ schemaVersion: 1;
875
+ receiptId: string;
876
+ settledAt: string;
877
+ billedAmount: string;
878
+ currency: string;
879
+ outcome: "failed" | "cancelled" | "completed" | "partial";
880
+ resolvedModelReference: string;
881
+ servingProvider: string;
882
+ platformFeeOnly: boolean;
883
+ attribution: {
884
+ requestId: string;
885
+ principal: {
886
+ environment: "development" | "staging" | "production";
887
+ applicationId: string;
888
+ credentialId: string;
889
+ billing: {
890
+ accountId: string;
891
+ };
892
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
893
+ };
894
+ userId?: string | undefined;
895
+ generationId?: string | undefined;
896
+ };
897
+ idempotencyKey: string;
898
+ units: {
899
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
900
+ quantity: number;
901
+ }[];
902
+ usageSource: "provider_reported" | "oxy_measured" | "estimated";
903
+ priceSnapshot: {
904
+ currency: string;
905
+ priceVersionId: string;
906
+ unitPrices: {
907
+ currency: string;
908
+ amount: string;
909
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
910
+ per: number;
911
+ }[];
912
+ };
913
+ reservationId?: string | undefined;
914
+ }>;
915
+ /**
916
+ * What a reversal acts on: an unused hold, or a settled charge.
917
+ *
918
+ * A discriminated union, so "release the rest of the hold" and "give back money
919
+ * already booked" can never be confused for one another — they hit different
920
+ * ledger accounts and only the second one is visible on an invoice.
921
+ */
922
+ export declare const usageRefundSubjectSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
923
+ kind: z.ZodLiteral<"reservation">;
924
+ reservationId: z.ZodString;
925
+ }, "strict", z.ZodTypeAny, {
926
+ kind: "reservation";
927
+ reservationId: string;
928
+ }, {
929
+ kind: "reservation";
930
+ reservationId: string;
931
+ }>, z.ZodObject<{
932
+ kind: z.ZodLiteral<"receipt">;
933
+ receiptId: z.ZodString;
934
+ }, "strict", z.ZodTypeAny, {
935
+ kind: "receipt";
936
+ receiptId: string;
937
+ }, {
938
+ kind: "receipt";
939
+ receiptId: string;
940
+ }>]>;
941
+ /** Why money was given back or a hold was released. */
942
+ export declare const usageRefundReasonSchema: z.ZodEnum<["unused_reservation", "client_cancelled", "upstream_failure", "partial_stream", "usage_unavailable", "billing_correction", "duplicate_charge"]>;
943
+ /**
944
+ * An immutable reversal entry.
945
+ *
946
+ * `amount` is non-negative like every other amount in this contract: the
947
+ * direction is carried by the record being a refund, not by a sign that a
948
+ * consumer could read the wrong way round. Idempotent by key, so a retried
949
+ * refund releases the same money once.
950
+ */
951
+ export declare const usageRefundSchema: z.ZodEffects<z.ZodObject<{
952
+ /** See `version.ts`: a ledger record read back on its own. */
953
+ schemaVersion: z.ZodLiteral<1>;
954
+ refundId: z.ZodString;
955
+ idempotencyKey: z.ZodString;
956
+ attribution: z.ZodObject<{
957
+ principal: z.ZodObject<{
958
+ billing: z.ZodObject<{
959
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
960
+ }, "strict", z.ZodTypeAny, {
961
+ accountId: string & z.BRAND<"OxyAccountId">;
962
+ }, {
963
+ accountId: string;
964
+ }>;
965
+ applicationId: z.ZodString;
966
+ credentialId: z.ZodString;
967
+ environment: z.ZodEnum<["development", "staging", "production"]>;
968
+ inferenceScopes: z.ZodArray<z.ZodEnum<["inference:invoke", "inference:models:read", "inference:usage:read", "inference:routing:read", "inference:routing:write", "inference:providers:read", "inference:providers:write"]>, "many">;
969
+ }, "strip", z.ZodTypeAny, {
970
+ environment: "development" | "staging" | "production";
971
+ applicationId: string;
972
+ credentialId: string;
973
+ billing: {
974
+ accountId: string & z.BRAND<"OxyAccountId">;
975
+ };
976
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
977
+ }, {
978
+ environment: "development" | "staging" | "production";
979
+ applicationId: string;
980
+ credentialId: string;
981
+ billing: {
982
+ accountId: string;
983
+ };
984
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
985
+ }>;
986
+ userId: z.ZodOptional<z.ZodBranded<z.ZodString, "DelegatedUserId">>;
987
+ requestId: z.ZodString;
988
+ generationId: z.ZodOptional<z.ZodString>;
989
+ }, "strip", z.ZodTypeAny, {
990
+ requestId: string;
991
+ principal: {
992
+ environment: "development" | "staging" | "production";
993
+ applicationId: string;
994
+ credentialId: string;
995
+ billing: {
996
+ accountId: string & z.BRAND<"OxyAccountId">;
997
+ };
998
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
999
+ };
1000
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
1001
+ generationId?: string | undefined;
1002
+ }, {
1003
+ requestId: string;
1004
+ principal: {
1005
+ environment: "development" | "staging" | "production";
1006
+ applicationId: string;
1007
+ credentialId: string;
1008
+ billing: {
1009
+ accountId: string;
1010
+ };
1011
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
1012
+ };
1013
+ userId?: string | undefined;
1014
+ generationId?: string | undefined;
1015
+ }>;
1016
+ subject: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
1017
+ kind: z.ZodLiteral<"reservation">;
1018
+ reservationId: z.ZodString;
1019
+ }, "strict", z.ZodTypeAny, {
1020
+ kind: "reservation";
1021
+ reservationId: string;
1022
+ }, {
1023
+ kind: "reservation";
1024
+ reservationId: string;
1025
+ }>, z.ZodObject<{
1026
+ kind: z.ZodLiteral<"receipt">;
1027
+ receiptId: z.ZodString;
1028
+ }, "strict", z.ZodTypeAny, {
1029
+ kind: "receipt";
1030
+ receiptId: string;
1031
+ }, {
1032
+ kind: "receipt";
1033
+ receiptId: string;
1034
+ }>]>;
1035
+ reason: z.ZodEnum<["unused_reservation", "client_cancelled", "upstream_failure", "partial_stream", "usage_unavailable", "billing_correction", "duplicate_charge"]>;
1036
+ amount: z.ZodBranded<z.ZodString, "ExactDecimal">;
1037
+ currency: z.ZodString;
1038
+ createdAt: z.ZodString;
1039
+ }, "strip", z.ZodTypeAny, {
1040
+ createdAt: string;
1041
+ reason: "unused_reservation" | "client_cancelled" | "upstream_failure" | "partial_stream" | "usage_unavailable" | "billing_correction" | "duplicate_charge";
1042
+ schemaVersion: 1;
1043
+ subject: {
1044
+ kind: "reservation";
1045
+ reservationId: string;
1046
+ } | {
1047
+ kind: "receipt";
1048
+ receiptId: string;
1049
+ };
1050
+ currency: string;
1051
+ attribution: {
1052
+ requestId: string;
1053
+ principal: {
1054
+ environment: "development" | "staging" | "production";
1055
+ applicationId: string;
1056
+ credentialId: string;
1057
+ billing: {
1058
+ accountId: string & z.BRAND<"OxyAccountId">;
1059
+ };
1060
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
1061
+ };
1062
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
1063
+ generationId?: string | undefined;
1064
+ };
1065
+ idempotencyKey: string;
1066
+ amount: string & z.BRAND<"ExactDecimal">;
1067
+ refundId: string;
1068
+ }, {
1069
+ createdAt: string;
1070
+ reason: "unused_reservation" | "client_cancelled" | "upstream_failure" | "partial_stream" | "usage_unavailable" | "billing_correction" | "duplicate_charge";
1071
+ schemaVersion: 1;
1072
+ subject: {
1073
+ kind: "reservation";
1074
+ reservationId: string;
1075
+ } | {
1076
+ kind: "receipt";
1077
+ receiptId: string;
1078
+ };
1079
+ currency: string;
1080
+ attribution: {
1081
+ requestId: string;
1082
+ principal: {
1083
+ environment: "development" | "staging" | "production";
1084
+ applicationId: string;
1085
+ credentialId: string;
1086
+ billing: {
1087
+ accountId: string;
1088
+ };
1089
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
1090
+ };
1091
+ userId?: string | undefined;
1092
+ generationId?: string | undefined;
1093
+ };
1094
+ idempotencyKey: string;
1095
+ amount: string;
1096
+ refundId: string;
1097
+ }>, {
1098
+ createdAt: string;
1099
+ reason: "unused_reservation" | "client_cancelled" | "upstream_failure" | "partial_stream" | "usage_unavailable" | "billing_correction" | "duplicate_charge";
1100
+ schemaVersion: 1;
1101
+ subject: {
1102
+ kind: "reservation";
1103
+ reservationId: string;
1104
+ } | {
1105
+ kind: "receipt";
1106
+ receiptId: string;
1107
+ };
1108
+ currency: string;
1109
+ attribution: {
1110
+ requestId: string;
1111
+ principal: {
1112
+ environment: "development" | "staging" | "production";
1113
+ applicationId: string;
1114
+ credentialId: string;
1115
+ billing: {
1116
+ accountId: string & z.BRAND<"OxyAccountId">;
1117
+ };
1118
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
1119
+ };
1120
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
1121
+ generationId?: string | undefined;
1122
+ };
1123
+ idempotencyKey: string;
1124
+ amount: string & z.BRAND<"ExactDecimal">;
1125
+ refundId: string;
1126
+ }, {
1127
+ createdAt: string;
1128
+ reason: "unused_reservation" | "client_cancelled" | "upstream_failure" | "partial_stream" | "usage_unavailable" | "billing_correction" | "duplicate_charge";
1129
+ schemaVersion: 1;
1130
+ subject: {
1131
+ kind: "reservation";
1132
+ reservationId: string;
1133
+ } | {
1134
+ kind: "receipt";
1135
+ receiptId: string;
1136
+ };
1137
+ currency: string;
1138
+ attribution: {
1139
+ requestId: string;
1140
+ principal: {
1141
+ environment: "development" | "staging" | "production";
1142
+ applicationId: string;
1143
+ credentialId: string;
1144
+ billing: {
1145
+ accountId: string;
1146
+ };
1147
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
1148
+ };
1149
+ userId?: string | undefined;
1150
+ generationId?: string | undefined;
1151
+ };
1152
+ idempotencyKey: string;
1153
+ amount: string;
1154
+ refundId: string;
1155
+ }>;
1156
+ export type UsageReservationRequest = z.infer<typeof usageReservationRequestSchema>;
1157
+ export type UsageReservationStatus = z.infer<typeof usageReservationStatusSchema>;
1158
+ export type UsageReservation = z.infer<typeof usageReservationSchema>;
1159
+ export type InferenceRequestOutcome = z.infer<typeof inferenceRequestOutcomeSchema>;
1160
+ export type NormalizedUsageReport = z.infer<typeof normalizedUsageReportSchema>;
1161
+ export type UsageReceipt = z.infer<typeof usageReceiptSchema>;
1162
+ export type UsageRefundSubject = z.infer<typeof usageRefundSubjectSchema>;
1163
+ export type UsageRefundReason = z.infer<typeof usageRefundReasonSchema>;
1164
+ export type UsageRefund = z.infer<typeof usageRefundSchema>;