@openmeter/client 1.0.0-beta.230 → 1.0.0-beta.232

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 (137) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +365 -76
  3. package/dist/core.d.ts +0 -1
  4. package/dist/core.js +11 -1
  5. package/dist/funcs/addons.d.ts +49 -1
  6. package/dist/funcs/addons.js +109 -12
  7. package/dist/funcs/apps.d.ts +55 -2
  8. package/dist/funcs/apps.js +179 -4
  9. package/dist/funcs/billing.d.ts +46 -1
  10. package/dist/funcs/billing.js +81 -8
  11. package/dist/funcs/currencies.d.ts +39 -2
  12. package/dist/funcs/currencies.js +93 -6
  13. package/dist/funcs/customers.d.ts +165 -2
  14. package/dist/funcs/customers.js +402 -40
  15. package/dist/funcs/defaults.d.ts +10 -1
  16. package/dist/funcs/defaults.js +11 -1
  17. package/dist/funcs/entitlements.d.ts +5 -1
  18. package/dist/funcs/entitlements.js +18 -4
  19. package/dist/funcs/events.d.ts +14 -1
  20. package/dist/funcs/events.js +18 -1
  21. package/dist/funcs/features.d.ts +42 -1
  22. package/dist/funcs/features.js +91 -10
  23. package/dist/funcs/governance.d.ts +14 -1
  24. package/dist/funcs/governance.js +15 -1
  25. package/dist/funcs/index.d.ts +0 -1
  26. package/dist/funcs/index.js +1 -1
  27. package/dist/funcs/invoices.d.ts +102 -2
  28. package/dist/funcs/invoices.js +247 -8
  29. package/dist/funcs/llmCost.d.ts +36 -1
  30. package/dist/funcs/llmCost.js +63 -6
  31. package/dist/funcs/meters.d.ts +53 -1
  32. package/dist/funcs/meters.js +113 -12
  33. package/dist/funcs/planAddons.d.ts +35 -1
  34. package/dist/funcs/planAddons.js +101 -18
  35. package/dist/funcs/plans.d.ts +49 -1
  36. package/dist/funcs/plans.js +109 -12
  37. package/dist/funcs/subscriptions.d.ts +59 -1
  38. package/dist/funcs/subscriptions.js +147 -18
  39. package/dist/funcs/tax.d.ts +25 -1
  40. package/dist/funcs/tax.js +60 -8
  41. package/dist/index.d.ts +4 -7
  42. package/dist/index.js +4 -6
  43. package/dist/lib/config.d.ts +2 -3
  44. package/dist/lib/config.js +1 -1
  45. package/dist/lib/encodings.d.ts +0 -1
  46. package/dist/lib/encodings.js +1 -1
  47. package/dist/lib/paginate.d.ts +56 -0
  48. package/dist/lib/paginate.js +60 -0
  49. package/dist/lib/request.d.ts +0 -1
  50. package/dist/lib/request.js +1 -1
  51. package/dist/lib/to-error.d.ts +0 -1
  52. package/dist/lib/to-error.js +1 -1
  53. package/dist/lib/types.d.ts +0 -1
  54. package/dist/lib/types.js +1 -1
  55. package/dist/lib/version.d.ts +1 -0
  56. package/dist/lib/version.js +5 -0
  57. package/dist/lib/wire.d.ts +4 -1
  58. package/dist/lib/wire.js +118 -7
  59. package/dist/models/errors.d.ts +13 -2
  60. package/dist/models/errors.js +31 -4
  61. package/dist/models/operations/addons.d.ts +0 -1
  62. package/dist/models/operations/addons.js +1 -1
  63. package/dist/models/operations/apps.d.ts +26 -5
  64. package/dist/models/operations/apps.js +1 -1
  65. package/dist/models/operations/billing.d.ts +0 -1
  66. package/dist/models/operations/billing.js +1 -1
  67. package/dist/models/operations/currencies.d.ts +10 -1
  68. package/dist/models/operations/currencies.js +1 -1
  69. package/dist/models/operations/customers.d.ts +11 -7
  70. package/dist/models/operations/customers.js +1 -1
  71. package/dist/models/operations/defaults.d.ts +0 -1
  72. package/dist/models/operations/defaults.js +1 -1
  73. package/dist/models/operations/entitlements.d.ts +0 -1
  74. package/dist/models/operations/entitlements.js +1 -1
  75. package/dist/models/operations/events.d.ts +0 -1
  76. package/dist/models/operations/events.js +1 -1
  77. package/dist/models/operations/features.d.ts +0 -1
  78. package/dist/models/operations/features.js +1 -1
  79. package/dist/models/operations/governance.d.ts +0 -1
  80. package/dist/models/operations/governance.js +1 -1
  81. package/dist/models/operations/invoices.d.ts +20 -7
  82. package/dist/models/operations/invoices.js +1 -1
  83. package/dist/models/operations/llmCost.d.ts +0 -1
  84. package/dist/models/operations/llmCost.js +1 -1
  85. package/dist/models/operations/meters.d.ts +0 -1
  86. package/dist/models/operations/meters.js +1 -1
  87. package/dist/models/operations/planAddons.d.ts +0 -1
  88. package/dist/models/operations/planAddons.js +1 -1
  89. package/dist/models/operations/plans.d.ts +0 -1
  90. package/dist/models/operations/plans.js +1 -1
  91. package/dist/models/operations/subscriptions.d.ts +0 -1
  92. package/dist/models/operations/subscriptions.js +1 -1
  93. package/dist/models/operations/tax.d.ts +0 -1
  94. package/dist/models/operations/tax.js +1 -1
  95. package/dist/models/schemas.d.ts +11651 -6090
  96. package/dist/models/schemas.js +991 -468
  97. package/dist/models/types.d.ts +941 -810
  98. package/dist/models/types.js +1 -1
  99. package/dist/sdk/addons.d.ts +60 -1
  100. package/dist/sdk/addons.js +63 -1
  101. package/dist/sdk/apps.d.ts +68 -2
  102. package/dist/sdk/apps.js +81 -2
  103. package/dist/sdk/billing.d.ts +57 -1
  104. package/dist/sdk/billing.js +60 -1
  105. package/dist/sdk/customers.d.ts +211 -2
  106. package/dist/sdk/customers.js +222 -2
  107. package/dist/sdk/defaults.d.ts +10 -1
  108. package/dist/sdk/defaults.js +11 -1
  109. package/dist/sdk/entitlements.d.ts +5 -1
  110. package/dist/sdk/entitlements.js +6 -1
  111. package/dist/sdk/events.d.ts +25 -1
  112. package/dist/sdk/events.js +28 -1
  113. package/dist/sdk/features.d.ts +53 -1
  114. package/dist/sdk/features.js +56 -1
  115. package/dist/sdk/internal.d.ts +328 -0
  116. package/dist/sdk/internal.js +404 -0
  117. package/dist/sdk/invoices.d.ts +5 -2
  118. package/dist/sdk/invoices.js +13 -2
  119. package/dist/sdk/llmCost.d.ts +57 -1
  120. package/dist/sdk/llmCost.js +62 -1
  121. package/dist/sdk/meters.d.ts +64 -1
  122. package/dist/sdk/meters.js +67 -1
  123. package/dist/sdk/planAddons.d.ts +46 -1
  124. package/dist/sdk/planAddons.js +49 -1
  125. package/dist/sdk/plans.d.ts +60 -1
  126. package/dist/sdk/plans.js +63 -1
  127. package/dist/sdk/sdk.d.ts +9 -13
  128. package/dist/sdk/sdk.js +11 -20
  129. package/dist/sdk/subscriptions.d.ts +72 -3
  130. package/dist/sdk/subscriptions.js +77 -5
  131. package/dist/sdk/tax.d.ts +34 -1
  132. package/dist/sdk/tax.js +37 -1
  133. package/package.json +30 -6
  134. package/dist/sdk/currencies.d.ts +0 -12
  135. package/dist/sdk/currencies.js +0 -21
  136. package/dist/sdk/governance.d.ts +0 -9
  137. package/dist/sdk/governance.js +0 -12
