@oxyhq/contracts 0.26.0 → 0.28.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 (52) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/accountGraph.js +4 -3
  3. package/dist/cjs/index.js +186 -1
  4. package/dist/cjs/inference/accountBilling.js +334 -0
  5. package/dist/cjs/inference/attribution.js +106 -0
  6. package/dist/cjs/inference/catalogue.js +482 -0
  7. package/dist/cjs/inference/entitlement.js +217 -0
  8. package/dist/cjs/inference/errors.js +210 -0
  9. package/dist/cjs/inference/identifiers.js +197 -0
  10. package/dist/cjs/inference/money.js +188 -0
  11. package/dist/cjs/inference/priceVersion.js +110 -0
  12. package/dist/cjs/inference/providerConnection.js +142 -0
  13. package/dist/cjs/inference/request.js +288 -0
  14. package/dist/cjs/inference/routingPolicy.js +213 -0
  15. package/dist/cjs/inference/streamEvents.js +219 -0
  16. package/dist/cjs/inference/usage.js +297 -0
  17. package/dist/cjs/inference/version.js +85 -0
  18. package/dist/esm/.tsbuildinfo +1 -1
  19. package/dist/esm/accountGraph.js +4 -3
  20. package/dist/esm/index.js +54 -0
  21. package/dist/esm/inference/accountBilling.js +331 -0
  22. package/dist/esm/inference/attribution.js +103 -0
  23. package/dist/esm/inference/catalogue.js +479 -0
  24. package/dist/esm/inference/entitlement.js +214 -0
  25. package/dist/esm/inference/errors.js +207 -0
  26. package/dist/esm/inference/identifiers.js +194 -0
  27. package/dist/esm/inference/money.js +185 -0
  28. package/dist/esm/inference/priceVersion.js +107 -0
  29. package/dist/esm/inference/providerConnection.js +139 -0
  30. package/dist/esm/inference/request.js +285 -0
  31. package/dist/esm/inference/routingPolicy.js +210 -0
  32. package/dist/esm/inference/streamEvents.js +216 -0
  33. package/dist/esm/inference/usage.js +294 -0
  34. package/dist/esm/inference/version.js +82 -0
  35. package/dist/types/.tsbuildinfo +1 -1
  36. package/dist/types/accountGraph.d.ts +6 -5
  37. package/dist/types/index.d.ts +27 -0
  38. package/dist/types/inference/accountBilling.d.ts +738 -0
  39. package/dist/types/inference/attribution.d.ts +176 -0
  40. package/dist/types/inference/catalogue.d.ts +1612 -0
  41. package/dist/types/inference/entitlement.d.ts +519 -0
  42. package/dist/types/inference/errors.d.ts +206 -0
  43. package/dist/types/inference/identifiers.d.ts +157 -0
  44. package/dist/types/inference/money.d.ts +185 -0
  45. package/dist/types/inference/priceVersion.d.ts +182 -0
  46. package/dist/types/inference/providerConnection.d.ts +297 -0
  47. package/dist/types/inference/request.d.ts +2364 -0
  48. package/dist/types/inference/routingPolicy.d.ts +426 -0
  49. package/dist/types/inference/streamEvents.d.ts +906 -0
  50. package/dist/types/inference/usage.d.ts +1139 -0
  51. package/dist/types/inference/version.d.ts +82 -0
  52. package/package.json +1 -1
