@openmeter/sdk 1.0.0-beta.8 → 1.0.0-beta.80

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 (59) hide show
  1. package/README.md +76 -1
  2. package/dist/cjs/clients/client.cjs +117 -0
  3. package/dist/cjs/clients/client.d.cts +40 -0
  4. package/dist/cjs/clients/client.js.map +1 -0
  5. package/dist/cjs/clients/event.cjs +71 -0
  6. package/dist/cjs/clients/event.d.cts +79 -0
  7. package/dist/cjs/clients/event.js.map +1 -0
  8. package/dist/cjs/clients/meter.cjs +69 -0
  9. package/dist/cjs/clients/meter.d.cts +75 -0
  10. package/dist/cjs/clients/meter.js.map +1 -0
  11. package/dist/cjs/clients/portal.cjs +41 -0
  12. package/dist/cjs/clients/portal.d.cts +22 -0
  13. package/dist/cjs/clients/portal.js.map +1 -0
  14. package/dist/cjs/clients/subject.cjs +60 -0
  15. package/dist/cjs/clients/subject.d.cts +27 -0
  16. package/dist/cjs/clients/subject.js.map +1 -0
  17. package/dist/cjs/index.cjs +24 -0
  18. package/dist/cjs/index.d.cts +15 -0
  19. package/dist/cjs/index.js.map +1 -0
  20. package/dist/cjs/schemas/openapi.cjs +7 -0
  21. package/dist/cjs/schemas/openapi.d.cts +1790 -0
  22. package/dist/cjs/schemas/openapi.js.map +1 -0
  23. package/dist/cjs/test/agent.cjs +266 -0
  24. package/dist/cjs/test/agent.d.cts +2 -0
  25. package/dist/cjs/test/agent.js.map +1 -0
  26. package/dist/cjs/test/mocks.cjs +44 -0
  27. package/dist/cjs/test/mocks.d.cts +14 -0
  28. package/dist/cjs/test/mocks.js.map +1 -0
  29. package/dist/cjs/tsconfig.0fbdac75.tsbuildinfo +1 -0
  30. package/dist/cjs/tsconfig.9f533246.tsbuildinfo +1 -0
  31. package/dist/clients/client.d.ts +1 -1
  32. package/dist/clients/client.js +9 -1
  33. package/dist/clients/client.js.map +1 -0
  34. package/dist/clients/event.d.ts +16 -2
  35. package/dist/clients/event.js +43 -18
  36. package/dist/clients/event.js.map +1 -0
  37. package/dist/clients/meter.d.ts +12 -32
  38. package/dist/clients/meter.js +1 -15
  39. package/dist/clients/meter.js.map +1 -0
  40. package/dist/clients/portal.d.ts +22 -0
  41. package/dist/clients/portal.js +37 -0
  42. package/dist/clients/portal.js.map +1 -0
  43. package/dist/clients/subject.d.ts +27 -0
  44. package/dist/clients/subject.js +56 -0
  45. package/dist/clients/subject.js.map +1 -0
  46. package/dist/index.d.ts +6 -2
  47. package/dist/index.js +8 -1
  48. package/dist/index.js.map +1 -0
  49. package/dist/schemas/openapi.d.ts +1453 -178
  50. package/dist/schemas/openapi.js +1 -0
  51. package/dist/schemas/openapi.js.map +1 -0
  52. package/dist/test/agent.js +120 -28
  53. package/dist/test/agent.js.map +1 -0
  54. package/dist/test/mocks.d.ts +4 -1
  55. package/dist/test/mocks.js +20 -0
  56. package/dist/test/mocks.js.map +1 -0
  57. package/dist/tsconfig.tsbuildinfo +1 -1
  58. package/package.json +45 -31
  59. package/index.ts +0 -22
@@ -4,53 +4,225 @@
4
4
  */