package/README.md CHANGED
@@ -1,11 +1,12 @@
1
+ <!-- Code generated by @openmeter/typespec-typescript. DO NOT EDIT. -->
2
+
1
3
  # OpenMeter SDK
2
4
 
3
5
  TypeScript client for the OpenMeter API — usage metering and billing for
4
6
  AI and DevTool companies. This package is generated from the OpenMeter
5
7
  TypeSpec definitions and ships fully-typed request and response models.
6
8
 
7
- > [!IMPORTANT]
8
- > This SDK is a work in progress.
9
+ > **Important:** This SDK is a work in progress.
9
10
  >
10
11
  > This SDK targets the [OpenMeter API v3](https://openmeter.io/docs/api/v3),
11
12
  > a rewrite of the OpenMeter API following AIP (API Improvement Proposal)
@@ -15,25 +16,31 @@ TypeSpec definitions and ships fully-typed request and response models.
15
16
 
16
17
  - [Installation](#installation)
17
18
  - [Initialization](#initialization)
19
+ - [Configuration](#configuration)
18
20
  - [Usage](#usage)
21
+ - [Pagination](#pagination)
19
22
  - [Available Resources and Operations](#available-resources-and-operations)
20
23
  - [Events](#events)
21
24
  - [Meters](#meters)
22
25
  - [Customers](#customers)
23
26
  - [Entitlements](#entitlements)
24
27
  - [Subscriptions](#subscriptions)
25
- - [Apps](#apps)
26
28
  - [Billing](#billing)
27
- - [Invoices](#invoices)
28
29
  - [Tax](#tax)
29
- - [Currencies](#currencies)
30
30
  - [Features](#features)
31
31
  - [LLMCost](#llmcost)
32
32
  - [Plans](#plans)
33
33
  - [Addons](#addons)
34
34
  - [PlanAddons](#planaddons)
35
35
  - [Defaults](#defaults)
36
- - [Governance](#governance)
36
+ - [Internal Operations](#internal-operations)
37
+ - [Internal Subscriptions](#internal-subscriptions)
38
+ - [Internal Apps](#internal-apps)
39
+ - [Internal Invoices](#internal-invoices)
40
+ - [Internal Currencies](#internal-currencies)
41
+ - [Internal Governance](#internal-governance)
42
+ - [Runtime Validation (validate option)](#runtime-validation-validate-option)
43
+ - [Zod Schemas (./zod export)](#zod-schemas-zod-export)
37
44
  - [Error Handling](#error-handling)
38
45
  - [Standalone Functions](#standalone-functions)
39
46
 
@@ -80,6 +87,76 @@ const client = new OpenMeter({
80
87
  The `apiKey` may also be a function returning a `string` or
81
88
  `Promise<string>`, so tokens can be refreshed per request.
82
89
 
90
+ ## Configuration
91
+
92
+ `SDKOptions` extends [ky](https://github.com/sindresorhus/ky)'s
93
+ `Options`, so every transport setting ky supports is a top-level client
94
+ option: retry policy, per-attempt timeout (ky defaults to 10 seconds),
95
+ lifecycle hooks, a custom `fetch`, and so on.
96
+
97
+ ```typescript
98
+ import { OpenMeter } from '@openmeter/client'
99
+
100
+ const client = new OpenMeter({
101
+ baseUrl: 'https://openmeter.cloud/api/v3',
102
+ apiKey: process.env.OPENMETER_API_KEY,
103
+ timeout: 30_000,
104
+ hooks: {
105
+ beforeRequest: [
106
+ ({ request }) => {
107
+ console.log(`-> ${request.method} ${request.url}`)
108
+ },
109
+ ],
110
+ },
111
+ fetch: async (input, init) => {
112
+ const start = Date.now()
113
+ const response = await fetch(input, init)
114
+ console.log(`${response.status} in ${Date.now() - start}ms`)
115
+ return response
116
+ },
117
+ })
118
+ ```
119
+
120
+ ky only retries the idempotent methods by default — `get`, `put`,
121
+ `head`, `delete`, `options`, `trace` — never `post`. That means a
122
+ dropped `client.events.ingest` call is not retried on a network error
123
+ or a 5xx response unless you opt in explicitly:
124
+
125
+ ```typescript
126
+ import { OpenMeter } from '@openmeter/client'
127
+
128
+ const client = new OpenMeter({
129
+ baseUrl: 'https://openmeter.cloud/api/v3',
130
+ apiKey: process.env.OPENMETER_API_KEY,
131
+ retry: { limit: 3, methods: ['get', 'put', 'head', 'delete', 'post'] },
132
+ })
133
+ ```
134
+
135
+ This is safe specifically for event ingestion: the event `id` is its
136
+ deduplication key server-side, so resending the same event on retry is
137
+ a no-op rather than a duplicate.
138
+
139
+ Every method also takes a per-request `RequestOptions` as its second
140
+ argument — a curated subset of ky's options (`signal`, `headers`,
141
+ `timeout`, `retry`) applied to that call only:
142
+
143
+ ```typescript
144
+ import { OpenMeter } from '@openmeter/client'
145
+
146
+ const client = new OpenMeter({
147
+ baseUrl: 'https://openmeter.cloud/api/v3',
148
+ apiKey: process.env.OPENMETER_API_KEY,
149
+ })
150
+
151
+ const controller = new AbortController()
152
+ setTimeout(() => controller.abort(), 5_000)
153
+
154
+ const meters = await client.meters.list(undefined, {
155
+ signal: controller.signal,
156
+ headers: { 'X-Request-Id': 'batch-42' },
157
+ })
158
+ ```
159
+
83
160
  ## Usage
84
161
 
85
162
  Every operation is reachable through a fluent, namespaced client and
@@ -112,6 +189,70 @@ Responses return date-time fields as native `Date` objects (every
112
189
  either a `Date` or an RFC 3339 string — a meter query `from`/`to`, an
113
190
  ingested event's `time`, filter operands, all alike.
114
191
 
192
+ ## Pagination
193
+
194
+ Every list operation that returns pages also has an `…All` companion —
195
+ `client.meters.listAll(request?)` alongside `client.meters.list(request?)` —
196
+ that returns an `AsyncIterable` of items instead of one page. It fetches
197
+ each following page lazily, only when the previous page is exhausted, so a
198
+ `break` (or a `return`) partway through never fires a request for a page
199
+ nothing consumes:
200
+
201
+ ```typescript
202
+ import { OpenMeter } from '@openmeter/client'
203
+
204
+ const client = new OpenMeter({
205
+ baseUrl: 'https://openmeter.cloud/api/v3',
206
+ apiKey: process.env.OPENMETER_API_KEY,
207
+ })
208
+
209
+ for await (const meter of client.meters.listAll()) {
210
+ console.log(meter.key)
211
+ }
212
+ ```
213
+
214
+ The request object accepts the same filters, sort, and page size as the
215
+ single-page method — only the page cursor/number itself advances between
216
+ requests:
217
+
218
+ ```typescript
219
+ for await (const meter of client.meters.listAll({ filter: { key: 'api' } })) {
220
+ if (meter.key === 'api-requests') {
221
+ break // stops iterating; no further pages are fetched
222
+ }
223
+ }
224
+ ```
225
+
226
+ Cursor-paginated resources (`events`, credit transactions) work the same
227
+ way:
228
+
229
+ ```typescript
230
+ for await (const event of client.events.listAll()) {
231
+ console.log(event.event.id)
232
+ }
233
+ ```
234
+
235
+ Auto-pagination takes the same optional `RequestOptions` as every other
236
+ method, so one `AbortSignal` cancels the whole iteration, not just the page
237
+ in flight:
238
+
239
+ ```typescript
240
+ const controller = new AbortController()
241
+ setTimeout(() => controller.abort(), 30_000)
242
+
243
+ for await (const meter of client.meters.listAll(undefined, {
244
+ signal: controller.signal,
245
+ })) {
246
+ console.log(meter.key)
247
+ }
248
+ ```
249
+
250
+ Iteration stops after the server’s last page — an empty or short-of-`size`
251
+ page for a page-number resource, or a response with no next cursor for a
252
+ cursor resource. A misbehaving server that never signals the end of the
253
+ list fails fast instead of looping forever: after 10,000 pages the
254
+ iterable throws `PaginationLimitExceededError`.
255
+
115
256
  ## Available Resources and Operations
116
257
 
117
258
  Operations are grouped by resource and exposed as methods on the client.
@@ -138,55 +279,48 @@ The full call path, HTTP route, and a short description are listed below.
138
279
 
139
280
  ### Customers
140
281
 
141
- | Method | HTTP | Description |
142
- | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
143
- | `client.customers.create` | `POST /openmeter/customers` | |
144
- | `client.customers.get` | `GET /openmeter/customers/{customerId}` | |
145
- | `client.customers.list` | `GET /openmeter/customers` | |
146
- | `client.customers.upsert` | `PUT /openmeter/customers/{customerId}` | |
147
- | `client.customers.delete` | `DELETE /openmeter/customers/{customerId}` | |
148
- | `client.customers.billing.get` | `GET /openmeter/customers/{customerId}/billing` | |
149
- | `client.customers.billing.update` | `PUT /openmeter/customers/{customerId}/billing` | |
150
- | `client.customers.billing.updateAppData` | `PUT /openmeter/customers/{customerId}/billing/app-data` | |
151
- | `client.customers.billing.createStripeCheckoutSession` | `POST /openmeter/customers/{customerId}/billing/stripe/checkout-sessions` | Create a [Stripe Checkout Session](https://docs.stripe.com/payments/checkout) for the customer. Creates a Checkout Session for collecting payment method information from customers. The session operates in "setup" mode, which collects payment details without charging the customer immediately. The collected payment method can be used for future subscription billing. For hosted checkout sessions, redirect customers to the returned URL. For embedded sessions, use the client_secret to initialize Stripe.js in your application. |
152
- | `client.customers.billing.createStripePortalSession` | `POST /openmeter/customers/{customerId}/billing/stripe/portal-sessions` | Create Stripe Customer Portal Session. Useful to redirect the customer to the Stripe Customer Portal to manage their payment methods, change their billing address and access their invoice history. Only returns URL if the customer billing profile is linked to a stripe app and customer. |
153
- | `client.customers.credits.grants.create` | `POST /openmeter/customers/{customerId}/credits/grants` | Create a new credit grant. A credit grant represents an allocation of prepaid credits to a customer. |
154
- | `client.customers.credits.grants.get` | `GET /openmeter/customers/{customerId}/credits/grants/{creditGrantId}` | Get a credit grant. |
155
- | `client.customers.credits.grants.list` | `GET /openmeter/customers/{customerId}/credits/grants` | List credit grants. |
156
- | `client.customers.credits.balance.get` | `GET /openmeter/customers/{customerId}/credits/balance` | Get a credit balance. |
157
- | `client.customers.credits.adjustments.create` | `POST /openmeter/customers/{customerId}/credits/adjustments` | A credit adjustment can be used to make manual adjustments to a customer's credit balance. Supported use-cases: - Usage correction |
158
- | `client.customers.credits.grants.updateExternalSettlement` | `POST /openmeter/customers/{customerId}/credits/grants/{creditGrantId}/settlement/external` | Update the payment settlement status of an externally funded credit grant. Use this endpoint to synchronize the payment state of an external payment with the system so that revenue recognition and credit availability work as expected. |
159
- | `client.customers.credits.transactions.list` | `GET /openmeter/customers/{customerId}/credits/transactions` | List credit transactions for a customer. Returns an immutable, chronological record of credit movements: funded credits and consumed credits. Transactions are returned in reverse chronological order by default. |
160
- | `client.customers.charges.list` | `GET /openmeter/customers/{customerId}/charges` | List customer charges. Returns the customer's charges that are represented as either flat fee or usage-based charges. |
161
- | `client.customers.charges.create` | `POST /openmeter/customers/{customerId}/charges` | Create customer charge. |
282
+ | Method | HTTP | Description |
283
+ | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
284
+ | `client.customers.create` | `POST /openmeter/customers` | Create customer |
285
+ | `client.customers.get` | `GET /openmeter/customers/{customerId}` | Get customer |
286
+ | `client.customers.list` | `GET /openmeter/customers` | List customers |
287
+ | `client.customers.upsert` | `PUT /openmeter/customers/{customerId}` | Upsert customer |
288
+ | `client.customers.delete` | `DELETE /openmeter/customers/{customerId}` | Delete customer |
289
+ | `client.customers.billing.get` | `GET /openmeter/customers/{customerId}/billing` | Get customer billing data |
290
+ | `client.customers.billing.update` | `PUT /openmeter/customers/{customerId}/billing` | Update customer billing data |
291
+ | `client.customers.billing.updateAppData` | `PUT /openmeter/customers/{customerId}/billing/app-data` | Update customer billing app data |
292
+ | `client.customers.billing.createStripeCheckoutSession` | `POST /openmeter/customers/{customerId}/billing/stripe/checkout-sessions` | Create a [Stripe Checkout Session](https://docs.stripe.com/payments/checkout) for the customer. Creates a Checkout Session for collecting payment method information from customers. The session operates in "setup" mode, which collects payment details without charging the customer immediately. The collected payment method can be used for future subscription billing. For hosted checkout sessions, redirect customers to the returned URL. For embedded sessions, use the client_secret to initialize Stripe.js in your application. |
293
+ | `client.customers.billing.createStripePortalSession` | `POST /openmeter/customers/{customerId}/billing/stripe/portal-sessions` | Create Stripe Customer Portal Session. Useful to redirect the customer to the Stripe Customer Portal to manage their payment methods, change their billing address and access their invoice history. Only returns URL if the customer billing profile is linked to a stripe app and customer. |
294
+ | `client.customers.credits.grants.create` | `POST /openmeter/customers/{customerId}/credits/grants` | Create a new credit grant. A credit grant represents an allocation of prepaid credits to a customer. |
295
+ | `client.customers.credits.grants.get` | `GET /openmeter/customers/{customerId}/credits/grants/{creditGrantId}` | Get a credit grant. |
296
+ | `client.customers.credits.grants.list` | `GET /openmeter/customers/{customerId}/credits/grants` | List credit grants. |
297
+ | `client.customers.credits.balance.get` | `GET /openmeter/customers/{customerId}/credits/balance` | Get a credit balance. |
298
+ | `client.customers.credits.adjustments.create` | `POST /openmeter/customers/{customerId}/credits/adjustments` | A credit adjustment can be used to make manual adjustments to a customer's credit balance. Supported use-cases: - Usage correction |
299
+ | `client.customers.credits.grants.void` | `POST /openmeter/customers/{customerId}/credits/grants/{creditGrantId}/void` | Void a credit grant, forfeiting the remaining unused balance. Voiding is a forward-looking, irreversible operation. Credits already consumed by usage remain unaffected — only the remaining balance is forfeited. The grant reads as `voided` status afterwards. Payment state is not adjusted when `payment_adjustment` is `none`, so invoice-backed or externally collected payments may still collect the original amount. Only `active` grants can be voided; voiding a pending, expired, or fully consumed grant returns a conflict. Retrying a successful void is an idempotent success. |
300
+ | `client.customers.credits.grants.updateExternalSettlement` | `POST /openmeter/customers/{customerId}/credits/grants/{creditGrantId}/settlement/external` | Update the payment settlement status of an externally funded credit grant. Use this endpoint to synchronize the payment state of an external payment with the system so that revenue recognition and credit availability work as expected. |
301
+ | `client.customers.credits.transactions.list` | `GET /openmeter/customers/{customerId}/credits/transactions` | List credit transactions for a customer. Returns an immutable, chronological record of credit movements: funded credits and consumed credits. Transactions are returned in reverse chronological order by default. |
302
+ | `client.customers.charges.list` | `GET /openmeter/customers/{customerId}/charges` | List customer charges. Returns the customer's charges that are represented as either flat fee or usage-based charges. |
303
+ | `client.customers.charges.create` | `POST /openmeter/customers/{customerId}/charges` | Create customer charge. |
162
304
 
163
305
  ### Entitlements
164
306
 
165
- | Method | HTTP | Description |
166
- | ---------------------------------------- | ---------------------------------------------------------- | ----------- |
167
- | `client.entitlements.listCustomerAccess` | `GET /openmeter/customers/{customerId}/entitlement-access` | |
307
+ | Method | HTTP | Description |
308
+ | ---------------------------------------- | ---------------------------------------------------------- | -------------------------------- |
309
+ | `client.entitlements.listCustomerAccess` | `GET /openmeter/customers/{customerId}/entitlement-access` | List customer entitlement access |
168
310
 
169
311
  ### Subscriptions
170
312
 
171
313
  | Method | HTTP | Description |
172
314
  | -------------------------------------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
173
- | `client.subscriptions.create` | `POST /openmeter/subscriptions` | |
174
- | `client.subscriptions.list` | `GET /openmeter/subscriptions` | |
175
- | `client.subscriptions.get` | `GET /openmeter/subscriptions/{subscriptionId}` | |
315
+ | `client.subscriptions.create` | `POST /openmeter/subscriptions` | Create subscription |
316
+ | `client.subscriptions.list` | `GET /openmeter/subscriptions` | List subscriptions |
317
+ | `client.subscriptions.get` | `GET /openmeter/subscriptions/{subscriptionId}` | Get subscription |
176
318
  | `client.subscriptions.cancel` | `POST /openmeter/subscriptions/{subscriptionId}/cancel` | Cancels the subscription. Will result in a scheduling conflict if there are other subscriptions scheduled to start after the cancelation time. |
177
319
  | `client.subscriptions.unscheduleCancelation` | `POST /openmeter/subscriptions/{subscriptionId}/unschedule-cancelation` | Unschedules the subscription cancelation. |
178
320
  | `client.subscriptions.change` | `POST /openmeter/subscriptions/{subscriptionId}/change` | Closes a running subscription and starts a new one according to the specification. Can be used for upgrades, downgrades, and plan changes. |
179
- | `client.subscriptions.createAddon` | `POST /openmeter/subscriptions/{subscriptionId}/addons` | Add add-on to a subscription. |
180
321
  | `client.subscriptions.listAddons` | `GET /openmeter/subscriptions/{subscriptionId}/addons` | List the add-ons of a subscription. |
181
322
  | `client.subscriptions.getAddon` | `GET /openmeter/subscriptions/{subscriptionId}/addons/{subscriptionAddonId}` | Get an add-on association for a subscription. |
182
323
 
183
- ### Apps
184
-
185
- | Method | HTTP | Description |
186
- | ------------------ | ----------------------------- | --------------------- |
187
- | `client.apps.list` | `GET /openmeter/apps` | List installed apps. |
188
- | `client.apps.get` | `GET /openmeter/apps/{appId}` | Get an installed app. |
189
-
190
324
  ### Billing
191
325
 
192
326
  | Method | HTTP | Description |
@@ -197,33 +331,15 @@ The full call path, HTTP route, and a short description are listed below.
197
331
  | `client.billing.updateProfile` | `PUT /openmeter/profiles/{id}` | Update a billing profile. |
198
332
  | `client.billing.deleteProfile` | `DELETE /openmeter/profiles/{id}` | Delete a billing profile. Only such billing profiles can be deleted that are: - not the default profile - not pinned to any customer using customer overrides - only have finalized invoices |
199
333
 
200
- ### Invoices
201
-
202
- | Method | HTTP | Description |
203
- | ------------------------ | ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
204
- | `client.invoices.list` | `GET /openmeter/billing/invoices` | List billing invoices. Returns a page of invoices. Gathering invoices are never included. Use `filter` to narrow by status, customer, dates, or service period start. Use `sort` to control ordering. |
205
- | `client.invoices.get` | `GET /openmeter/billing/invoices/{invoiceId}` | Get a billing invoice by ID. Returns the full invoice resource including line items, status details, totals, and workflow configuration snapshot. |
206
- | `client.invoices.update` | `PUT /openmeter/billing/invoices/{invoiceId}` | Update a billing invoice. Only the mutable fields of the invoice can be edited: description, labels, supplier, customer, workflow settings, and top-level lines. Top-level lines are matched by `id`; lines without an `id` are created, and existing lines omitted from `lines` are deleted. Detailed (child) lines are always computed and cannot be edited directly. Only invoices in draft status can be updated. |
207
- | `client.invoices.delete` | `DELETE /openmeter/billing/invoices/{invoiceId}` | Delete a billing invoice. Only standard invoices in draft status can be deleted. Deleting an invoice will also delete all associated line items and workflow configuration. |
208
-
209
334
  ### Tax
210
335
 
211
- | Method | HTTP | Description |
212
- | ----------------------- | ----------------------------------------- | ----------- |
213
- | `client.tax.createCode` | `POST /openmeter/tax-codes` | |
214
- | `client.tax.getCode` | `GET /openmeter/tax-codes/{taxCodeId}` | |
215
- | `client.tax.listCodes` | `GET /openmeter/tax-codes` | |
216
- | `client.tax.upsertCode` | `PUT /openmeter/tax-codes/{taxCodeId}` | |
217
- | `client.tax.deleteCode` | `DELETE /openmeter/tax-codes/{taxCodeId}` | |
218
-
219
- ### Currencies
220
-
221
- | Method | HTTP | Description |
222
- | ---------------------------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
223
- | `client.currencies.list` | `GET /openmeter/currencies` | List currencies supported by the billing system. |
224
- | `client.currencies.createCustomCurrency` | `POST /openmeter/currencies/custom` | Create a custom currency. This operation allows defining your own custom currency for billing purposes. |
225
- | `client.currencies.listCostBases` | `GET /openmeter/currencies/custom/{currencyId}/cost-bases` | List cost bases for a currency. For custom currencies, there can be multiple cost bases with different `effective_from` dates. |
226
- | `client.currencies.createCostBasis` | `POST /openmeter/currencies/custom/{currencyId}/cost-bases` | Create a cost basis for a currency. |
336
+ | Method | HTTP | Description |
337
+ | ----------------------- | ----------------------------------------- | --------------- |
338
+ | `client.tax.createCode` | `POST /openmeter/tax-codes` | Create tax code |
339
+ | `client.tax.getCode` | `GET /openmeter/tax-codes/{taxCodeId}` | Get tax code |
340
+ | `client.tax.listCodes` | `GET /openmeter/tax-codes` | List tax codes |
341
+ | `client.tax.upsertCode` | `PUT /openmeter/tax-codes/{taxCodeId}` | Upsert tax code |
342
+ | `client.tax.deleteCode` | `DELETE /openmeter/tax-codes/{taxCodeId}` | Delete tax code |
227
343
 
228
344
  ### Features
229
345
 
@@ -282,21 +398,139 @@ The full call path, HTTP route, and a short description are listed below.
282
398
 
283
399
  ### Defaults
284
400
 
285
- | Method | HTTP | Description |
286
- | -------------------------------------------- | ----------------------------------- | ----------- |
287
- | `client.defaults.getOrganizationTaxCodes` | `GET /openmeter/defaults/tax-codes` | |
288
- | `client.defaults.updateOrganizationTaxCodes` | `PUT /openmeter/defaults/tax-codes` | |
401
+ | Method | HTTP | Description |
402
+ | -------------------------------------------- | ----------------------------------- | ------------------------------------- |
403
+ | `client.defaults.getOrganizationTaxCodes` | `GET /openmeter/defaults/tax-codes` | Get organization default tax codes |
404
+ | `client.defaults.updateOrganizationTaxCodes` | `PUT /openmeter/defaults/tax-codes` | Update organization default tax codes |
405
+
406
+ ## Internal Operations
407
+
408
+ Operations marked internal in the API definition are exposed under
409
+ `client.internal.*`, quarantined from the customer surface. They are not
410
+ intended for customer use: they may require additional permissions, and
411
+ they can change or be removed without notice or semver consideration.
412
+
413
+ ### Internal Subscriptions
414
+
415
+ | Method | HTTP | Description |
416
+ | ------------------------------------------- | ------------------------------------------------------- | ----------------------------- |
417
+ | `client.internal.subscriptions.createAddon` | `POST /openmeter/subscriptions/{subscriptionId}/addons` | Add add-on to a subscription. |
418
+
419
+ ### Internal Apps
420
+
421
+ | Method | HTTP | Description |
422
+ | ------------------------------------- | -------------------------------------- | -------------------------------- |
423
+ | `client.internal.apps.list` | `GET /openmeter/apps` | List installed apps. |
424
+ | `client.internal.apps.get` | `GET /openmeter/apps/{appId}` | Get an installed app. |
425
+ | `client.internal.apps.uninstall` | `DELETE /openmeter/apps/{appId}` | Uninstall an app by ID. |
426
+ | `client.internal.apps.update` | `PUT /openmeter/apps/{appId}` | Update an installed app. |
427
+ | `client.internal.apps.listCatalog` | `GET /openmeter/app-catalog` | List available apps. |
428
+ | `client.internal.apps.getCatalogItem` | `GET /openmeter/app-catalog/{appType}` | Get an app catalog item by type. |
429
+ | `client.internal.apps.install` | `POST /openmeter/app-catalog/install` | Install an app from the catalog. |
430
+
431
+ ### Internal Invoices
432
+
433
+ | Method | HTTP | Description |
434
+ | --------------------------------------------- | ------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
435
+ | `client.internal.invoices.list` | `GET /openmeter/billing/invoices` | List billing invoices. Returns a page of invoices. Gathering invoices are never included. Use `filter` to narrow by status, customer, dates, or service period start. Use `sort` to control ordering. |
436
+ | `client.internal.invoices.get` | `GET /openmeter/billing/invoices/{invoiceId}` | Get a billing invoice by ID. Returns the full invoice resource including line items, status details, totals, and workflow configuration snapshot. |
437
+ | `client.internal.invoices.update` | `PUT /openmeter/billing/invoices/{invoiceId}` | Update a billing invoice. Only the mutable fields of the invoice can be edited: description, labels, supplier, customer, workflow settings, and top-level lines. Top-level lines are matched by `id`; lines without an `id` are created, and existing lines omitted from `lines` are deleted. Detailed (child) lines are always computed and cannot be edited directly. Only invoices in draft status can be updated. |
438
+ | `client.internal.invoices.delete` | `DELETE /openmeter/billing/invoices/{invoiceId}` | Delete a billing invoice. Only standard invoices in draft status can be deleted. Deleting an invoice will also delete all associated line items and workflow configuration. |
439
+ | `client.internal.invoices.advance` | `POST /openmeter/billing/invoices/{invoiceId}/advance` | Advance a billing invoice. Advances the invoice to the next workflow state. The next state is determined by the invoice's current status and workflow configuration. Only invoices in draft or issued status can be advanced. |
440
+ | `client.internal.invoices.approve` | `POST /openmeter/billing/invoices/{invoiceId}/approve` | Approve a billing invoice. This call instantly sends the invoice to the customer using the configured billing profile app. This call is valid in two invoice statuses: - draft: the invoice will be sent to the customer, the invoice state becomes issued - manual_approval_needed: the invoice will be sent to the customer, the invoice state becomes issued |
441
+ | `client.internal.invoices.retry` | `POST /openmeter/billing/invoices/{invoiceId}/retry` | Retry sending a billing invoice. Retry advancing the invoice after a failed attempt. The action can be called when the invoice's statusDetails' actions field contain the "retry" action. |
442
+ | `client.internal.invoices.snapshotQuantities` | `POST /openmeter/billing/invoices/{invoiceId}/snapshot-quantities` | Snapshot quantities for usage-based line items. This call will snapshot the quantities for all usage based line items in the invoice. This call is only valid in draft.waiting_for_collection status, where the collection period can be skipped using this action. |
443
+
444
+ ### Internal Currencies
445
+
446
+ | Method | HTTP | Description |
447
+ | ------------------------------------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
448
+ | `client.internal.currencies.list` | `GET /openmeter/currencies` | List currencies supported by the billing system. |
449
+ | `client.internal.currencies.createCustomCurrency` | `POST /openmeter/currencies/custom` | Create a custom currency. This operation allows defining your own custom currency for billing purposes. |
450
+ | `client.internal.currencies.getCustomCurrency` | `GET /openmeter/currencies/custom/{currencyId}` | Get a custom currency. |
451
+ | `client.internal.currencies.listCostBases` | `GET /openmeter/currencies/custom/{currencyId}/cost-bases` | List cost bases for a currency. For custom currencies, there can be multiple cost bases with different `effective_from` dates. |
452
+ | `client.internal.currencies.createCostBasis` | `POST /openmeter/currencies/custom/{currencyId}/cost-bases` | Create a cost basis for a currency. |
453
+
454
+ ### Internal Governance
455
+
456
+ | Method | HTTP | Description |
457
+ | ---------------------------------------- | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
458
+ | `client.internal.governance.queryAccess` | `POST /openmeter/governance/query` | Query feature access for a list of customers. The endpoint resolves each provided identifier to a customer and returns the access status for the requested features, plus optional credit balance availability. _Designed to be called on a fixed refresh interval and the query response is intended to be cached._ |
459
+
460
+ ## Runtime Validation (validate option)
461
+
462
+ `validate` is off by default. The SDK's normal request/response mapping
463
+ only renames keys and converts dates — it never rejects a payload — so
464
+ an additive server-side change (a new response field, a new enum value)
465
+ never breaks a client running an older SDK version.
466
+
467
+ Set `validate: true` to additionally check the wire payload — the
468
+ request body after mapping to snake_case, and the raw response before
469
+ mapping back — against the generated `…Wire` schemas. Those schemas are
470
+ strict: an unknown field or an unrecognized enum value fails validation
471
+ instead of being silently accepted. That makes `validate` a tool for
472
+ catching SDK/server contract drift in development or CI, not something
473
+ to run in production, where forward compatibility with additive server
474
+ changes matters more than strict rejection.
475
+
476
+ ```typescript
477
+ import { OpenMeter, ValidationError } from '@openmeter/client'
289
478
 
290
- ### Governance
479
+ const client = new OpenMeter({
480
+ baseUrl: 'https://openmeter.cloud/api/v3',
481
+ apiKey: process.env.OPENMETER_API_KEY,
482
+ validate: true,
483
+ })
484
+
485
+ try {
486
+ await client.meters.get({ meterId: 'meter_123' })
487
+ } catch (error) {
488
+ if (error instanceof ValidationError) {
489
+ console.error(error.issues)
490
+ }
491
+ }
492
+ ```
493
+
494
+ The standalone functions surface the same failure as a `Result` instead
495
+ of throwing — check `result.error instanceof ValidationError`.
496
+
497
+ ## Zod Schemas (./zod export)
498
+
499
+ `@openmeter/client/zod` exports every model twice: once shaped like the
500
+ SDK's public surface (camelCase keys, `Date` for date-time fields — the
501
+ same shape `meter.eventType`/`meter.createdAt` have in TypeScript) and
502
+ once as a strict `…Wire` schema shaped like the literal JSON the server
503
+ sends and accepts (snake_case keys, RFC 3339 date-time strings, unknown
504
+ fields rejected) — the same `…Wire` schemas the `validate` option checks
505
+ internally.
506
+
507
+ Use the public schemas to validate a payload the SDK did not produce —
508
+ a webhook body, a cached record, a test fixture — before trusting its
509
+ shape:
510
+
511
+ ```typescript
512
+ import * as schemas from '@openmeter/client/zod'
513
+
514
+ const parsed = schemas.meter.safeParse({
515
+ id: '01HZY3W6VXQK6H3NPC6DFA0PJT',
516
+ name: 'Tokens',
517
+ key: 'tokens',
518
+ aggregation: 'sum',
519
+ eventType: 'request',
520
+ createdAt: new Date(),
521
+ updatedAt: new Date(),
522
+ })
291
523
 
292
- | Method | HTTP | Description |
293
- | ------------------------------- | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
294
- | `client.governance.queryAccess` | `POST /openmeter/governance/query` | Query feature access for a list of customers. The endpoint resolves each provided identifier to a customer and returns the access status for the requested features, plus optional credit balance availability. _Designed to be called on a fixed refresh interval and the query response is intended to be cached._ |
524
+ if (parsed.success) {
525
+ console.log(parsed.data.eventType)
526
+ }
527
+ ```
295
528
 
296
529
  ## Error Handling
297
530
 
298
- A non-2xx response rejects with an `HTTPError` carrying the problem-details
299
- fields (`status`, `type`, `title`, `url`) from the response.
531
+ A non-2xx response rejects with an `HTTPError` (`error.name === 'HTTPError'`)
532
+ carrying the problem-details fields (`status`, `type`, `title`, `url`)
533
+ from the response.
300
534
 
301
535
  ```typescript
302
536
  import { OpenMeter, HTTPError } from '@openmeter/client'
@@ -315,6 +549,46 @@ try {
315
549
  }
316
550
  ```
317
551
 
552
+ `error.retryAfter` is the delta-seconds form of a numeric `Retry-After`
553
+ header (the common case on 429 and 503 responses) and `undefined`
554
+ otherwise. A 400 Bad Request additionally carries a typed
555
+ `error.invalidParameters` array describing which fields failed
556
+ validation; `error.getField(key)` is an untyped escape hatch for any
557
+ other problem-details extension member:
558
+
559
+ ```typescript
560
+ import { OpenMeter, HTTPError } from '@openmeter/client'
561
+
562
+ const client = new OpenMeter({
563
+ baseUrl: 'https://openmeter.cloud/api/v3',
564
+ apiKey: process.env.OPENMETER_API_KEY,
565
+ })
566
+
567
+ try {
568
+ await client.meters.create({
569
+ name: 'Tokens',
570
+ key: 'tokens',
571
+ aggregation: 'sum',
572
+ eventType: 'request',
573
+ })
574
+ } catch (error) {
575
+ if (error instanceof HTTPError && error.status === 400) {
576
+ for (const param of error.invalidParameters ?? []) {
577
+ console.error(param)
578
+ }
579
+ }
580
+ }
581
+ ```
582
+
583
+ The SDK's other typed errors are `ValidationError` (see
584
+ [Runtime Validation (validate option)](#runtime-validation-validate-option)), `UnsafeIntegerError`
585
+ (an `int64`/`uint64` value exceeds what JSON can represent without
586
+ precision loss), `DepthLimitExceededError` (response data nested deeper
587
+ than the mapper's safety limit), and `PaginationLimitExceededError` (an
588
+ [Pagination](#pagination) iterable exceeded
589
+ its page-count safety limit) — each distinguished the same way, by
590
+ `instanceof` or by `.name`.
591
+
318
592
  ## Standalone Functions
319
593
 
320
594
  Every method is also available as a standalone, tree-shakeable function
@@ -335,3 +609,18 @@ if (result.ok) {
335
609
  console.error(result.error)
336
610
  }
337
611
  ```
612
+
613
+ `ok`, `err`, and `unwrap` — the helpers `Result` is built from — are
614
+ exported too, so a func call can be unwrapped back into a throwing call
615
+ where that is more convenient:
616
+
617
+ ```typescript
618
+ import { Client, funcs, unwrap } from '@openmeter/client'
619
+
620
+ const client = new Client({
621
+ baseUrl: 'https://openmeter.cloud/api/v3',
622
+ apiKey: process.env.OPENMETER_API_KEY,
623
+ })
624
+
625
+ const meters = unwrap(await funcs.listMeters(client))
626
+ ```
package/dist/core.d.ts CHANGED
@@ -7,4 +7,3 @@ export declare class Client {
7
7
  }
8
8
  export declare function http(client: Client): HTTPClient;
9
9
  export type { HTTPClient };
10
- //# sourceMappingURL=core.d.ts.map