@@ -0,0 +1,1139 @@
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
+ credentialId: string;
62
+ applicationId: 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
+ credentialId: string;
70
+ applicationId: 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
+ credentialId: string;
84
+ applicationId: 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
+ credentialId: string;
97
+ applicationId: 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
+ attribution: {
126
+ requestId: string;
127
+ principal: {
128
+ environment: "development" | "staging" | "production";
129
+ credentialId: string;
130
+ applicationId: string;
131
+ billing: {
132
+ accountId: string & z.BRAND<"OxyAccountId">;
133
+ };
134
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
135
+ };
136
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
137
+ generationId?: string | undefined;
138
+ };
139
+ idempotencyKey: string;
140
+ currency: string;
141
+ schemaVersion: 1;
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
+ attribution: {
152
+ requestId: string;
153
+ principal: {
154
+ environment: "development" | "staging" | "production";
155
+ credentialId: string;
156
+ applicationId: string;
157
+ billing: {
158
+ accountId: string;
159
+ };
160
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
161
+ };
162
+ userId?: string | undefined;
163
+ generationId?: string | undefined;
164
+ };
165
+ idempotencyKey: string;
166
+ currency: string;
167
+ schemaVersion: 1;
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
+ credentialId: string;
207
+ applicationId: 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
+ credentialId: string;
215
+ applicationId: 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
+ credentialId: string;
229
+ applicationId: 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
+ credentialId: string;
242
+ applicationId: 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
+ attribution: {
263
+ requestId: string;
264
+ principal: {
265
+ environment: "development" | "staging" | "production";
266
+ credentialId: string;
267
+ applicationId: string;
268
+ billing: {
269
+ accountId: string & z.BRAND<"OxyAccountId">;
270
+ };
271
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
272
+ };
273
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
274
+ generationId?: string | undefined;
275
+ };
276
+ idempotencyKey: string;
277
+ createdAt: string;
278
+ currency: string;
279
+ schemaVersion: 1;
280
+ ceilingPriceVersionId: string;
281
+ reservationId: string;
282
+ reservedAmount: string & z.BRAND<"ExactDecimal">;
283
+ settledReceiptId?: string | undefined;
284
+ }, {
285
+ status: "expired" | "held" | "settled" | "released";
286
+ expiresAt: string;
287
+ attribution: {
288
+ requestId: string;
289
+ principal: {
290
+ environment: "development" | "staging" | "production";
291
+ credentialId: string;
292
+ applicationId: string;
293
+ billing: {
294
+ accountId: string;
295
+ };
296
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
297
+ };
298
+ userId?: string | undefined;
299
+ generationId?: string | undefined;
300
+ };
301
+ idempotencyKey: string;
302
+ createdAt: string;
303
+ currency: string;
304
+ schemaVersion: 1;
305
+ ceilingPriceVersionId: string;
306
+ reservationId: string;
307
+ reservedAmount: string;
308
+ settledReceiptId?: string | undefined;
309
+ }>, {
310
+ status: "expired" | "held" | "settled" | "released";
311
+ expiresAt: string;
312
+ attribution: {
313
+ requestId: string;
314
+ principal: {
315
+ environment: "development" | "staging" | "production";
316
+ credentialId: string;
317
+ applicationId: string;
318
+ billing: {
319
+ accountId: string & z.BRAND<"OxyAccountId">;
320
+ };
321
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
322
+ };
323
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
324
+ generationId?: string | undefined;
325
+ };
326
+ idempotencyKey: string;
327
+ createdAt: string;
328
+ currency: string;
329
+ schemaVersion: 1;
330
+ ceilingPriceVersionId: string;
331
+ reservationId: string;
332
+ reservedAmount: string & z.BRAND<"ExactDecimal">;
333
+ settledReceiptId?: string | undefined;
334
+ }, {
335
+ status: "expired" | "held" | "settled" | "released";
336
+ expiresAt: string;
337
+ attribution: {
338
+ requestId: string;
339
+ principal: {
340
+ environment: "development" | "staging" | "production";
341
+ credentialId: string;
342
+ applicationId: string;
343
+ billing: {
344
+ accountId: string;
345
+ };
346
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
347
+ };
348
+ userId?: string | undefined;
349
+ generationId?: string | undefined;
350
+ };
351
+ idempotencyKey: string;
352
+ createdAt: string;
353
+ currency: string;
354
+ schemaVersion: 1;
355
+ ceilingPriceVersionId: string;
356
+ reservationId: string;
357
+ reservedAmount: 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.
364
+ *
365
+ * No money and no price: the data plane measures units and names the route it
366
+ * used, and the control plane decides what that costs. Keeping the two apart is
367
+ * what allows a price to be corrected after the fact without re-running or
368
+ * re-measuring anything.
369
+ *
370
+ * `usageSource` is load-bearing when a provider returns no usage at all: the
371
+ * report still arrives, marked `estimated`, so settlement can apply the
372
+ * estimation policy knowingly instead of treating a reconstruction as fact.
373
+ *
374
+ * `units` is a PARTITION of what the request consumed, not a set of totals with
375
+ * details hanging off them — see `USAGE_UNITS` in `money.ts`. Reporting a provider's
376
+ * nested `prompt_tokens`/`completion_tokens` verbatim charges the cached and
377
+ * reasoning tokens twice, so subtracting the children out is part of what
378
+ * "normalized" means in this shape's name.
379
+ */
380
+ export declare const normalizedUsageReportSchema: z.ZodEffects<z.ZodObject<{
381
+ /** See `version.ts`: emitted by the data plane as a whole message. */
382
+ schemaVersion: z.ZodLiteral<1>;
383
+ requestId: z.ZodString;
384
+ generationId: z.ZodOptional<z.ZodString>;
385
+ attribution: z.ZodObject<{
386
+ principal: z.ZodObject<{
387
+ billing: z.ZodObject<{
388
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
389
+ }, "strict", z.ZodTypeAny, {
390
+ accountId: string & z.BRAND<"OxyAccountId">;
391
+ }, {
392
+ accountId: string;
393
+ }>;
394
+ applicationId: z.ZodString;
395
+ credentialId: z.ZodString;
396
+ environment: z.ZodEnum<["development", "staging", "production"]>;
397
+ 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">;
398
+ }, "strip", z.ZodTypeAny, {
399
+ environment: "development" | "staging" | "production";
400
+ credentialId: string;
401
+ applicationId: string;
402
+ billing: {
403
+ accountId: string & z.BRAND<"OxyAccountId">;
404
+ };
405
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
406
+ }, {
407
+ environment: "development" | "staging" | "production";
408
+ credentialId: string;
409
+ applicationId: string;
410
+ billing: {
411
+ accountId: string;
412
+ };
413
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
414
+ }>;
415
+ userId: z.ZodOptional<z.ZodBranded<z.ZodString, "DelegatedUserId">>;
416
+ requestId: z.ZodString;
417
+ generationId: z.ZodOptional<z.ZodString>;
418
+ }, "strip", z.ZodTypeAny, {
419
+ requestId: string;
420
+ principal: {
421
+ environment: "development" | "staging" | "production";
422
+ credentialId: string;
423
+ applicationId: string;
424
+ billing: {
425
+ accountId: string & z.BRAND<"OxyAccountId">;
426
+ };
427
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
428
+ };
429
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
430
+ generationId?: string | undefined;
431
+ }, {
432
+ requestId: string;
433
+ principal: {
434
+ environment: "development" | "staging" | "production";
435
+ credentialId: string;
436
+ applicationId: string;
437
+ billing: {
438
+ accountId: string;
439
+ };
440
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
441
+ };
442
+ userId?: string | undefined;
443
+ generationId?: string | undefined;
444
+ }>;
445
+ outcome: z.ZodEnum<["completed", "partial", "cancelled", "failed"]>;
446
+ units: z.ZodArray<z.ZodObject<{
447
+ unit: z.ZodEnum<["input_tokens", "cached_input_tokens", "output_tokens", "reasoning_tokens", "requests", "images", "audio_input_milliseconds", "audio_output_milliseconds", "video_milliseconds", "characters", "embeddings"]>;
448
+ quantity: z.ZodNumber;
449
+ }, "strict", z.ZodTypeAny, {
450
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
451
+ quantity: number;
452
+ }, {
453
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
454
+ quantity: number;
455
+ }>, "many">;
456
+ usageSource: z.ZodEnum<["provider_reported", "oxy_measured", "estimated"]>;
457
+ resolvedModelReference: z.ZodString;
458
+ servingProvider: z.ZodString;
459
+ deploymentId: z.ZodOptional<z.ZodString>;
460
+ /** How many allowed route switches occurred while serving this request. */
461
+ routeSwitches: z.ZodNumber;
462
+ startedAt: z.ZodString;
463
+ completedAt: z.ZodString;
464
+ timeToFirstTokenMs: z.ZodOptional<z.ZodNumber>;
465
+ }, "strip", z.ZodTypeAny, {
466
+ requestId: string;
467
+ attribution: {
468
+ requestId: string;
469
+ principal: {
470
+ environment: "development" | "staging" | "production";
471
+ credentialId: string;
472
+ applicationId: string;
473
+ billing: {
474
+ accountId: string & z.BRAND<"OxyAccountId">;
475
+ };
476
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
477
+ };
478
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
479
+ generationId?: string | undefined;
480
+ };
481
+ schemaVersion: 1;
482
+ resolvedModelReference: string;
483
+ servingProvider: string;
484
+ startedAt: string;
485
+ units: {
486
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
487
+ quantity: number;
488
+ }[];
489
+ usageSource: "provider_reported" | "oxy_measured" | "estimated";
490
+ completedAt: string;
491
+ outcome: "cancelled" | "completed" | "partial" | "failed";
492
+ routeSwitches: number;
493
+ generationId?: string | undefined;
494
+ deploymentId?: string | undefined;
495
+ timeToFirstTokenMs?: number | undefined;
496
+ }, {
497
+ requestId: string;
498
+ attribution: {
499
+ requestId: string;
500
+ principal: {
501
+ environment: "development" | "staging" | "production";
502
+ credentialId: string;
503
+ applicationId: string;
504
+ billing: {
505
+ accountId: string;
506
+ };
507
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
508
+ };
509
+ userId?: string | undefined;
510
+ generationId?: string | undefined;
511
+ };
512
+ schemaVersion: 1;
513
+ resolvedModelReference: string;
514
+ servingProvider: string;
515
+ startedAt: string;
516
+ units: {
517
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
518
+ quantity: number;
519
+ }[];
520
+ usageSource: "provider_reported" | "oxy_measured" | "estimated";
521
+ completedAt: string;
522
+ outcome: "cancelled" | "completed" | "partial" | "failed";
523
+ routeSwitches: number;
524
+ generationId?: string | undefined;
525
+ deploymentId?: string | undefined;
526
+ timeToFirstTokenMs?: number | undefined;
527
+ }>, {
528
+ requestId: string;
529
+ attribution: {
530
+ requestId: string;
531
+ principal: {
532
+ environment: "development" | "staging" | "production";
533
+ credentialId: string;
534
+ applicationId: string;
535
+ billing: {
536
+ accountId: string & z.BRAND<"OxyAccountId">;
537
+ };
538
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
539
+ };
540
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
541
+ generationId?: string | undefined;
542
+ };
543
+ schemaVersion: 1;
544
+ resolvedModelReference: string;
545
+ servingProvider: string;
546
+ startedAt: string;
547
+ units: {
548
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
549
+ quantity: number;
550
+ }[];
551
+ usageSource: "provider_reported" | "oxy_measured" | "estimated";
552
+ completedAt: string;
553
+ outcome: "cancelled" | "completed" | "partial" | "failed";
554
+ routeSwitches: number;
555
+ generationId?: string | undefined;
556
+ deploymentId?: string | undefined;
557
+ timeToFirstTokenMs?: number | undefined;
558
+ }, {
559
+ requestId: string;
560
+ attribution: {
561
+ requestId: string;
562
+ principal: {
563
+ environment: "development" | "staging" | "production";
564
+ credentialId: string;
565
+ applicationId: string;
566
+ billing: {
567
+ accountId: string;
568
+ };
569
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
570
+ };
571
+ userId?: string | undefined;
572
+ generationId?: string | undefined;
573
+ };
574
+ schemaVersion: 1;
575
+ resolvedModelReference: string;
576
+ servingProvider: string;
577
+ startedAt: string;
578
+ units: {
579
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
580
+ quantity: number;
581
+ }[];
582
+ usageSource: "provider_reported" | "oxy_measured" | "estimated";
583
+ completedAt: string;
584
+ outcome: "cancelled" | "completed" | "partial" | "failed";
585
+ routeSwitches: number;
586
+ generationId?: string | undefined;
587
+ deploymentId?: string | undefined;
588
+ timeToFirstTokenMs?: number | undefined;
589
+ }>;
590
+ /**
591
+ * The immutable record of what a request was actually charged.
592
+ *
593
+ * `priceSnapshot` is a COPY of the unit prices applied, not just the id of the
594
+ * price version they came from, so the arithmetic on this receipt can be
595
+ * checked years later without depending on any other record still existing.
596
+ *
597
+ * `platformFeeOnly` marks a BYOK request: the upstream provider billed the
598
+ * customer's own account directly, and `billedAmount` is Oxy's service fee
599
+ * rather than the cost of the tokens. Without the flag, the two look identical
600
+ * and a BYOK customer appears to have been charged twice for one request.
601
+ */
602
+ export declare const usageReceiptSchema: z.ZodEffects<z.ZodObject<{
603
+ /** See `version.ts`: returned to customers by `GET /v1/generations/:id`. */
604
+ schemaVersion: z.ZodLiteral<1>;
605
+ receiptId: z.ZodString;
606
+ /** The hold this settled against. Absent for a charge with no reservation. */
607
+ reservationId: z.ZodOptional<z.ZodString>;
608
+ idempotencyKey: z.ZodString;
609
+ attribution: z.ZodObject<{
610
+ principal: z.ZodObject<{
611
+ billing: z.ZodObject<{
612
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
613
+ }, "strict", z.ZodTypeAny, {
614
+ accountId: string & z.BRAND<"OxyAccountId">;
615
+ }, {
616
+ accountId: string;
617
+ }>;
618
+ applicationId: z.ZodString;
619
+ credentialId: z.ZodString;
620
+ environment: z.ZodEnum<["development", "staging", "production"]>;
621
+ 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">;
622
+ }, "strip", z.ZodTypeAny, {
623
+ environment: "development" | "staging" | "production";
624
+ credentialId: string;
625
+ applicationId: string;
626
+ billing: {
627
+ accountId: string & z.BRAND<"OxyAccountId">;
628
+ };
629
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
630
+ }, {
631
+ environment: "development" | "staging" | "production";
632
+ credentialId: string;
633
+ applicationId: string;
634
+ billing: {
635
+ accountId: string;
636
+ };
637
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
638
+ }>;
639
+ userId: z.ZodOptional<z.ZodBranded<z.ZodString, "DelegatedUserId">>;
640
+ requestId: z.ZodString;
641
+ generationId: z.ZodOptional<z.ZodString>;
642
+ }, "strip", z.ZodTypeAny, {
643
+ requestId: string;
644
+ principal: {
645
+ environment: "development" | "staging" | "production";
646
+ credentialId: string;
647
+ applicationId: string;
648
+ billing: {
649
+ accountId: string & z.BRAND<"OxyAccountId">;
650
+ };
651
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
652
+ };
653
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
654
+ generationId?: string | undefined;
655
+ }, {
656
+ requestId: string;
657
+ principal: {
658
+ environment: "development" | "staging" | "production";
659
+ credentialId: string;
660
+ applicationId: string;
661
+ billing: {
662
+ accountId: string;
663
+ };
664
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
665
+ };
666
+ userId?: string | undefined;
667
+ generationId?: string | undefined;
668
+ }>;
669
+ outcome: z.ZodEnum<["completed", "partial", "cancelled", "failed"]>;
670
+ units: z.ZodArray<z.ZodObject<{
671
+ unit: z.ZodEnum<["input_tokens", "cached_input_tokens", "output_tokens", "reasoning_tokens", "requests", "images", "audio_input_milliseconds", "audio_output_milliseconds", "video_milliseconds", "characters", "embeddings"]>;
672
+ quantity: z.ZodNumber;
673
+ }, "strict", z.ZodTypeAny, {
674
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
675
+ quantity: number;
676
+ }, {
677
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
678
+ quantity: number;
679
+ }>, "many">;
680
+ usageSource: z.ZodEnum<["provider_reported", "oxy_measured", "estimated"]>;
681
+ priceSnapshot: z.ZodObject<{
682
+ priceVersionId: z.ZodString;
683
+ currency: z.ZodString;
684
+ unitPrices: z.ZodArray<z.ZodObject<{
685
+ unit: z.ZodEnum<["input_tokens", "cached_input_tokens", "output_tokens", "reasoning_tokens", "requests", "images", "audio_input_milliseconds", "audio_output_milliseconds", "video_milliseconds", "characters", "embeddings"]>;
686
+ amount: z.ZodBranded<z.ZodString, "ExactDecimal">;
687
+ per: z.ZodNumber;
688
+ currency: z.ZodString;
689
+ }, "strict", z.ZodTypeAny, {
690
+ amount: string & z.BRAND<"ExactDecimal">;
691
+ currency: string;
692
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
693
+ per: number;
694
+ }, {
695
+ amount: string;
696
+ currency: string;
697
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
698
+ per: number;
699
+ }>, "many">;
700
+ }, "strict", z.ZodTypeAny, {
701
+ currency: string;
702
+ priceVersionId: string;
703
+ unitPrices: {
704
+ amount: string & z.BRAND<"ExactDecimal">;
705
+ currency: string;
706
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
707
+ per: number;
708
+ }[];
709
+ }, {
710
+ currency: string;
711
+ priceVersionId: string;
712
+ unitPrices: {
713
+ amount: string;
714
+ currency: string;
715
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
716
+ per: number;
717
+ }[];
718
+ }>;
719
+ billedAmount: z.ZodBranded<z.ZodString, "ExactDecimal">;
720
+ currency: z.ZodString;
721
+ platformFeeOnly: z.ZodBoolean;
722
+ resolvedModelReference: z.ZodString;
723
+ servingProvider: z.ZodString;
724
+ settledAt: z.ZodString;
725
+ }, "strip", z.ZodTypeAny, {
726
+ attribution: {
727
+ requestId: string;
728
+ principal: {
729
+ environment: "development" | "staging" | "production";
730
+ credentialId: string;
731
+ applicationId: string;
732
+ billing: {
733
+ accountId: string & z.BRAND<"OxyAccountId">;
734
+ };
735
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
736
+ };
737
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
738
+ generationId?: string | undefined;
739
+ };
740
+ idempotencyKey: string;
741
+ currency: string;
742
+ schemaVersion: 1;
743
+ resolvedModelReference: string;
744
+ servingProvider: string;
745
+ units: {
746
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
747
+ quantity: number;
748
+ }[];
749
+ usageSource: "provider_reported" | "oxy_measured" | "estimated";
750
+ receiptId: string;
751
+ outcome: "cancelled" | "completed" | "partial" | "failed";
752
+ priceSnapshot: {
753
+ currency: string;
754
+ priceVersionId: string;
755
+ unitPrices: {
756
+ amount: string & z.BRAND<"ExactDecimal">;
757
+ currency: string;
758
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
759
+ per: number;
760
+ }[];
761
+ };
762
+ billedAmount: string & z.BRAND<"ExactDecimal">;
763
+ platformFeeOnly: boolean;
764
+ settledAt: string;
765
+ reservationId?: string | undefined;
766
+ }, {
767
+ attribution: {
768
+ requestId: string;
769
+ principal: {
770
+ environment: "development" | "staging" | "production";
771
+ credentialId: string;
772
+ applicationId: string;
773
+ billing: {
774
+ accountId: string;
775
+ };
776
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
777
+ };
778
+ userId?: string | undefined;
779
+ generationId?: string | undefined;
780
+ };
781
+ idempotencyKey: string;
782
+ currency: string;
783
+ schemaVersion: 1;
784
+ resolvedModelReference: string;
785
+ servingProvider: string;
786
+ units: {
787
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
788
+ quantity: number;
789
+ }[];
790
+ usageSource: "provider_reported" | "oxy_measured" | "estimated";
791
+ receiptId: string;
792
+ outcome: "cancelled" | "completed" | "partial" | "failed";
793
+ priceSnapshot: {
794
+ currency: string;
795
+ priceVersionId: string;
796
+ unitPrices: {
797
+ amount: string;
798
+ currency: string;
799
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
800
+ per: number;
801
+ }[];
802
+ };
803
+ billedAmount: string;
804
+ platformFeeOnly: boolean;
805
+ settledAt: string;
806
+ reservationId?: string | undefined;
807
+ }>, {
808
+ attribution: {
809
+ requestId: string;
810
+ principal: {
811
+ environment: "development" | "staging" | "production";
812
+ credentialId: string;
813
+ applicationId: string;
814
+ billing: {
815
+ accountId: string & z.BRAND<"OxyAccountId">;
816
+ };
817
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
818
+ };
819
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
820
+ generationId?: string | undefined;
821
+ };
822
+ idempotencyKey: string;
823
+ currency: string;
824
+ schemaVersion: 1;
825
+ resolvedModelReference: string;
826
+ servingProvider: string;
827
+ units: {
828
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
829
+ quantity: number;
830
+ }[];
831
+ usageSource: "provider_reported" | "oxy_measured" | "estimated";
832
+ receiptId: string;
833
+ outcome: "cancelled" | "completed" | "partial" | "failed";
834
+ priceSnapshot: {
835
+ currency: string;
836
+ priceVersionId: string;
837
+ unitPrices: {
838
+ amount: string & z.BRAND<"ExactDecimal">;
839
+ currency: string;
840
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
841
+ per: number;
842
+ }[];
843
+ };
844
+ billedAmount: string & z.BRAND<"ExactDecimal">;
845
+ platformFeeOnly: boolean;
846
+ settledAt: string;
847
+ reservationId?: string | undefined;
848
+ }, {
849
+ attribution: {
850
+ requestId: string;
851
+ principal: {
852
+ environment: "development" | "staging" | "production";
853
+ credentialId: string;
854
+ applicationId: string;
855
+ billing: {
856
+ accountId: string;
857
+ };
858
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
859
+ };
860
+ userId?: string | undefined;
861
+ generationId?: string | undefined;
862
+ };
863
+ idempotencyKey: string;
864
+ currency: string;
865
+ schemaVersion: 1;
866
+ resolvedModelReference: string;
867
+ servingProvider: string;
868
+ units: {
869
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
870
+ quantity: number;
871
+ }[];
872
+ usageSource: "provider_reported" | "oxy_measured" | "estimated";
873
+ receiptId: string;
874
+ outcome: "cancelled" | "completed" | "partial" | "failed";
875
+ priceSnapshot: {
876
+ currency: string;
877
+ priceVersionId: string;
878
+ unitPrices: {
879
+ amount: string;
880
+ currency: string;
881
+ unit: "input_tokens" | "cached_input_tokens" | "output_tokens" | "reasoning_tokens" | "requests" | "images" | "audio_input_milliseconds" | "audio_output_milliseconds" | "video_milliseconds" | "characters" | "embeddings";
882
+ per: number;
883
+ }[];
884
+ };
885
+ billedAmount: string;
886
+ platformFeeOnly: boolean;
887
+ settledAt: string;
888
+ reservationId?: string | undefined;
889
+ }>;
890
+ /**
891
+ * What a reversal acts on: an unused hold, or a settled charge.
892
+ *
893
+ * A discriminated union, so "release the rest of the hold" and "give back money
894
+ * already booked" can never be confused for one another — they hit different
895
+ * ledger accounts and only the second one is visible on an invoice.
896
+ */
897
+ export declare const usageRefundSubjectSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
898
+ kind: z.ZodLiteral<"reservation">;
899
+ reservationId: z.ZodString;
900
+ }, "strict", z.ZodTypeAny, {
901
+ kind: "reservation";
902
+ reservationId: string;
903
+ }, {
904
+ kind: "reservation";
905
+ reservationId: string;
906
+ }>, z.ZodObject<{
907
+ kind: z.ZodLiteral<"receipt">;
908
+ receiptId: z.ZodString;
909
+ }, "strict", z.ZodTypeAny, {
910
+ kind: "receipt";
911
+ receiptId: string;
912
+ }, {
913
+ kind: "receipt";
914
+ receiptId: string;
915
+ }>]>;
916
+ /** Why money was given back or a hold was released. */
917
+ export declare const usageRefundReasonSchema: z.ZodEnum<["unused_reservation", "client_cancelled", "upstream_failure", "partial_stream", "usage_unavailable", "billing_correction", "duplicate_charge"]>;
918
+ /**
919
+ * An immutable reversal entry.
920
+ *
921
+ * `amount` is non-negative like every other amount in this contract: the
922
+ * direction is carried by the record being a refund, not by a sign that a
923
+ * consumer could read the wrong way round. Idempotent by key, so a retried
924
+ * refund releases the same money once.
925
+ */
926
+ export declare const usageRefundSchema: z.ZodEffects<z.ZodObject<{
927
+ /** See `version.ts`: a ledger record read back on its own. */
928
+ schemaVersion: z.ZodLiteral<1>;
929
+ refundId: z.ZodString;
930
+ idempotencyKey: z.ZodString;
931
+ attribution: z.ZodObject<{
932
+ principal: z.ZodObject<{
933
+ billing: z.ZodObject<{
934
+ accountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
935
+ }, "strict", z.ZodTypeAny, {
936
+ accountId: string & z.BRAND<"OxyAccountId">;
937
+ }, {
938
+ accountId: string;
939
+ }>;
940
+ applicationId: z.ZodString;
941
+ credentialId: z.ZodString;
942
+ environment: z.ZodEnum<["development", "staging", "production"]>;
943
+ 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">;
944
+ }, "strip", z.ZodTypeAny, {
945
+ environment: "development" | "staging" | "production";
946
+ credentialId: string;
947
+ applicationId: string;
948
+ billing: {
949
+ accountId: string & z.BRAND<"OxyAccountId">;
950
+ };
951
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
952
+ }, {
953
+ environment: "development" | "staging" | "production";
954
+ credentialId: string;
955
+ applicationId: string;
956
+ billing: {
957
+ accountId: string;
958
+ };
959
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
960
+ }>;
961
+ userId: z.ZodOptional<z.ZodBranded<z.ZodString, "DelegatedUserId">>;
962
+ requestId: z.ZodString;
963
+ generationId: z.ZodOptional<z.ZodString>;
964
+ }, "strip", z.ZodTypeAny, {
965
+ requestId: string;
966
+ principal: {
967
+ environment: "development" | "staging" | "production";
968
+ credentialId: string;
969
+ applicationId: string;
970
+ billing: {
971
+ accountId: string & z.BRAND<"OxyAccountId">;
972
+ };
973
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
974
+ };
975
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
976
+ generationId?: string | undefined;
977
+ }, {
978
+ requestId: string;
979
+ principal: {
980
+ environment: "development" | "staging" | "production";
981
+ credentialId: string;
982
+ applicationId: string;
983
+ billing: {
984
+ accountId: string;
985
+ };
986
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
987
+ };
988
+ userId?: string | undefined;
989
+ generationId?: string | undefined;
990
+ }>;
991
+ subject: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
992
+ kind: z.ZodLiteral<"reservation">;
993
+ reservationId: z.ZodString;
994
+ }, "strict", z.ZodTypeAny, {
995
+ kind: "reservation";
996
+ reservationId: string;
997
+ }, {
998
+ kind: "reservation";
999
+ reservationId: string;
1000
+ }>, z.ZodObject<{
1001
+ kind: z.ZodLiteral<"receipt">;
1002
+ receiptId: z.ZodString;
1003
+ }, "strict", z.ZodTypeAny, {
1004
+ kind: "receipt";
1005
+ receiptId: string;
1006
+ }, {
1007
+ kind: "receipt";
1008
+ receiptId: string;
1009
+ }>]>;
1010
+ reason: z.ZodEnum<["unused_reservation", "client_cancelled", "upstream_failure", "partial_stream", "usage_unavailable", "billing_correction", "duplicate_charge"]>;
1011
+ amount: z.ZodBranded<z.ZodString, "ExactDecimal">;
1012
+ currency: z.ZodString;
1013
+ createdAt: z.ZodString;
1014
+ }, "strip", z.ZodTypeAny, {
1015
+ reason: "unused_reservation" | "client_cancelled" | "upstream_failure" | "partial_stream" | "usage_unavailable" | "billing_correction" | "duplicate_charge";
1016
+ subject: {
1017
+ kind: "reservation";
1018
+ reservationId: string;
1019
+ } | {
1020
+ kind: "receipt";
1021
+ receiptId: string;
1022
+ };
1023
+ attribution: {
1024
+ requestId: string;
1025
+ principal: {
1026
+ environment: "development" | "staging" | "production";
1027
+ credentialId: string;
1028
+ applicationId: string;
1029
+ billing: {
1030
+ accountId: string & z.BRAND<"OxyAccountId">;
1031
+ };
1032
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
1033
+ };
1034
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
1035
+ generationId?: string | undefined;
1036
+ };
1037
+ idempotencyKey: string;
1038
+ createdAt: string;
1039
+ amount: string & z.BRAND<"ExactDecimal">;
1040
+ currency: string;
1041
+ schemaVersion: 1;
1042
+ refundId: string;
1043
+ }, {
1044
+ reason: "unused_reservation" | "client_cancelled" | "upstream_failure" | "partial_stream" | "usage_unavailable" | "billing_correction" | "duplicate_charge";
1045
+ subject: {
1046
+ kind: "reservation";
1047
+ reservationId: string;
1048
+ } | {
1049
+ kind: "receipt";
1050
+ receiptId: string;
1051
+ };
1052
+ attribution: {
1053
+ requestId: string;
1054
+ principal: {
1055
+ environment: "development" | "staging" | "production";
1056
+ credentialId: string;
1057
+ applicationId: string;
1058
+ billing: {
1059
+ accountId: string;
1060
+ };
1061
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
1062
+ };
1063
+ userId?: string | undefined;
1064
+ generationId?: string | undefined;
1065
+ };
1066
+ idempotencyKey: string;
1067
+ createdAt: string;
1068
+ amount: string;
1069
+ currency: string;
1070
+ schemaVersion: 1;
1071
+ refundId: string;
1072
+ }>, {
1073
+ reason: "unused_reservation" | "client_cancelled" | "upstream_failure" | "partial_stream" | "usage_unavailable" | "billing_correction" | "duplicate_charge";
1074
+ subject: {
1075
+ kind: "reservation";
1076
+ reservationId: string;
1077
+ } | {
1078
+ kind: "receipt";
1079
+ receiptId: string;
1080
+ };
1081
+ attribution: {
1082
+ requestId: string;
1083
+ principal: {
1084
+ environment: "development" | "staging" | "production";
1085
+ credentialId: string;
1086
+ applicationId: string;
1087
+ billing: {
1088
+ accountId: string & z.BRAND<"OxyAccountId">;
1089
+ };
1090
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
1091
+ };
1092
+ userId?: (string & z.BRAND<"DelegatedUserId">) | undefined;
1093
+ generationId?: string | undefined;
1094
+ };
1095
+ idempotencyKey: string;
1096
+ createdAt: string;
1097
+ amount: string & z.BRAND<"ExactDecimal">;
1098
+ currency: string;
1099
+ schemaVersion: 1;
1100
+ refundId: string;
1101
+ }, {
1102
+ reason: "unused_reservation" | "client_cancelled" | "upstream_failure" | "partial_stream" | "usage_unavailable" | "billing_correction" | "duplicate_charge";
1103
+ subject: {
1104
+ kind: "reservation";
1105
+ reservationId: string;
1106
+ } | {
1107
+ kind: "receipt";
1108
+ receiptId: string;
1109
+ };
1110
+ attribution: {
1111
+ requestId: string;
1112
+ principal: {
1113
+ environment: "development" | "staging" | "production";
1114
+ credentialId: string;
1115
+ applicationId: string;
1116
+ billing: {
1117
+ accountId: string;
1118
+ };
1119
+ inferenceScopes: ("inference:invoke" | "inference:models:read" | "inference:usage:read" | "inference:routing:read" | "inference:routing:write" | "inference:providers:read" | "inference:providers:write")[];
1120
+ };
1121
+ userId?: string | undefined;
1122
+ generationId?: string | undefined;
1123
+ };
1124
+ idempotencyKey: string;
1125
+ createdAt: string;
1126
+ amount: string;
1127
+ currency: string;
1128
+ schemaVersion: 1;
1129
+ refundId: string;
1130
+ }>;
1131
+ export type UsageReservationRequest = z.infer<typeof usageReservationRequestSchema>;
1132
+ export type UsageReservationStatus = z.infer<typeof usageReservationStatusSchema>;
1133
+ export type UsageReservation = z.infer<typeof usageReservationSchema>;
1134
+ export type InferenceRequestOutcome = z.infer<typeof inferenceRequestOutcomeSchema>;
1135
+ export type NormalizedUsageReport = z.infer<typeof normalizedUsageReportSchema>;
1136
+ export type UsageReceipt = z.infer<typeof usageReceiptSchema>;
1137
+ export type UsageRefundSubject = z.infer<typeof usageRefundSubjectSchema>;
1138
+ export type UsageRefundReason = z.infer<typeof usageRefundReasonSchema>;
1139
+ export type UsageRefund = z.infer<typeof usageRefundSchema>;