5
5
  export interface paths {
6
6
  '/api/v1/events': {
7
- /** @description Ingest events */
7
+ /**
8
+ * List ingested events
9
+ * @description List ingested events within a time range.
10
+ */
11
+ get: operations['listEvents'];
12
+ /**
13
+ * Ingest events
14
+ * @description Ingests an event or batch of events following the CloudEvents specification.
15
+ */
8
16
  post: operations['ingestEvents'];
9
17
  };
10
18
  '/api/v1/meters': {
11
- /** @description List meters */
19
+ /**
20
+ * List meters
21
+ * @description List meters.
22
+ */
12
23
  get: operations['listMeters'];
13
- /** @description Create meter */
24
+ /**
25
+ * ☁ Create meter
26
+ * @description *Available in OpenMeter Cloud.*
27
+ * *In the open-source version, meters are created in the configuration file.*
28
+ *
29
+ * Create a meter.
30
+ */
14
31
  post: operations['createMeter'];
15
32
  };
16
33
  '/api/v1/meters/{meterIdOrSlug}': {
17
- /** @description Get meter by slugs */
34
+ /**
35
+ * Get meter
36
+ * @description Get meter by ID or slug
37
+ */
18
38
  get: operations['getMeter'];
19
- /** @description Delete meter by slug */
20
- delete: operations['deleteMeter'];
21
- };
22
- '/api/v1/meters/{meterIdOrSlug}/values': {
23
39
  /**
24
- * @deprecated
25
- * @description Get meter values
26
- * Deprecated: use /api/v1/meters/{meter}/query instead.
40
+ * ☁ Delete meter
41
+ * @description *Available in OpenMeter Cloud.*
42
+ *
43
+ * Delete a meter by ID or slug.
27
44
  */
28
- get: operations['getMeterValues'];
45
+ delete: operations['deleteMeter'];
29
46
  };
30
47
  '/api/v1/meters/{meterIdOrSlug}/query': {
31
- /** @description Query meter */
48
+ /**
49
+ * Query meter
50
+ * @description Query meter for usage.
51
+ */
32
52
  get: operations['queryMeter'];
33
53
  };
34
54
  '/api/v1/meters/{meterIdOrSlug}/subjects': {
35
- /** @description List meter subjects */
55
+ /**
56
+ * List meter subjects
57
+ * @description List subjects for a meter.
58
+ */
36
59
  get: operations['listMeterSubjects'];
37
60
  };
38
- '/api/v1/namespaces': {
39
- /** @description Create namespace */
40
- post: operations['createNamespace'];
61
+ '/api/v1/portal/tokens': {
62
+ /**
63
+ * ☁ List portal tokens
64
+ * @description *Available in OpenMeter Cloud.*
65
+ *
66
+ * List consumer portal tokens.
67
+ */
68
+ get: operations['listPortalTokens'];
69
+ /**
70
+ * Create portal token
71
+ * @description Create a consumer portal token.
72
+ */
73
+ post: operations['createPortalToken'];
74
+ };
75
+ '/api/v1/portal/tokens/invalidate': {
76
+ /**
77
+ * ☁ Invalidate portal tokens
78
+ * @description *Available in OpenMeter Cloud.*
79
+ *
80
+ * Invalidates consumer portal tokens by ID or subject.
81
+ */
82
+ post: operations['invalidatePortalTokens'];
83
+ };
84
+ '/api/v1/subjects': {
85
+ /**
86
+ * ☁ List subjects
87
+ * @description *Available in OpenMeter Cloud.*
88
+ *
89
+ * List subjects.
90
+ */
91
+ get: operations['listSubjects'];
92
+ /**
93
+ * ☁ Upsert subject
94
+ * @description *Available in OpenMeter Cloud.*
95
+ *
96
+ * Upserts a subject. Creates or updates subject.
97
+ * If the subject doesn't exist, it will be created.
98
+ * If the subject exists, it will be partially updated with the provided fields.
99
+ */
100
+ post: operations['upsertSubject'];
101
+ };
102
+ '/api/v1/subjects/{subjectIdOrKey}': {
103
+ /**
104
+ * ☁ Get subject
105
+ * @description *Available in OpenMeter Cloud.*
106
+ *
107
+ * Get subject by ID or key.
108
+ */
109
+ get: operations['getSubject'];
110
+ /**
111
+ * ☁ Delete subject
112
+ * @description *Available in OpenMeter Cloud.*
113
+ *
114
+ * Delete a subject by ID or key.
115
+ */
116
+ delete: operations['deleteSubject'];
117
+ };
118
+ '/api/v1/portal/meters/{meterSlug}/query': {
119
+ /**
120
+ * Query portal meter
121
+ * @description Query meter for consumer portal. This endpoint is publicly exposable to consumers.
122
+ */
123
+ get: operations['queryPortalMeter'];
124
+ };
125
+ '/api/v1/features': {
126
+ /**
127
+ * List features
128
+ * @description List features.
129
+ */
130
+ get: operations['listFeatures'];
131
+ /**
132
+ * Create feature
133
+ * @description Creates a feature.
134
+ */
135
+ post: operations['createFeature'];
136
+ };
137
+ '/api/v1/features/{featureID}': {
138
+ /**
139
+ * Get feature
140
+ * @description Get feature by key.
141
+ */
142
+ get: operations['getFeature'];
143
+ /**
144
+ * Delete feature
145
+ * @description Delete a feature by key.
146
+ */
147
+ delete: operations['deleteFeature'];
148
+ };
149
+ '/api/v1/ledgers': {
150
+ /**
151
+ * List the already defined ledgers.
152
+ * @description List the already defined ledgers.
153
+ */
154
+ get: operations['listLedgers'];
155
+ /**
156
+ * Creates the specified ledger
157
+ * @description Create or update the specified ledger.
158
+ */
159
+ post: operations['createLedger'];
160
+ };
161
+ '/api/v1/ledgers/{ledgerID}/balance': {
162
+ /**
163
+ * Get the balance of a specific subject.
164
+ * @description Get the balance of a specific subject.
165
+ */
166
+ get: operations['getLedgerBalance'];
167
+ };
168
+ '/api/v1/ledgers/{ledgerID}/history': {
169
+ /**
170
+ * Get the history of a ledger
171
+ * @description Get the history of a specific ledger
172
+ */
173
+ get: operations['getLedgerHistory'];
174
+ };
175
+ '/api/v1/ledgers/{ledgerID}/reset': {
176
+ /**
177
+ * Reset the ledger's balance
178
+ * @description Resets the ledger's balances to zero for a specific subject and re-apply active grants with rollover configuration.
179
+ */
180
+ post: operations['resetLedger'];
181
+ };
182
+ '/api/v1/ledgers/grants': {
183
+ /**
184
+ * List grants for multiple ledgers.
185
+ * @description List grants for multiple ledgers.
186
+ */
187
+ get: operations['listLedgerGrants'];
188
+ };
189
+ '/api/v1/ledgers/{ledgerID}/grants': {
190
+ /**
191
+ * List ledger grants
192
+ * @description List ledger grants for a specific ledger.
193
+ */
194
+ get: operations['listLedgerGrantsByLedger'];
195
+ /**
196
+ * Create a grant on a specific ledger.
197
+ * @description Create a grant on a specific ledger.
198
+ */
199
+ post: operations['createLedgerGrant'];
200
+ };
201
+ '/api/v1/ledgers/{ledgerID}/grants/{ledgerGrantID}': {
202
+ /**
203
+ * Get a single grant.
204
+ * @description Gets the grant for a ledger by ID.
205
+ */
206
+ get: operations['getLedgerGrant'];
207
+ /**
208
+ * Void ledger grant
209
+ * @description Void a ledger grant by ID. Partially or fully used grants cannot be voided.
210
+ * Voided grant won't be applied to the subject's balance anymore.
211
+ */
212
+ delete: operations['voidLedgerGrant'];
41
213
  };
42
214
  }
43
215
  export type webhooks = Record<string, never>;
44
216
  export interface components {
45
217
  schemas: {
46
218
  /**
47
- * @description A Problem Details object (RFC 7807)
219
+ * @description A Problem Details object (RFC 7807).
220
+ * Additional properties specific to the problem type may be present.
48
221
  * @example {
49
222
  * "type": "urn:problem-type:bad-request",
50
223
  * "title": "Bad Request",
51
224
  * "status": 400,
52
- * "detail": "header Content-Type has unexpected value \"application/xml\"",
53
- * "instance": "urn:request:local/JMOlctsKV8-000001"
225
+ * "detail": "body must be a JSON object"
54
226
  * }
55
227
  */
56
228
  Problem: {
@@ -73,7 +245,7 @@ export interface components {
73
245
  status: number;
74
246
  /**
75
247
  * @description A human-readable explanation specific to this occurrence of the problem.
76
- * @example header Content-Type has unexpected value \"application/xml\"
248
+ * @example body must be a JSON object
77
249
  */
78
250
  detail: string;
79
251
  /**
@@ -84,7 +256,22 @@ export interface components {
84
256
  instance?: string;
85
257
  [key: string]: unknown;
86
258
  };
87
- /** @description CloudEvents Specification JSON Schema */
259
+ /**
260
+ * @description CloudEvents Specification JSON Schema
261
+ * @example {
262
+ * "id": "5c10fade-1c9e-4d6c-8275-c52c36731d3c",
263
+ * "source": "service-name",
264
+ * "specversion": "1.0",
265
+ * "type": "prompt",
266
+ * "subject": "customer-id",
267
+ * "time": "2023-01-01T01:01:01.001Z",
268
+ * "data": {
269
+ * "tokens": "1234",
270
+ * "model": "gpt-4-turbo",
271
+ * "type": "input"
272
+ * }
273
+ * }
274
+ */
88
275
  Event: {
89
276
  /**
90
277
  * @description Identifies the event.
@@ -94,7 +281,7 @@ export interface components {
94
281
  /**
95
282
  * Format: uri-reference
96
283
  * @description Identifies the context in which an event happened.
97
- * @example services/service-0
284
+ * @example service-name
98
285
  */
99
286
  source: string;
100
287
  /**
@@ -104,7 +291,7 @@ export interface components {
104
291
  specversion: string;
105
292
  /**
106
293
  * @description Describes the type of event related to the originating occurrence.
107
- * @example api_request
294
+ * @example prompt
108
295
  */
109
296
  type: string;
110
297
  /**
@@ -120,7 +307,7 @@ export interface components {
120
307
  dataschema?: string | null;
121
308
  /**
122
309
  * @description Describes the subject of the event in the context of the event producer (identified by source).
123
- * @example customer_id
310
+ * @example customer-id
124
311
  */
125
312
  subject: string;
126
313
  /**
@@ -132,14 +319,387 @@ export interface components {
132
319
  /**
133
320
  * @description The event payload.
134
321
  * @example {
135
- * "duration_ms": "12",
136
- * "path": "/hello"
322
+ * "tokens": "1234",
323
+ * "model": "gpt-4-turbo"
137
324
  * }
138
325
  */
139
326
  data?: {
140
327
  [key: string]: unknown;
141
328
  };
142
329
  };
330
+ /**
331
+ * @description An ingested event with optional validation error.
332
+ * @example {
333
+ * "event": {
334
+ * "id": "5c10fade-1c9e-4d6c-8275-c52c36731d3d",
335
+ * "source": "service-name",
336
+ * "specversion": "1.0",
337
+ * "type": "prompt",
338
+ * "subject": "customer-id",
339
+ * "time": "2023-01-01T01:01:01.001Z",
340
+ * "data": {
341
+ * "tokens": "1234",
342
+ * "model": "gpt-4-turbo"
343
+ * }
344
+ * },
345
+ * "validationError": "meter not found for event"
346
+ * }
347
+ */
348
+ IngestedEvent: {
349
+ event: components['schemas']['Event'];
350
+ /** @example invalid event */
351
+ validationError?: string;
352
+ };
353
+ /**
354
+ * @description A feature is a feature or service offered to a customer.
355
+ * For example: CPU-Hours, Tokens, API Calls, etc.
356
+ */
357
+ Feature: {
358
+ /**
359
+ * @description Readonly unique ULID identifier of the feature.
360
+ *
361
+ * @example 01ARZ3NDEKTSV4RRFFQ69G5FAV
362
+ */
363
+ id?: string;
364
+ /**
365
+ * @description The name of the feature.
366
+ *
367
+ * @example AI Tokens
368
+ */
369
+ name: string;
370
+ /**
371
+ * @description The meter that the feature is associated with and decreases grants by usage.
372
+ *
373
+ * @example tokens_total
374
+ */
375
+ meterSlug: string;
376
+ /**
377
+ * @description Optional meter group by filters. Useful if the meter scope is broader than what feature tracks.
378
+ *
379
+ * @example {
380
+ * "model": "gpt-4"
381
+ * }
382
+ */
383
+ meterGroupByFilters?: {
384
+ [key: string]: string;
385
+ };
386
+ /**
387
+ * @description If the feature is archived, it will not be used for grants or usage.
388
+ *
389
+ * @example false
390
+ */
391
+ archived?: boolean;
392
+ /**
393
+ * Format: date-time
394
+ * @description The time the feature was created.
395
+ *
396
+ * @example 2023-01-01T00:00:00Z
397
+ */
398
+ createdAt?: string;
399
+ /**
400
+ * Format: date-time
401
+ * @description The time the feature was last updated.
402
+ *
403
+ * @example 2023-01-01T00:00:00Z
404
+ */
405
+ updatedAt?: string;
406
+ };
407
+ /**
408
+ * @description A ledger represented in open meter. A ledger must be assigned to a single
409
+ * subject.
410
+ */
411
+ CreateLedger: {
412
+ /** @description The metering subject this ledger used to track grants for. */
413
+ subject: string;
414
+ /**
415
+ * @example {
416
+ * "stripePaymentId": "pi_4OrAkhLvyihio9p51h9iiFnB"
417
+ * }
418
+ */
419
+ metadata?: {
420
+ [key: string]: string;
421
+ };
422
+ };
423
+ /**
424
+ * @description Ledger Exists
425
+ * @example {
426
+ * "type": "about:blank",
427
+ * "title": "Conflict",
428
+ * "status": 409,
429
+ * "detail": "ledger (default.01HXVNDJR532E8GTBVSC2XK5D4) already exitst for subject subject-1",
430
+ * "instance": "urn:request:local/JMOlctsKV8-000001",
431
+ * "conflictingEntity": {
432
+ * "id": "01HXVNDJR532E8GTBVSC2XK5D4",
433
+ * "subject": "subject-1"
434
+ * }
435
+ * }
436
+ */
437
+ LedgerAlreadyExistsProblem: {
438
+ /**
439
+ * Format: uri
440
+ * @description Type contains a URI that identifies the problem type.
441
+ * @example urn:problem-type:bad-request
442
+ */
443
+ type: string;
444
+ /**
445
+ * @description A a short, human-readable summary of the problem type.
446
+ * @example Bad Request
447
+ */
448
+ title: string;
449
+ /**
450
+ * Format: int32
451
+ * @description The HTTP status code generated by the origin server for this occurrence of the problem.
452
+ * @example 400
453
+ */
454
+ status: number;
455
+ /**
456
+ * @description A human-readable explanation specific to this occurrence of the problem.
457
+ * @example body must be a JSON object
458
+ */
459
+ detail: string;
460
+ /**
461
+ * Format: uri
462
+ * @description A URI reference that identifies the specific occurrence of the problem.
463
+ * @example urn:request:local/JMOlctsKV8-000001
464
+ */
465
+ instance?: string;
466
+ conflictingEntity?: components['schemas']['Ledger'];
467
+ [key: string]: unknown;
468
+ };
469
+ /** @description A ledger represented in our system. */
470
+ Ledger: components['schemas']['CreateLedger'] & {
471
+ /**
472
+ * @description Readonly unique ULID identifier of the ledger.
473
+ *
474
+ * @example 01ARZ3NDEKTSV4RRFFQ69G5FAV
475
+ */
476
+ id: string;
477
+ /**
478
+ * Format: date-time
479
+ * @description The time the ledger was created.
480
+ *
481
+ * @example 2023-01-01T00:00:00Z
482
+ */
483
+ createdAt?: string;
484
+ };
485
+ /** @description A ledger entry. */
486
+ LedgerEntry: {
487
+ /**
488
+ * @description Readonly unique ULID identifier of the ledger entry.
489
+ *
490
+ * @example 01ARZ3NDEKTSV4RRFFQ69G5FAV
491
+ */
492
+ id: string;
493
+ type: components['schemas']['LedgerEntryType'];
494
+ /**
495
+ * Format: date-time
496
+ * @description The time the ledger entry was created.
497
+ *
498
+ * @example 2023-01-01T00:00:00Z
499
+ */
500
+ time: string;
501
+ /**
502
+ * @description The amount to apply. Can be positive or negative number. If applicable.
503
+ *
504
+ * @example 100
505
+ */
506
+ amount?: number;
507
+ period?: components['schemas']['Period'];
508
+ };
509
+ /** @description A time period */
510
+ Period: {
511
+ /**
512
+ * Format: date-time
513
+ * @description Period start time where the amount was applied. If applicable.
514
+ *
515
+ * @example 2023-01-01T00:00:00Z
516
+ */
517
+ from: string;
518
+ /**
519
+ * Format: date-time
520
+ * @description Period end time where the amount was applied. If applicable.
521
+ *
522
+ * @example 2023-01-01T00:00:00Z
523
+ */
524
+ to: string;
525
+ };
526
+ /**
527
+ * @example GRANT
528
+ * @enum {string}
529
+ */
530
+ LedgerEntryType: 'GRANT' | 'VOID' | 'RESET' | 'GRANT_USAGE';
531
+ /** @description Balance of a subject. */
532
+ LedgerBalance: {
533
+ /** @description Features with balances. */
534
+ features?: components['schemas']['FeatureBalance'][];
535
+ /** @description The grants applied to the subject. */
536
+ grants: components['schemas']['LedgerGrantBalance'][];
537
+ };
538
+ /** @description Ledger reset configuration. */
539
+ LedgerReset: {
540
+ /**
541
+ * @description Readonly unique ULID identifier of the reset.
542
+ *
543
+ * @example 01ARZ3NDEKTSV4RRFFQ69G5FAV
544
+ */
545
+ id: string;
546
+ /**
547
+ * Format: date-time
548
+ * @description The time to reset the ledger. It cannot be in the future.
549
+ *
550
+ * @example 2023-01-01T00:00:00Z
551
+ */
552
+ effectiveAt: string;
553
+ };
554
+ LedgerGrantBalance: components['schemas']['LedgerGrantResponse'] & {
555
+ /**
556
+ * @description The balance of the grant.
557
+ *
558
+ * @example 100
559
+ */
560
+ balance?: number;
561
+ };
562
+ FeatureBalance: components['schemas']['Feature'] & {
563
+ /**
564
+ * @description The balance of the feature.
565
+ *
566
+ * @example 100
567
+ */
568
+ balance?: number;
569
+ };
570
+ /** @description Grants are used to increase balance of specific subjects. */
571
+ CreateLedgerGrantRequest: {
572
+ type: components['schemas']['LedgerGrantType'];
573
+ /**
574
+ * @description The amount to grant. Can be positive or negative number.
575
+ *
576
+ * @example 100
577
+ */
578
+ amount: number;
579
+ /**
580
+ * @description The unique feature ULID that the grant is associated with, if any.
581
+ *
582
+ * @example 01ARZ3NDEKTSV4RRFFQ69G5FAV
583
+ */
584
+ featureID: string;
585
+ /**
586
+ * @description The priority of the grant. Grants with higher priority are applied first.
587
+ * Priority is a positive decimal numbers. With lower numbers indicating higher importance.
588
+ * For example, a priority of 1 is more urgent than a priority of 2.
589
+ * When there are several grants available for the same subject, the system selects the grant with the highest priority.
590
+ * In cases where grants share the same priority level, the grant closest to its expiration will be used first.
591
+ * In the case of two grants have identical priorities and expiration dates, the system will use the grant that was created first.
592
+ *
593
+ * @default 1
594
+ * @example 1
595
+ */
596
+ priority?: number;
597
+ /**
598
+ * Format: date-time
599
+ * @description The effective date.
600
+ *
601
+ * @example 2023-01-01T00:00:00Z
602
+ */
603
+ effectiveAt: string;
604
+ expiration: components['schemas']['LedgerGrantExpirationPeriod'];
605
+ rollover?: components['schemas']['LedgerGrantRollover'];
606
+ /**
607
+ * @example {
608
+ * "stripePaymentId": "pi_4OrAkhLvyihio9p51h9iiFnB"
609
+ * }
610
+ */
611
+ metadata?: {
612
+ [key: string]: string;
613
+ };
614
+ /**
615
+ * Format: date-time
616
+ * @description The time the grant was created.
617
+ *
618
+ * @example 2023-01-01T00:00:00Z
619
+ */
620
+ createdAt?: string;
621
+ /**
622
+ * Format: date-time
623
+ * @description The time the grant was last updated.
624
+ *
625
+ * @example 2023-01-01T00:00:00Z
626
+ */
627
+ updatedAt?: string;
628
+ };
629
+ LedgerGrantResponse: components['schemas']['CreateLedgerGrantRequest'] & {
630
+ /**
631
+ * @description Readonly unique ULID identifier of the grant.
632
+ *
633
+ * @example 01ARZ3NDEKTSV4RRFFQ69G5FAV
634
+ */
635
+ id: string;
636
+ /**
637
+ * @description The subject to grant the amount to.
638
+ *
639
+ * @example customer-id
640
+ */
641
+ subject: string;
642
+ /**
643
+ * Format: date-time
644
+ * @description The expiration date of the grant.
645
+ *
646
+ * @example 2023-01-01T00:00:00Z
647
+ */
648
+ expiresAt?: string;
649
+ };
650
+ /**
651
+ * @description The grant type:
652
+ * - `USAGE` - Increase balance by the amount in the unit of the associated meter.
653
+ *
654
+ * @example USAGE
655
+ * @enum {string}
656
+ */
657
+ LedgerGrantType: 'USAGE';
658
+ /** @description Grant rollover configuration. */
659
+ LedgerGrantRollover: {
660
+ type: components['schemas']['LedgerGrantRolloverType'];
661
+ /** @description Maximum amount to rollover. */
662
+ maxAmount?: number;
663
+ };
664
+ /**
665
+ * @description The rollover type to use:
666
+ * - `REMAINING_AMOUNT` - Rollover remaining amount.
667
+ * - `ORIGINAL_AMOUNT` - Rollover re-applies the full grant amount.
668
+ *
669
+ * @example ORIGINAL_AMOUNT
670
+ * @enum {string}
671
+ */
672
+ LedgerGrantRolloverType: 'REMAINING_AMOUNT' | 'ORIGINAL_AMOUNT';
673
+ /** @description Expiration period of a ledger grant. */
674
+ LedgerGrantExpirationPeriod: {
675
+ /**
676
+ * @description The expiration period duration like month.
677
+ *
678
+ * @enum {string}
679
+ */
680
+ duration: 'HOUR' | 'DAY' | 'WEEK' | 'MONTH' | 'YEAR';
681
+ /**
682
+ * @description The expiration period count like 12 months.
683
+ *
684
+ * @example 12
685
+ */
686
+ count: number;
687
+ };
688
+ /**
689
+ * @description A meter is a configuration that defines how to match and aggregate events.
690
+ * @example {
691
+ * "slug": "tokens_total",
692
+ * "description": "AI token usage",
693
+ * "aggregation": "SUM",
694
+ * "windowSize": "MINUTE",
695
+ * "eventType": "prompt",
696
+ * "valueProperty": "$.tokens",
697
+ * "groupBy": {
698
+ * "model": "$.model",
699
+ * "type": "$.type"
700
+ * }
701
+ * }
702
+ */
143
703
  Meter: {
144
704
  /**
145
705
  * @description A unique identifier for the meter.
@@ -147,77 +707,232 @@ export interface components {
147
707
  */
148
708
  id?: string;
149
709
  /**
150
- * @description A unique identifier for the meter.
151
- * @example my-meter
710
+ * @description A unique, human-readable identifier for the meter. Must consist only alphanumeric and underscore characters.
711
+ * @example tokens_total
152
712
  */
153
713
  slug: string;
154
714
  /**
155
715
  * @description A description of the meter.
156
- * @example My Meter Description
716
+ * @example AI Token Usage
157
717
  */
158
718
  description?: string | null;
159
719
  aggregation: components['schemas']['MeterAggregation'];
720
+ windowSize: components['schemas']['WindowSize'];
160
721
  /**
161
722
  * @description The event type to aggregate.
162
- * @example api_request
723
+ * @example prompt
163
724
  */
164
725
  eventType: string;
165
726
  /**
166
- * @description JSONPath expression to extract the value from the event data.
167
- * @example $.duration_ms
727
+ * @description JSONPath expression to extract the value from the ingested event's data property.
728
+ * The ingested value for SUM, AVG, MIN, and MAX aggregations is a number or a string that can be parsed to a number.
729
+ * For UNIQUE_COUNT aggregation, the ingested value must be a string. For COUNT aggregation the valueProperty is ignored.
730
+ *
731
+ * @example $.tokens
168
732
  */
169
733
  valueProperty?: string;
170
734
  /**
171
- * @description Named JSONPath expressions to extract the group by values from the event data.
735
+ * @description Named JSONPath expressions to extract the group by values from the event data. Keys must be unique and consist only alphanumeric and underscore characters.
172
736
  * @example {
173
- * "duration_ms": "$.duration_ms",
174
- * "path": "$.path"
737
+ * "model": "$.model",
738
+ * "type": "$.type"
175
739
  * }
176
740
  */
177
741
  groupBy?: {
178
742
  [key: string]: string;
179
743
  };
180
- windowSize: components['schemas']['WindowSize'];
181
744
  };
182
745
  /**
183
746
  * @description The aggregation type to use for the meter.
747
+ * @example SUM
748
+ * @enum {string}
749
+ */
750
+ MeterAggregation: 'SUM' | 'COUNT' | 'UNIQUE_COUNT' | 'AVG' | 'MIN' | 'MAX';
751
+ /**
752
+ * @description Aggregation window size.
753
+ * @example MINUTE
184
754
  * @enum {string}
185
755
  */
186
- MeterAggregation: 'SUM' | 'COUNT' | 'AVG' | 'MIN' | 'MAX';
187
- /** @enum {string} */
188
756
  WindowSize: 'MINUTE' | 'HOUR' | 'DAY';
189
- MeterValue: {
190
- /** @description The subject of the meter value. */
191
- subject?: string;
192
- /** Format: date-time */
193
- windowStart: string;
194
- /** Format: date-time */
195
- windowEnd: string;
196
- value: number;
197
- groupBy?: {
198
- [key: string]: string;
199
- } | null;
200
- };
201
- MeterQueryRow: {
202
- value: number;
203
- /** Format: date-time */
204
- windowStart: string;
205
- /** Format: date-time */
206
- windowEnd: string;
207
- /** @description The subject of the meter value. */
208
- subject?: string | null;
757
+ /**
758
+ * @description The result of a meter query.
759
+ * @example {
760
+ * "from": "2023-01-01T00:00:00Z",
761
+ * "to": "2023-01-02T00:00:00Z",
762
+ * "windowSize": "MINUTE",
763
+ * "data": [
764
+ * {
765
+ * "value": 12,
766
+ * "windowStart": "2023-01-01T00:00:00Z",
767
+ * "windowEnd": "2023-01-02T00:00:00Z",
768
+ * "subject": "customer-id",
769
+ * "groupBy": {
770
+ * "model": "gpt-4-turbo",
771
+ * "type": "prompt"
772
+ * }
773
+ * }
774
+ * ]
775
+ * }
776
+ */
777
+ MeterQueryResult: {
778
+ /**
779
+ * Format: date-time
780
+ * @example 2023-01-01T00:00:00Z
781
+ */
782
+ from?: string;
783
+ /**
784
+ * Format: date-time
785
+ * @example 2023-01-02T00:00:00Z
786
+ */
787
+ to?: string;
788
+ windowSize?: components['schemas']['WindowSize'];
789
+ /**
790
+ * @example [
791
+ * {
792
+ * "value": 12,
793
+ * "windowStart": "2023-01-01T00:00:00Z",
794
+ * "windowEnd": "2023-01-02T00:00:00Z",
795
+ * "subject": "customer-id",
796
+ * "groupBy": {
797
+ * "model": "gpt-4-turbo",
798
+ * "type": "prompt"
799
+ * }
800
+ * }
801
+ * ]
802
+ */
803
+ data: components['schemas']['MeterQueryRow'][];
804
+ };
805
+ /**
806
+ * @description A row in the result of a meter query.
807
+ * @example {
808
+ * "value": 12,
809
+ * "windowStart": "2023-01-01T00:00:00Z",
810
+ * "windowEnd": "2023-01-02T00:00:00Z",
811
+ * "subject": "customer-id",
812
+ * "groupBy": {
813
+ * "model": "gpt-4-turbo",
814
+ * "type": "prompt"
815
+ * }
816
+ * }
817
+ */
818
+ MeterQueryRow: {
819
+ /** @example 12 */
820
+ value: number;
821
+ /**
822
+ * Format: date-time
823
+ * @example 2023-01-01T00:00:00Z
824
+ */
825
+ windowStart: string;
826
+ /**
827
+ * Format: date-time
828
+ * @example 2023-01-02T00:00:00Z
829
+ */
830
+ windowEnd: string;
831
+ /**
832
+ * @description The subject of the meter value.
833
+ * @example customer-id
834
+ */
835
+ subject?: string | null;
836
+ /**
837
+ * @example {
838
+ * "model": "gpt-4-turbo",
839
+ * "type": "prompt"
840
+ * }
841
+ */
209
842
  groupBy?: {
210
843
  [key: string]: string;
211
844
  } | null;
212
845
  };
213
- IdOrSlug: string;
214
- Namespace: {
846
+ /**
847
+ * @description A consumer portal token.
848
+ * @example {
849
+ * "id": "01G65Z755AFWAKHE12NY0CQ9FH",
850
+ * "subject": "customer-id",
851
+ * "expiresAt": "2023-01-02T00:00:00Z",
852
+ * "expired": false,
853
+ * "createdAt": "2023-01-01T00:00:00Z",
854
+ * "token": "om_portal_IAnD3PpWW2A2Wr8m9jfzeHlGX8xmCXwG.y5q4S-AWqFu6qjfaFz0zQq4Ez28RsnyVwJffX5qxMvo",
855
+ * "allowedMeterSlugs": [
856
+ * "tokens_total"
857
+ * ]
858
+ * }
859
+ */
860
+ PortalToken: {
861
+ /** @example 01G65Z755AFWAKHE12NY0CQ9FH */
862
+ id?: string;
863
+ /** @example customer-id */
864
+ subject: string;
865
+ /**
866
+ * Format: date-time
867
+ * @example 2023-01-02T00:00:00Z
868
+ */
869
+ expiresAt?: string;
870
+ expired?: boolean;
871
+ /**
872
+ * Format: date-time
873
+ * @example 2023-01-01T00:00:00Z
874
+ */
875
+ createdAt?: string;
876
+ /**
877
+ * @description The token is only returned at creation.
878
+ * @example om_portal_IAnD3PpWW2A2Wr8m9jfzeHlGX8xmCXwG.y5q4S-AWqFu6qjfaFz0zQq4Ez28RsnyVwJffX5qxMvo
879
+ */
880
+ token?: string;
881
+ /**
882
+ * @description Optional, if defined only the specified meters will be allowed
883
+ * @example [
884
+ * "tokens_total"
885
+ * ]
886
+ */
887
+ allowedMeterSlugs?: string[];
888
+ };
889
+ /**
890
+ * @description A subject is a unique identifier for a user or entity.
891
+ * @example {
892
+ * "id": "01G65Z755AFWAKHE12NY0CQ9FH",
893
+ * "key": "customer-id",
894
+ * "displayName": "Customer Name",
895
+ * "metadata": {
896
+ * "hubspotId": "123456"
897
+ * },
898
+ * "currentPeriodStart": "2023-01-01T00:00:00Z",
899
+ * "currentPeriodEnd": "2023-02-01T00:00:00Z",
900
+ * "stripeCustomerId": "cus_JMOlctsKV8"
901
+ * }
902
+ */
903
+ Subject: {
904
+ /** @example 01G65Z755AFWAKHE12NY0CQ9FH */
905
+ id?: string;
906
+ /** @example customer-id */
907
+ key: string;
908
+ /** @example Customer Name */
909
+ displayName?: string | null;
910
+ /**
911
+ * @example {
912
+ * "hubspotId": "123456"
913
+ * }
914
+ */
915
+ metadata?: {
916
+ [key: string]: unknown;
917
+ } | null;
215
918
  /**
216
- * @description A namespace
217
- * @example my-namesapce
919
+ * Format: date-time
920
+ * @example 2023-01-01T00:00:00Z
218
921
  */
219
- namespace: string;
922
+ currentPeriodStart?: string | null;
923
+ /**
924
+ * Format: date-time
925
+ * @example 2023-02-01T00:00:00Z
926
+ */
927
+ currentPeriodEnd?: string | null;
928
+ /** @example cus_JMOlctsKV8 */
929
+ stripeCustomerId?: string | null;
220
930
  };
931
+ /**
932
+ * @description A unique identifier.
933
+ * @example tokens_total
934
+ */
935
+ IdOrSlug: string;
221
936
  };
222
937
  responses: {
223
938
  /** @description Bad Request */
@@ -226,12 +941,18 @@ export interface components {
226
941
  'application/problem+json': components['schemas']['Problem'];
227
942
  };
228
943
  };
229
- /** @description Method not allowed, feature not supported */
230
- MethodNotAllowedProblemResponse: {
944
+ /** @description Unauthorized */
945
+ UnauthorizedProblemResponse: {
231
946
  content: {
232
947
  'application/problem+json': components['schemas']['Problem'];
233
948
  };
234
949
  };
950
+ /** @description Ledger Exists */
951
+ LedgerAlreadyExistsProblemResponse: {
952
+ content: {
953
+ 'application/problem+json': components['schemas']['LedgerAlreadyExistsProblem'];
954
+ };
955
+ };
235
956
  /** @description Not Found */
236
957
  NotFoundProblemResponse: {
237
958
  content: {
@@ -254,8 +975,57 @@ export interface components {
254
975
  parameters: {
255
976
  /** @description A unique identifier for the meter. */
256
977
  meterIdOrSlug: components['schemas']['IdOrSlug'];
257
- /** @description Optional namespace */
258
- namespaceParam?: string;
978
+ /** @description A unique identifier for a subject. */
979
+ subjectIdOrKey: string;
980
+ /** @description A unique ULID identifier for a feature. */
981
+ featureID: string;
982
+ /** @description A unique identifier for a ledger grant. */
983
+ ledgerGrantID: string;
984
+ /** @description A unique identifier for a ledger. */
985
+ ledgerID: string;
986
+ /** @description Number of entries to return */
987
+ ledgerQueryLimit?: number;
988
+ /** @description Number of entries to skip */
989
+ ledgerQueryOffset?: number;
990
+ /**
991
+ * @description Start date-time in RFC 3339 format.
992
+ * Inclusive.
993
+ */
994
+ queryFrom?: string;
995
+ /**
996
+ * @description End date-time in RFC 3339 format.
997
+ * Inclusive.
998
+ */
999
+ queryTo?: string;
1000
+ /** @description If not specified, a single usage aggregate will be returned for the entirety of the specified period for each subject and group. */
1001
+ queryWindowSize?: components['schemas']['WindowSize'];
1002
+ /**
1003
+ * @description The value is the name of the time zone as defined in the IANA Time Zone Database (http://www.iana.org/time-zones).
1004
+ * If not specified, the UTC timezone will be used.
1005
+ */
1006
+ queryWindowTimeZone?: string;
1007
+ /**
1008
+ * @description Filtering and group by multiple subjects.
1009
+ *
1010
+ * Usage: `?ledgerID=01HX6VK5C498B3ABY9PR1069PP`
1011
+ *
1012
+ * @example 01HX6VK5C498B3ABY9PR1069PP
1013
+ */
1014
+ queryFilterLedgerID?: string;
1015
+ /**
1016
+ * @description Filtering by multiple subjects.
1017
+ *
1018
+ * Usage: ?subject=customer-1&subject=customer-2
1019
+ */
1020
+ queryFilterSubject?: string[];
1021
+ queryFilterGroupBy?: {
1022
+ [key: string]: string;
1023
+ };
1024
+ /**
1025
+ * @description If not specified a single aggregate will be returned for each subject and time window.
1026
+ * `subject` is a reserved group by value.
1027
+ */
1028
+ queryGroupBy?: string[];
259
1029
  };
260
1030
  requestBodies: never;
261
1031
  headers: never;
@@ -264,13 +1034,41 @@ export interface components {
264
1034
  export type $defs = Record<string, never>;
265
1035
  export type external = Record<string, never>;
266
1036
  export interface operations {
267
- /** @description Ingest events */
268
- ingestEvents: {
1037
+ /**
1038
+ * List ingested events
1039
+ * @description List ingested events within a time range.
1040
+ */
1041
+ listEvents: {
269
1042
  parameters: {
270
- header?: {
271
- 'OM-Namespace'?: components['parameters']['namespaceParam'];
1043
+ query?: {
1044
+ from?: components['parameters']['queryFrom'];
1045
+ to?: components['parameters']['queryTo'];
1046
+ /** @description Number of events to return */
1047
+ limit?: number;
272
1048
  };
273
1049
  };
1050
+ responses: {
1051
+ /** @description List of events for debugging. */
1052
+ 200: {
1053
+ content: {
1054
+ 'application/json': components['schemas']['IngestedEvent'][];
1055
+ };
1056
+ };
1057
+ 400: components['responses']['BadRequestProblemResponse'];
1058
+ 401: components['responses']['UnauthorizedProblemResponse'];
1059
+ default: components['responses']['UnexpectedProblemResponse'];
1060
+ };
1061
+ };
1062
+ /**
1063
+ * Ingest events
1064
+ * @description Ingests an event or batch of events following the CloudEvents specification.
1065
+ */
1066
+ ingestEvents: {
1067
+ /**
1068
+ * @description The event or batch of events to ingest.
1069
+ * The request body must be a CloudEvents JSON object or an array of CloudEvents JSON objects.
1070
+ * The CloudEvents JSON object must adhere to the CloudEvents Specification JSON Schema.
1071
+ */
274
1072
  requestBody: {
275
1073
  content: {
276
1074
  'application/cloudevents+json': components['schemas']['Event'];
@@ -278,67 +1076,70 @@ export interface operations {
278
1076
  };
279
1077
  };
280
1078
  responses: {
281
- /** @description OK */
1079
+ /** @description Successfully ingested. */
282
1080
  204: {
283
1081
  content: never;
284
1082
  };
285
1083
  400: components['responses']['BadRequestProblemResponse'];
1084
+ 401: components['responses']['UnauthorizedProblemResponse'];
286
1085
  default: components['responses']['UnexpectedProblemResponse'];
287
1086
  };
288
1087
  };
289
- /** @description List meters */
1088
+ /**
1089
+ * List meters
1090
+ * @description List meters.
1091
+ */
290
1092
  listMeters: {
291
- parameters: {
292
- header?: {
293
- 'OM-Namespace'?: components['parameters']['namespaceParam'];
294
- };
295
- };
296
1093
  responses: {
297
- /** @description Meters response */
1094
+ /** @description List of meters. */
298
1095
  200: {
299
1096
  content: {
300
1097
  'application/json': components['schemas']['Meter'][];
301
1098
  };
302
1099
  };
1100
+ 401: components['responses']['UnauthorizedProblemResponse'];
303
1101
  default: components['responses']['UnexpectedProblemResponse'];
304
1102
  };
305
1103
  };
306
- /** @description Create meter */
1104
+ /**
1105
+ * ☁ Create meter
1106
+ * @description *Available in OpenMeter Cloud.*
1107
+ * *In the open-source version, meters are created in the configuration file.*
1108
+ *
1109
+ * Create a meter.
1110
+ */
307
1111
  createMeter: {
308
- parameters: {
309
- header?: {
310
- 'OM-Namespace'?: components['parameters']['namespaceParam'];
311
- };
312
- };
1112
+ /** @description The meter to create. */
313
1113
  requestBody: {
314
1114
  content: {
315
1115
  'application/json': components['schemas']['Meter'];
316
1116
  };
317
1117
  };
318
1118
  responses: {
319
- /** @description Created */
1119
+ /** @description Created. */
320
1120
  201: {
321
1121
  content: {
322
1122
  'application/json': components['schemas']['Meter'];
323
1123
  };
324
1124
  };
325
1125
  400: components['responses']['BadRequestProblemResponse'];
1126
+ 401: components['responses']['UnauthorizedProblemResponse'];
326
1127
  501: components['responses']['NotImplementedProblemResponse'];
327
1128
  default: components['responses']['UnexpectedProblemResponse'];
328
1129
  };
329
1130
  };
330
- /** @description Get meter by slugs */
1131
+ /**
1132
+ * Get meter
1133
+ * @description Get meter by ID or slug
1134
+ */
331
1135
  getMeter: {
332
1136
  parameters: {
333
- header?: {
334
- 'OM-Namespace'?: components['parameters']['namespaceParam'];
335
- };
336
1137
  path: {
337
1138
  meterIdOrSlug: components['parameters']['meterIdOrSlug'];
338
1139
  };
339
1140
  };
340
1141
  responses: {
341
- /** @description OK */
1142
+ /** @description Meter found. */
342
1143
  200: {
343
1144
  content: {
344
1145
  'application/json': components['schemas']['Meter'];
@@ -348,18 +1149,20 @@ export interface operations {
348
1149
  default: components['responses']['UnexpectedProblemResponse'];
349
1150
  };
350
1151
  };
351
- /** @description Delete meter by slug */
1152
+ /**
1153
+ * ☁ Delete meter
1154
+ * @description *Available in OpenMeter Cloud.*
1155
+ *
1156
+ * Delete a meter by ID or slug.
1157
+ */
352
1158
  deleteMeter: {
353
1159
  parameters: {
354
- header?: {
355
- 'OM-Namespace'?: components['parameters']['namespaceParam'];
356
- };
357
1160
  path: {
358
1161
  meterIdOrSlug: components['parameters']['meterIdOrSlug'];
359
1162
  };
360
1163
  };
361
1164
  responses: {
362
- /** @description No Content */
1165
+ /** @description Meter deleted. */
363
1166
  204: {
364
1167
  content: never;
365
1168
  };
@@ -369,146 +1172,618 @@ export interface operations {
369
1172
  };
370
1173
  };
371
1174
  /**
372
- * @deprecated
373
- * @description Get meter values
374
- * Deprecated: use /api/v1/meters/{meter}/query instead.
1175
+ * Query meter
1176
+ * @description Query meter for usage.
375
1177
  */
376
- getMeterValues: {
1178
+ queryMeter: {
377
1179
  parameters: {
378
1180
  query?: {
379
- subject?: string;
380
- /**
381
- * @description Start date-time in RFC 3339 format in UTC timezone.
382
- * Must be aligned with the window size.
383
- * Inclusive.
384
- */
385
- from?: string;
386
- /**
387
- * @description End date-time in RFC 3339 format in UTC timezone.
388
- * Must be aligned with the window size.
389
- * Inclusive.
390
- */
391
- to?: string;
392
- /** @description If not specified, a single usage aggregate will be returned for the entirety of the specified period for each subject and group. */
393
- windowSize?: components['schemas']['WindowSize'];
394
- /**
395
- * @description If not specified, OpenMeter will use the default aggregation type.
396
- * As OpenMeter stores aggregates defined by meter config, passing a different aggregate can lead to inaccurate results.
397
- * For example getting the MIN of SUMs.
398
- */
399
- aggregation?: components['schemas']['MeterAggregation'];
400
- /** @description If not specified a single aggregate will be returned for each subject and time window. */
401
- groupBy?: string;
1181
+ from?: components['parameters']['queryFrom'];
1182
+ to?: components['parameters']['queryTo'];
1183
+ windowSize?: components['parameters']['queryWindowSize'];
1184
+ windowTimeZone?: components['parameters']['queryWindowTimeZone'];
1185
+ subject?: components['parameters']['queryFilterSubject'];
1186
+ filterGroupBy?: components['parameters']['queryFilterGroupBy'];
1187
+ groupBy?: components['parameters']['queryGroupBy'];
402
1188
  };
403
- header?: {
404
- 'OM-Namespace'?: components['parameters']['namespaceParam'];
1189
+ path: {
1190
+ meterIdOrSlug: components['parameters']['meterIdOrSlug'];
405
1191
  };
1192
+ };
1193
+ responses: {
1194
+ /** @description Usage data. */
1195
+ 200: {
1196
+ content: {
1197
+ 'application/json': components['schemas']['MeterQueryResult'];
1198
+ 'text/csv': string;
1199
+ };
1200
+ };
1201
+ 400: components['responses']['BadRequestProblemResponse'];
1202
+ 401: components['responses']['UnauthorizedProblemResponse'];
1203
+ default: components['responses']['UnexpectedProblemResponse'];
1204
+ };
1205
+ };
1206
+ /**
1207
+ * List meter subjects
1208
+ * @description List subjects for a meter.
1209
+ */
1210
+ listMeterSubjects: {
1211
+ parameters: {
406
1212
  path: {
407
1213
  meterIdOrSlug: components['parameters']['meterIdOrSlug'];
408
1214
  };
409
1215
  };
410
1216
  responses: {
411
- /** @description OK */
1217
+ /** @description List of subjects. */
412
1218
  200: {
413
1219
  content: {
414
- 'application/json': {
415
- windowSize?: components['schemas']['WindowSize'];
416
- data: components['schemas']['MeterValue'][];
417
- };
1220
+ 'application/json': string[];
418
1221
  };
419
1222
  };
420
1223
  400: components['responses']['BadRequestProblemResponse'];
421
1224
  default: components['responses']['UnexpectedProblemResponse'];
422
1225
  };
423
1226
  };
424
- /** @description Query meter */
425
- queryMeter: {
1227
+ /**
1228
+ * ☁ List portal tokens
1229
+ * @description *Available in OpenMeter Cloud.*
1230
+ *
1231
+ * List consumer portal tokens.
1232
+ */
1233
+ listPortalTokens: {
426
1234
  parameters: {
427
1235
  query?: {
1236
+ /** @description Number of portal tokens to return. Default is 25. */
1237
+ limit?: number;
1238
+ };
1239
+ };
1240
+ responses: {
1241
+ /** @description List of portal tokens. */
1242
+ 200: {
1243
+ content: {
1244
+ 'application/json': components['schemas']['PortalToken'][];
1245
+ };
1246
+ };
1247
+ 400: components['responses']['BadRequestProblemResponse'];
1248
+ 401: components['responses']['UnauthorizedProblemResponse'];
1249
+ 501: components['responses']['NotImplementedProblemResponse'];
1250
+ default: components['responses']['UnexpectedProblemResponse'];
1251
+ };
1252
+ };
1253
+ /**
1254
+ * Create portal token
1255
+ * @description Create a consumer portal token.
1256
+ */
1257
+ createPortalToken: {
1258
+ /** @description The portal token to create. */
1259
+ requestBody: {
1260
+ content: {
428
1261
  /**
429
- * @description Start date-time in RFC 3339 format in UTC timezone.
430
- * Must be aligned with the window size.
431
- * Inclusive.
432
- */
433
- from?: string;
434
- /**
435
- * @description End date-time in RFC 3339 format in UTC timezone.
436
- * Must be aligned with the window size.
437
- * Inclusive.
438
- */
439
- to?: string;
440
- /** @description If not specified, a single usage aggregate will be returned for the entirety of the specified period for each subject and group. */
441
- windowSize?: components['schemas']['WindowSize'];
442
- /**
443
- * @deprecated
444
- * @description If not specified, OpenMeter will use the default aggregation type.
445
- * As OpenMeter stores aggregates defined by meter config, passing a different aggregate can lead to inaccurate results.
446
- * For example getting the MIN of SUMs.
1262
+ * @example {
1263
+ * "subject": "customer-id",
1264
+ * "allowedMeterSlugs": [
1265
+ * "tokens_total"
1266
+ * ]
1267
+ * }
447
1268
  */
448
- aggregation?: components['schemas']['MeterAggregation'];
449
- subject?: string[];
450
- /** @description If not specified a single aggregate will be returned for each subject and time window. */
451
- groupBy?: string[];
1269
+ 'application/json': components['schemas']['PortalToken'];
452
1270
  };
453
- header?: {
454
- 'OM-Namespace'?: components['parameters']['namespaceParam'];
1271
+ };
1272
+ responses: {
1273
+ /** @description Created. */
1274
+ 200: {
1275
+ content: {
1276
+ 'application/json': components['schemas']['PortalToken'];
1277
+ };
1278
+ };
1279
+ 400: components['responses']['BadRequestProblemResponse'];
1280
+ 401: components['responses']['UnauthorizedProblemResponse'];
1281
+ default: components['responses']['UnexpectedProblemResponse'];
1282
+ };
1283
+ };
1284
+ /**
1285
+ * ☁ Invalidate portal tokens
1286
+ * @description *Available in OpenMeter Cloud.*
1287
+ *
1288
+ * Invalidates consumer portal tokens by ID or subject.
1289
+ */
1290
+ invalidatePortalTokens: {
1291
+ /** @description If no id or subject is specified, all tokens will be invalidated. */
1292
+ requestBody: {
1293
+ content: {
1294
+ 'application/json': {
1295
+ /** @description Invalidate a portal token by ID. */
1296
+ id?: string;
1297
+ /** @description Invalidate all portal tokens for a subject. */
1298
+ subject?: string;
1299
+ };
1300
+ };
1301
+ };
1302
+ responses: {
1303
+ /** @description Portal tokens invalidated. */
1304
+ 204: {
1305
+ content: never;
1306
+ };
1307
+ 400: components['responses']['BadRequestProblemResponse'];
1308
+ 401: components['responses']['UnauthorizedProblemResponse'];
1309
+ 501: components['responses']['NotImplementedProblemResponse'];
1310
+ default: components['responses']['UnexpectedProblemResponse'];
1311
+ };
1312
+ };
1313
+ /**
1314
+ * ☁ List subjects
1315
+ * @description *Available in OpenMeter Cloud.*
1316
+ *
1317
+ * List subjects.
1318
+ */
1319
+ listSubjects: {
1320
+ responses: {
1321
+ /** @description List of subjects. */
1322
+ 200: {
1323
+ content: {
1324
+ 'application/json': components['schemas']['Subject'][];
1325
+ };
455
1326
  };
1327
+ 401: components['responses']['UnauthorizedProblemResponse'];
1328
+ default: components['responses']['UnexpectedProblemResponse'];
1329
+ };
1330
+ };
1331
+ /**
1332
+ * ☁ Upsert subject
1333
+ * @description *Available in OpenMeter Cloud.*
1334
+ *
1335
+ * Upserts a subject. Creates or updates subject.
1336
+ * If the subject doesn't exist, it will be created.
1337
+ * If the subject exists, it will be partially updated with the provided fields.
1338
+ */
1339
+ upsertSubject: {
1340
+ /** @description The subject to upsert. */
1341
+ requestBody: {
1342
+ content: {
1343
+ 'application/json': components['schemas']['Subject'][];
1344
+ };
1345
+ };
1346
+ responses: {
1347
+ /** @description Subject upserted. */
1348
+ 200: {
1349
+ content: {
1350
+ 'application/json': components['schemas']['Subject'][];
1351
+ };
1352
+ };
1353
+ 400: components['responses']['BadRequestProblemResponse'];
1354
+ 401: components['responses']['UnauthorizedProblemResponse'];
1355
+ 501: components['responses']['NotImplementedProblemResponse'];
1356
+ default: components['responses']['UnexpectedProblemResponse'];
1357
+ };
1358
+ };
1359
+ /**
1360
+ * ☁ Get subject
1361
+ * @description *Available in OpenMeter Cloud.*
1362
+ *
1363
+ * Get subject by ID or key.
1364
+ */
1365
+ getSubject: {
1366
+ parameters: {
456
1367
  path: {
457
- meterIdOrSlug: components['parameters']['meterIdOrSlug'];
1368
+ subjectIdOrKey: components['parameters']['subjectIdOrKey'];
458
1369
  };
459
1370
  };
460
1371
  responses: {
461
- /** @description OK */
1372
+ /** @description Subject found. */
462
1373
  200: {
463
1374
  content: {
464
- 'application/json': {
465
- /** Format: date-time */
466
- from?: string;
467
- /** Format: date-time */
468
- to?: string;
469
- windowSize?: components['schemas']['WindowSize'];
470
- data: components['schemas']['MeterQueryRow'][];
471
- };
1375
+ 'application/json': components['schemas']['Subject'];
1376
+ };
1377
+ };
1378
+ 401: components['responses']['UnauthorizedProblemResponse'];
1379
+ 404: components['responses']['NotFoundProblemResponse'];
1380
+ default: components['responses']['UnexpectedProblemResponse'];
1381
+ };
1382
+ };
1383
+ /**
1384
+ * ☁ Delete subject
1385
+ * @description *Available in OpenMeter Cloud.*
1386
+ *
1387
+ * Delete a subject by ID or key.
1388
+ */
1389
+ deleteSubject: {
1390
+ parameters: {
1391
+ path: {
1392
+ subjectIdOrKey: components['parameters']['subjectIdOrKey'];
1393
+ };
1394
+ };
1395
+ responses: {
1396
+ /** @description Subject deleted. */
1397
+ 204: {
1398
+ content: never;
1399
+ };
1400
+ 400: components['responses']['BadRequestProblemResponse'];
1401
+ 401: components['responses']['UnauthorizedProblemResponse'];
1402
+ 404: components['responses']['NotFoundProblemResponse'];
1403
+ 501: components['responses']['NotImplementedProblemResponse'];
1404
+ default: components['responses']['UnexpectedProblemResponse'];
1405
+ };
1406
+ };
1407
+ /**
1408
+ * Query portal meter
1409
+ * @description Query meter for consumer portal. This endpoint is publicly exposable to consumers.
1410
+ */
1411
+ queryPortalMeter: {
1412
+ parameters: {
1413
+ query?: {
1414
+ from?: components['parameters']['queryFrom'];
1415
+ to?: components['parameters']['queryTo'];
1416
+ windowSize?: components['parameters']['queryWindowSize'];
1417
+ windowTimeZone?: components['parameters']['queryWindowTimeZone'];
1418
+ filterGroupBy?: components['parameters']['queryFilterGroupBy'];
1419
+ groupBy?: components['parameters']['queryGroupBy'];
1420
+ };
1421
+ path: {
1422
+ /** @description A unique identifier for the meter. */
1423
+ meterSlug: string;
1424
+ };
1425
+ };
1426
+ responses: {
1427
+ /** @description Usage data. */
1428
+ 200: {
1429
+ content: {
1430
+ 'application/json': components['schemas']['MeterQueryResult'];
472
1431
  'text/csv': string;
473
1432
  };
474
1433
  };
475
1434
  400: components['responses']['BadRequestProblemResponse'];
1435
+ 401: components['responses']['UnauthorizedProblemResponse'];
476
1436
  default: components['responses']['UnexpectedProblemResponse'];
477
1437
  };
478
1438
  };
479
- /** @description List meter subjects */
480
- listMeterSubjects: {
1439
+ /**
1440
+ * List features
1441
+ * @description List features.
1442
+ */
1443
+ listFeatures: {
481
1444
  parameters: {
482
- header?: {
483
- 'OM-Namespace'?: components['parameters']['namespaceParam'];
1445
+ query?: {
1446
+ limit?: components['parameters']['ledgerQueryLimit'];
1447
+ offset?: components['parameters']['ledgerQueryOffset'];
1448
+ /** @description Order by field */
1449
+ orderBy?: 'id' | 'createdAt' | 'updatedAt';
1450
+ /** @description Include archived features. */
1451
+ includeArchived?: boolean;
484
1452
  };
1453
+ };
1454
+ responses: {
1455
+ /** @description List of features. */
1456
+ 200: {
1457
+ content: {
1458
+ 'application/json': components['schemas']['Feature'][];
1459
+ };
1460
+ };
1461
+ 401: components['responses']['UnauthorizedProblemResponse'];
1462
+ default: components['responses']['UnexpectedProblemResponse'];
1463
+ };
1464
+ };
1465
+ /**
1466
+ * Create feature
1467
+ * @description Creates a feature.
1468
+ */
1469
+ createFeature: {
1470
+ /** @description The feature to create. */
1471
+ requestBody: {
1472
+ content: {
1473
+ 'application/json': components['schemas']['Feature'];
1474
+ };
1475
+ };
1476
+ responses: {
1477
+ /** @description Feature created. */
1478
+ 201: {
1479
+ content: {
1480
+ 'application/json': components['schemas']['Feature'];
1481
+ };
1482
+ };
1483
+ 400: components['responses']['BadRequestProblemResponse'];
1484
+ 401: components['responses']['UnauthorizedProblemResponse'];
1485
+ 501: components['responses']['NotImplementedProblemResponse'];
1486
+ default: components['responses']['UnexpectedProblemResponse'];
1487
+ };
1488
+ };
1489
+ /**
1490
+ * Get feature
1491
+ * @description Get feature by key.
1492
+ */
1493
+ getFeature: {
1494
+ parameters: {
485
1495
  path: {
486
- meterIdOrSlug: components['parameters']['meterIdOrSlug'];
1496
+ featureID: components['parameters']['featureID'];
487
1497
  };
488
1498
  };
489
1499
  responses: {
490
- /** @description OK */
1500
+ /** @description Feature found. */
491
1501
  200: {
492
1502
  content: {
493
- 'application/json': string[];
1503
+ 'application/json': components['schemas']['Feature'];
1504
+ };
1505
+ };
1506
+ 401: components['responses']['UnauthorizedProblemResponse'];
1507
+ 404: components['responses']['NotFoundProblemResponse'];
1508
+ default: components['responses']['UnexpectedProblemResponse'];
1509
+ };
1510
+ };
1511
+ /**
1512
+ * Delete feature
1513
+ * @description Delete a feature by key.
1514
+ */
1515
+ deleteFeature: {
1516
+ parameters: {
1517
+ path: {
1518
+ featureID: components['parameters']['featureID'];
1519
+ };
1520
+ };
1521
+ responses: {
1522
+ /** @description Feature deleted. */
1523
+ 204: {
1524
+ content: never;
1525
+ };
1526
+ 401: components['responses']['UnauthorizedProblemResponse'];
1527
+ 404: components['responses']['NotFoundProblemResponse'];
1528
+ default: components['responses']['UnexpectedProblemResponse'];
1529
+ };
1530
+ };
1531
+ /**
1532
+ * List the already defined ledgers.
1533
+ * @description List the already defined ledgers.
1534
+ */
1535
+ listLedgers: {
1536
+ parameters: {
1537
+ query?: {
1538
+ /** @description Query ledgers specific to subjects. */
1539
+ subject?: string[];
1540
+ /** @description Query ledgers with subjects that are similar to the provided text. */
1541
+ subjectSimilarTo?: string;
1542
+ limit?: components['parameters']['ledgerQueryLimit'];
1543
+ offset?: components['parameters']['ledgerQueryOffset'];
1544
+ /** @description Order by field */
1545
+ orderBy?: 'subject' | 'createdAt' | 'id';
1546
+ };
1547
+ };
1548
+ responses: {
1549
+ /** @description List of the matching ledgers. */
1550
+ 200: {
1551
+ content: {
1552
+ 'application/json': components['schemas']['Ledger'][];
1553
+ };
1554
+ };
1555
+ 400: components['responses']['BadRequestProblemResponse'];
1556
+ 401: components['responses']['UnauthorizedProblemResponse'];
1557
+ default: components['responses']['UnexpectedProblemResponse'];
1558
+ };
1559
+ };
1560
+ /**
1561
+ * Creates the specified ledger
1562
+ * @description Create or update the specified ledger.
1563
+ */
1564
+ createLedger: {
1565
+ /** @description The ledger to be created */
1566
+ requestBody: {
1567
+ content: {
1568
+ 'application/json': components['schemas']['CreateLedger'];
1569
+ };
1570
+ };
1571
+ responses: {
1572
+ /** @description The created ledger. */
1573
+ 201: {
1574
+ content: {
1575
+ 'application/json': components['schemas']['Ledger'];
1576
+ };
1577
+ };
1578
+ 400: components['responses']['BadRequestProblemResponse'];
1579
+ 401: components['responses']['UnauthorizedProblemResponse'];
1580
+ 409: components['responses']['LedgerAlreadyExistsProblemResponse'];
1581
+ default: components['responses']['UnexpectedProblemResponse'];
1582
+ };
1583
+ };
1584
+ /**
1585
+ * Get the balance of a specific subject.
1586
+ * @description Get the balance of a specific subject.
1587
+ */
1588
+ getLedgerBalance: {
1589
+ parameters: {
1590
+ query?: {
1591
+ /** @description Point of time to query balances: date-time in RFC 3339 format. Defaults to now. */
1592
+ time?: string;
1593
+ };
1594
+ path: {
1595
+ ledgerID: components['parameters']['ledgerID'];
1596
+ };
1597
+ };
1598
+ responses: {
1599
+ /** @description Ledger balances available. */
1600
+ 200: {
1601
+ content: {
1602
+ 'application/json': components['schemas']['LedgerBalance'];
1603
+ };
1604
+ };
1605
+ 401: components['responses']['UnauthorizedProblemResponse'];
1606
+ 404: components['responses']['NotFoundProblemResponse'];
1607
+ default: components['responses']['UnexpectedProblemResponse'];
1608
+ };
1609
+ };
1610
+ /**
1611
+ * Get the history of a ledger
1612
+ * @description Get the history of a specific ledger
1613
+ */
1614
+ getLedgerHistory: {
1615
+ parameters: {
1616
+ query: {
1617
+ limit?: components['parameters']['ledgerQueryLimit'];
1618
+ offset?: components['parameters']['ledgerQueryOffset'];
1619
+ /** @description Start of time range to query ledger: date-time in RFC 3339 format. */
1620
+ from: string;
1621
+ /** @description End of time range to query ledger: date-time in RFC 3339 format. Defaults to now. */
1622
+ to?: string;
1623
+ };
1624
+ path: {
1625
+ ledgerID: components['parameters']['ledgerID'];
1626
+ };
1627
+ };
1628
+ responses: {
1629
+ /** @description Ledger balance history. */
1630
+ 200: {
1631
+ content: {
1632
+ 'application/json': components['schemas']['LedgerEntry'][];
1633
+ };
1634
+ };
1635
+ 401: components['responses']['UnauthorizedProblemResponse'];
1636
+ 404: components['responses']['NotFoundProblemResponse'];
1637
+ default: components['responses']['UnexpectedProblemResponse'];
1638
+ };
1639
+ };
1640
+ /**
1641
+ * Reset the ledger's balance
1642
+ * @description Resets the ledger's balances to zero for a specific subject and re-apply active grants with rollover configuration.
1643
+ */
1644
+ resetLedger: {
1645
+ parameters: {
1646
+ path: {
1647
+ ledgerID: components['parameters']['ledgerID'];
1648
+ };
1649
+ };
1650
+ /** @description Details for the reset. */
1651
+ requestBody: {
1652
+ content: {
1653
+ 'application/json': components['schemas']['LedgerReset'];
1654
+ };
1655
+ };
1656
+ responses: {
1657
+ /** @description Ledger balance reset. */
1658
+ 201: {
1659
+ content: {
1660
+ 'application/json': components['schemas']['LedgerReset'];
494
1661
  };
495
1662
  };
496
1663
  400: components['responses']['BadRequestProblemResponse'];
1664
+ 401: components['responses']['UnauthorizedProblemResponse'];
1665
+ 404: components['responses']['NotFoundProblemResponse'];
497
1666
  default: components['responses']['UnexpectedProblemResponse'];
498
1667
  };
499
1668
  };
500
- /** @description Create namespace */
501
- createNamespace: {
1669
+ /**
1670
+ * List grants for multiple ledgers.
1671
+ * @description List grants for multiple ledgers.
1672
+ */
1673
+ listLedgerGrants: {
1674
+ parameters: {
1675
+ query?: {
1676
+ ledgerID?: components['parameters']['queryFilterLedgerID'];
1677
+ limit?: components['parameters']['ledgerQueryLimit'];
1678
+ };
1679
+ };
1680
+ responses: {
1681
+ /** @description List of ledger grants. */
1682
+ 200: {
1683
+ content: {
1684
+ 'application/json': components['schemas']['LedgerGrantResponse'][];
1685
+ };
1686
+ };
1687
+ 400: components['responses']['BadRequestProblemResponse'];
1688
+ 401: components['responses']['UnauthorizedProblemResponse'];
1689
+ default: components['responses']['UnexpectedProblemResponse'];
1690
+ };
1691
+ };
1692
+ /**
1693
+ * List ledger grants
1694
+ * @description List ledger grants for a specific ledger.
1695
+ */
1696
+ listLedgerGrantsByLedger: {
1697
+ parameters: {
1698
+ query?: {
1699
+ limit?: components['parameters']['ledgerQueryLimit'];
1700
+ };
1701
+ path: {
1702
+ ledgerID: components['parameters']['ledgerID'];
1703
+ };
1704
+ };
1705
+ responses: {
1706
+ /** @description List of ledger grants created. */
1707
+ 200: {
1708
+ content: {
1709
+ 'application/json': components['schemas']['LedgerGrantResponse'][];
1710
+ };
1711
+ };
1712
+ 400: components['responses']['BadRequestProblemResponse'];
1713
+ 401: components['responses']['UnauthorizedProblemResponse'];
1714
+ default: components['responses']['UnexpectedProblemResponse'];
1715
+ };
1716
+ };
1717
+ /**
1718
+ * Create a grant on a specific ledger.
1719
+ * @description Create a grant on a specific ledger.
1720
+ */
1721
+ createLedgerGrant: {
1722
+ parameters: {
1723
+ path: {
1724
+ ledgerID: components['parameters']['ledgerID'];
1725
+ };
1726
+ };
1727
+ /** @description The grant to create. */
502
1728
  requestBody: {
503
1729
  content: {
504
- 'application/json': components['schemas']['Namespace'];
1730
+ 'application/json': components['schemas']['CreateLedgerGrantRequest'];
505
1731
  };
506
1732
  };
507
1733
  responses: {
508
- /** @description Created */
1734
+ /** @description LedgerGrant created. */
509
1735
  201: {
1736
+ content: {
1737
+ 'application/json': components['schemas']['LedgerGrantResponse'];
1738
+ };
1739
+ };
1740
+ 400: components['responses']['BadRequestProblemResponse'];
1741
+ 401: components['responses']['UnauthorizedProblemResponse'];
1742
+ default: components['responses']['UnexpectedProblemResponse'];
1743
+ };
1744
+ };
1745
+ /**
1746
+ * Get a single grant.
1747
+ * @description Gets the grant for a ledger by ID.
1748
+ */
1749
+ getLedgerGrant: {
1750
+ parameters: {
1751
+ path: {
1752
+ ledgerID: components['parameters']['ledgerID'];
1753
+ ledgerGrantID: components['parameters']['ledgerGrantID'];
1754
+ };
1755
+ };
1756
+ responses: {
1757
+ /** @description Ledger grant found. */
1758
+ 200: {
1759
+ content: {
1760
+ 'application/json': components['schemas']['LedgerGrantResponse'];
1761
+ };
1762
+ };
1763
+ 401: components['responses']['UnauthorizedProblemResponse'];
1764
+ 404: components['responses']['NotFoundProblemResponse'];
1765
+ default: components['responses']['UnexpectedProblemResponse'];
1766
+ };
1767
+ };
1768
+ /**
1769
+ * Void ledger grant
1770
+ * @description Void a ledger grant by ID. Partially or fully used grants cannot be voided.
1771
+ * Voided grant won't be applied to the subject's balance anymore.
1772
+ */
1773
+ voidLedgerGrant: {
1774
+ parameters: {
1775
+ path: {
1776
+ ledgerGrantID: components['parameters']['ledgerGrantID'];
1777
+ ledgerID: components['parameters']['ledgerID'];
1778
+ };
1779
+ };
1780
+ responses: {
1781
+ /** @description Ledger grant voided. */
1782
+ 204: {
510
1783
  content: never;
511
1784
  };
1785
+ 401: components['responses']['UnauthorizedProblemResponse'];
1786
+ 404: components['responses']['NotFoundProblemResponse'];
512
1787
  default: components['responses']['UnexpectedProblemResponse'];
513
1788
  };
514
1789
  };