@openmeter/client 1.0.0-beta-4d26c6d3c7fe → 1.0.0-beta-e7a04be10ed8

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 +316 -55
  3. package/dist/core.d.ts +0 -1
  4. package/dist/core.js +8 -1
  5. package/dist/funcs/addons.d.ts +49 -1
  6. package/dist/funcs/addons.js +50 -1
  7. package/dist/funcs/apps.d.ts +14 -1
  8. package/dist/funcs/apps.js +15 -1
  9. package/dist/funcs/billing.d.ts +46 -1
  10. package/dist/funcs/billing.js +47 -1
  11. package/dist/funcs/currencies.d.ts +30 -1
  12. package/dist/funcs/currencies.js +31 -1
  13. package/dist/funcs/customers.d.ts +148 -1
  14. package/dist/funcs/customers.js +149 -1
  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 +6 -1
  19. package/dist/funcs/events.d.ts +14 -1
  20. package/dist/funcs/events.js +15 -1
  21. package/dist/funcs/features.d.ts +42 -1
  22. package/dist/funcs/features.js +43 -1
  23. package/dist/funcs/index.d.ts +0 -3
  24. package/dist/funcs/index.js +1 -3
  25. package/dist/funcs/llmCost.d.ts +36 -1
  26. package/dist/funcs/llmCost.js +37 -1
  27. package/dist/funcs/meters.d.ts +53 -1
  28. package/dist/funcs/meters.js +54 -1
  29. package/dist/funcs/planAddons.d.ts +35 -1
  30. package/dist/funcs/planAddons.js +36 -1
  31. package/dist/funcs/plans.d.ts +49 -1
  32. package/dist/funcs/plans.js +50 -1
  33. package/dist/funcs/subscriptions.d.ts +59 -1
  34. package/dist/funcs/subscriptions.js +60 -1
  35. package/dist/funcs/tax.d.ts +25 -1
  36. package/dist/funcs/tax.js +26 -1
  37. package/dist/index.d.ts +4 -8
  38. package/dist/index.js +4 -5
  39. package/dist/lib/config.d.ts +0 -1
  40. package/dist/lib/config.js +1 -1
  41. package/dist/lib/encodings.d.ts +0 -1
  42. package/dist/lib/encodings.js +1 -1
  43. package/dist/lib/paginate.d.ts +56 -0
  44. package/dist/lib/paginate.js +60 -0
  45. package/dist/lib/request.d.ts +0 -1
  46. package/dist/lib/request.js +1 -1
  47. package/dist/lib/to-error.d.ts +0 -1
  48. package/dist/lib/to-error.js +1 -1
  49. package/dist/lib/types.d.ts +0 -1
  50. package/dist/lib/types.js +1 -1
  51. package/dist/lib/version.d.ts +1 -0
  52. package/dist/lib/version.js +5 -0
  53. package/dist/lib/wire.d.ts +3 -1
  54. package/dist/lib/wire.js +93 -4
  55. package/dist/models/errors.d.ts +13 -2
  56. package/dist/models/errors.js +31 -4
  57. package/dist/models/operations/addons.d.ts +0 -1
  58. package/dist/models/operations/addons.js +1 -1
  59. package/dist/models/operations/apps.d.ts +2 -5
  60. package/dist/models/operations/apps.js +1 -1
  61. package/dist/models/operations/billing.d.ts +0 -1
  62. package/dist/models/operations/billing.js +1 -1
  63. package/dist/models/operations/currencies.d.ts +0 -1
  64. package/dist/models/operations/currencies.js +1 -1
  65. package/dist/models/operations/customers.d.ts +3 -6
  66. package/dist/models/operations/customers.js +1 -1
  67. package/dist/models/operations/defaults.d.ts +0 -1
  68. package/dist/models/operations/defaults.js +1 -1
  69. package/dist/models/operations/entitlements.d.ts +0 -1
  70. package/dist/models/operations/entitlements.js +1 -1
  71. package/dist/models/operations/events.d.ts +0 -1
  72. package/dist/models/operations/events.js +1 -1
  73. package/dist/models/operations/features.d.ts +0 -1
  74. package/dist/models/operations/features.js +1 -1
  75. package/dist/models/operations/llmCost.d.ts +0 -1
  76. package/dist/models/operations/llmCost.js +1 -1
  77. package/dist/models/operations/meters.d.ts +0 -1
  78. package/dist/models/operations/meters.js +1 -1
  79. package/dist/models/operations/planAddons.d.ts +0 -1
  80. package/dist/models/operations/planAddons.js +1 -1
  81. package/dist/models/operations/plans.d.ts +0 -1
  82. package/dist/models/operations/plans.js +1 -1
  83. package/dist/models/operations/subscriptions.d.ts +0 -1
  84. package/dist/models/operations/subscriptions.js +1 -1
  85. package/dist/models/operations/tax.d.ts +0 -1
  86. package/dist/models/operations/tax.js +1 -1
  87. package/dist/models/schemas.d.ts +4453 -6950
  88. package/dist/models/schemas.js +1 -73
  89. package/dist/models/types.d.ts +381 -566
  90. package/dist/models/types.js +1 -1
  91. package/dist/sdk/addons.d.ts +60 -1
  92. package/dist/sdk/addons.js +63 -1
  93. package/dist/sdk/apps.d.ts +25 -1
  94. package/dist/sdk/apps.js +28 -1
  95. package/dist/sdk/billing.d.ts +57 -1
  96. package/dist/sdk/billing.js +60 -1
  97. package/dist/sdk/customers.d.ts +194 -1
  98. package/dist/sdk/customers.js +203 -1
  99. package/dist/sdk/defaults.d.ts +10 -1
  100. package/dist/sdk/defaults.js +11 -1
  101. package/dist/sdk/entitlements.d.ts +5 -1
  102. package/dist/sdk/entitlements.js +6 -1
  103. package/dist/sdk/events.d.ts +25 -1
  104. package/dist/sdk/events.js +28 -1
  105. package/dist/sdk/features.d.ts +53 -1
  106. package/dist/sdk/features.js +56 -1
  107. package/dist/sdk/internal.d.ts +89 -0
  108. package/dist/sdk/internal.js +113 -0
  109. package/dist/sdk/llmCost.d.ts +57 -1
  110. package/dist/sdk/llmCost.js +62 -1
  111. package/dist/sdk/meters.d.ts +64 -1
  112. package/dist/sdk/meters.js +67 -1
  113. package/dist/sdk/planAddons.d.ts +46 -1
  114. package/dist/sdk/planAddons.js +49 -1
  115. package/dist/sdk/plans.d.ts +60 -1
  116. package/dist/sdk/plans.js +63 -1
  117. package/dist/sdk/sdk.d.ts +9 -10
  118. package/dist/sdk/sdk.js +11 -15
  119. package/dist/sdk/subscriptions.d.ts +72 -3
  120. package/dist/sdk/subscriptions.js +77 -5
  121. package/dist/sdk/tax.d.ts +34 -1
  122. package/dist/sdk/tax.js +37 -1
  123. package/package.json +28 -4
  124. package/dist/funcs/governance.d.ts +0 -5
  125. package/dist/funcs/governance.js +0 -34
  126. package/dist/funcs/invoices.d.ts +0 -8
  127. package/dist/funcs/invoices.js +0 -81
  128. package/dist/models/operations/governance.d.ts +0 -10
  129. package/dist/models/operations/governance.js +0 -2
  130. package/dist/models/operations/invoices.d.ts +0 -48
  131. package/dist/models/operations/invoices.js +0 -2
  132. package/dist/sdk/currencies.d.ts +0 -12
  133. package/dist/sdk/currencies.js +0 -21
  134. package/dist/sdk/governance.d.ts +0 -9
  135. package/dist/sdk/governance.js +0 -12
  136. package/dist/sdk/invoices.d.ts +0 -12
  137. package/dist/sdk/invoices.js +0 -21
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,7 +16,9 @@ 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)
@@ -24,16 +27,18 @@ TypeSpec definitions and ships fully-typed request and response models.
24
27
  - [Subscriptions](#subscriptions)
25
28
  - [Apps](#apps)
26
29
  - [Billing](#billing)
27
- - [Invoices](#invoices)
28
30
  - [Tax](#tax)
29
- - [Currencies](#currencies)
30
31
  - [Features](#features)
31
32
  - [LLMCost](#llmcost)
32
33
  - [Plans](#plans)
33
34
  - [Addons](#addons)
34
35
  - [PlanAddons](#planaddons)
35
36
  - [Defaults](#defaults)
36
- - [Governance](#governance)
37
+ - [Internal Operations](#internal-operations)
38
+ - [Internal Subscriptions](#internal-subscriptions)
39
+ - [Internal Currencies](#internal-currencies)
40
+ - [Runtime Validation (validate option)](#runtime-validation-validate-option)
41
+ - [Zod Schemas (./zod export)](#zod-schemas-zod-export)
37
42
  - [Error Handling](#error-handling)
38
43
  - [Standalone Functions](#standalone-functions)
39
44
 
@@ -80,6 +85,76 @@ const client = new OpenMeter({
80
85
  The `apiKey` may also be a function returning a `string` or
81
86
  `Promise<string>`, so tokens can be refreshed per request.
82
87
 
88
+ ## Configuration
89
+
90
+ `SDKOptions` extends [ky](https://github.com/sindresorhus/ky)'s
91
+ `Options`, so every transport setting ky supports is a top-level client
92
+ option: retry policy, per-attempt timeout (ky defaults to 10 seconds),
93
+ lifecycle hooks, a custom `fetch`, and so on.
94
+
95
+ ```typescript
96
+ import { OpenMeter } from '@openmeter/client'
97
+
98
+ const client = new OpenMeter({
99
+ baseUrl: 'https://openmeter.cloud/api/v3',
100
+ apiKey: process.env.OPENMETER_API_KEY,
101
+ timeout: 30_000,
102
+ hooks: {
103
+ beforeRequest: [
104
+ ({ request }) => {
105
+ console.log(`-> ${request.method} ${request.url}`)
106
+ },
107
+ ],
108
+ },
109
+ fetch: async (input, init) => {
110
+ const start = Date.now()
111
+ const response = await fetch(input, init)
112
+ console.log(`${response.status} in ${Date.now() - start}ms`)
113
+ return response
114
+ },
115
+ })
116
+ ```
117
+
118
+ ky only retries the idempotent methods by default — `get`, `put`,
119
+ `head`, `delete`, `options`, `trace` — never `post`. That means a
120
+ dropped `client.events.ingest` call is not retried on a network error
121
+ or a 5xx response unless you opt in explicitly:
122
+
123
+ ```typescript
124
+ import { OpenMeter } from '@openmeter/client'
125
+
126
+ const client = new OpenMeter({
127
+ baseUrl: 'https://openmeter.cloud/api/v3',
128
+ apiKey: process.env.OPENMETER_API_KEY,
129
+ retry: { limit: 3, methods: ['get', 'put', 'head', 'delete', 'post'] },
130
+ })
131
+ ```
132
+
133
+ This is safe specifically for event ingestion: the event `id` is its
134
+ deduplication key server-side, so resending the same event on retry is
135
+ a no-op rather than a duplicate.
136
+
137
+ Every method also takes a per-request `RequestOptions` as its second
138
+ argument — a curated subset of ky's options (`signal`, `headers`,
139
+ `timeout`, `retry`) applied to that call only:
140
+
141
+ ```typescript
142
+ import { OpenMeter } from '@openmeter/client'
143
+
144
+ const client = new OpenMeter({
145
+ baseUrl: 'https://openmeter.cloud/api/v3',
146
+ apiKey: process.env.OPENMETER_API_KEY,
147
+ })
148
+
149
+ const controller = new AbortController()
150
+ setTimeout(() => controller.abort(), 5_000)
151
+
152
+ const meters = await client.meters.list(undefined, {
153
+ signal: controller.signal,
154
+ headers: { 'X-Request-Id': 'batch-42' },
155
+ })
156
+ ```
157
+
83
158
  ## Usage
84
159
 
85
160
  Every operation is reachable through a fluent, namespaced client and
@@ -112,6 +187,70 @@ Responses return date-time fields as native `Date` objects (every
112
187
  either a `Date` or an RFC 3339 string — a meter query `from`/`to`, an
113
188
  ingested event's `time`, filter operands, all alike.
114
189
 
190
+ ## Pagination
191
+
192
+ Every list operation that returns pages also has an `…All` companion —
193
+ `client.meters.listAll(request?)` alongside `client.meters.list(request?)` —
194
+ that returns an `AsyncIterable` of items instead of one page. It fetches
195
+ each following page lazily, only when the previous page is exhausted, so a
196
+ `break` (or a `return`) partway through never fires a request for a page
197
+ nothing consumes:
198
+
199
+ ```typescript
200
+ import { OpenMeter } from '@openmeter/client'
201
+
202
+ const client = new OpenMeter({
203
+ baseUrl: 'https://openmeter.cloud/api/v3',
204
+ apiKey: process.env.OPENMETER_API_KEY,
205
+ })
206
+
207
+ for await (const meter of client.meters.listAll()) {
208
+ console.log(meter.key)
209
+ }
210
+ ```
211
+
212
+ The request object accepts the same filters, sort, and page size as the
213
+ single-page method — only the page cursor/number itself advances between
214
+ requests:
215
+
216
+ ```typescript
217
+ for await (const meter of client.meters.listAll({ filter: { key: 'api' } })) {
218
+ if (meter.key === 'api-requests') {
219
+ break // stops iterating; no further pages are fetched
220
+ }
221
+ }
222
+ ```
223
+
224
+ Cursor-paginated resources (`events`, credit transactions) work the same
225
+ way:
226
+
227
+ ```typescript
228
+ for await (const event of client.events.listAll()) {
229
+ console.log(event.event.id)
230
+ }
231
+ ```
232
+
233
+ Auto-pagination takes the same optional `RequestOptions` as every other
234
+ method, so one `AbortSignal` cancels the whole iteration, not just the page
235
+ in flight:
236
+
237
+ ```typescript
238
+ const controller = new AbortController()
239
+ setTimeout(() => controller.abort(), 30_000)
240
+
241
+ for await (const meter of client.meters.listAll(undefined, {
242
+ signal: controller.signal,
243
+ })) {
244
+ console.log(meter.key)
245
+ }
246
+ ```
247
+
248
+ Iteration stops after the server’s last page — an empty or short-of-`size`
249
+ page for a page-number resource, or a response with no next cursor for a
250
+ cursor resource. A misbehaving server that never signals the end of the
251
+ list fails fast instead of looping forever: after 10,000 pages the
252
+ iterable throws `PaginationLimitExceededError`.
253
+
115
254
  ## Available Resources and Operations
116
255
 
117
256
  Operations are grouped by resource and exposed as methods on the client.
@@ -140,14 +279,14 @@ The full call path, HTTP route, and a short description are listed below.
140
279
 
141
280
  | Method | HTTP | Description |
142
281
  | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
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` | |
282
+ | `client.customers.create` | `POST /openmeter/customers` | Create customer |
283
+ | `client.customers.get` | `GET /openmeter/customers/{customerId}` | Get customer |
284
+ | `client.customers.list` | `GET /openmeter/customers` | List customers |
285
+ | `client.customers.upsert` | `PUT /openmeter/customers/{customerId}` | Upsert customer |
286
+ | `client.customers.delete` | `DELETE /openmeter/customers/{customerId}` | Delete customer |
287
+ | `client.customers.billing.get` | `GET /openmeter/customers/{customerId}/billing` | Get customer billing data |
288
+ | `client.customers.billing.update` | `PUT /openmeter/customers/{customerId}/billing` | Update customer billing data |
289
+ | `client.customers.billing.updateAppData` | `PUT /openmeter/customers/{customerId}/billing/app-data` | Update customer billing app data |
151
290
  | `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
291
  | `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
292
  | `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. |
@@ -162,21 +301,20 @@ The full call path, HTTP route, and a short description are listed below.
162
301
 
163
302
  ### Entitlements
164
303
 
165
- | Method | HTTP | Description |
166
- | ---------------------------------------- | ---------------------------------------------------------- | ----------- |
167
- | `client.entitlements.listCustomerAccess` | `GET /openmeter/customers/{customerId}/entitlement-access` | |
304
+ | Method | HTTP | Description |
305
+ | ---------------------------------------- | ---------------------------------------------------------- | -------------------------------- |
306
+ | `client.entitlements.listCustomerAccess` | `GET /openmeter/customers/{customerId}/entitlement-access` | List customer entitlement access |
168
307
 
169
308
  ### Subscriptions
170
309
 
171
310
  | Method | HTTP | Description |
172
311
  | -------------------------------------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
173
- | `client.subscriptions.create` | `POST /openmeter/subscriptions` | |
174
- | `client.subscriptions.list` | `GET /openmeter/subscriptions` | |
175
- | `client.subscriptions.get` | `GET /openmeter/subscriptions/{subscriptionId}` | |
312
+ | `client.subscriptions.create` | `POST /openmeter/subscriptions` | Create subscription |
313
+ | `client.subscriptions.list` | `GET /openmeter/subscriptions` | List subscriptions |
314
+ | `client.subscriptions.get` | `GET /openmeter/subscriptions/{subscriptionId}` | Get subscription |
176
315
  | `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
316
  | `client.subscriptions.unscheduleCancelation` | `POST /openmeter/subscriptions/{subscriptionId}/unschedule-cancelation` | Unschedules the subscription cancelation. |
178
317
  | `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
318
  | `client.subscriptions.listAddons` | `GET /openmeter/subscriptions/{subscriptionId}/addons` | List the add-ons of a subscription. |
181
319
  | `client.subscriptions.getAddon` | `GET /openmeter/subscriptions/{subscriptionId}/addons/{subscriptionAddonId}` | Get an add-on association for a subscription. |
182
320
 
@@ -197,33 +335,15 @@ The full call path, HTTP route, and a short description are listed below.
197
335
  | `client.billing.updateProfile` | `PUT /openmeter/profiles/{id}` | Update a billing profile. |
198
336
  | `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
337
 
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
338
  ### Tax
210
339
 
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. |
340
+ | Method | HTTP | Description |
341
+ | ----------------------- | ----------------------------------------- | --------------- |
342
+ | `client.tax.createCode` | `POST /openmeter/tax-codes` | Create tax code |
343
+ | `client.tax.getCode` | `GET /openmeter/tax-codes/{taxCodeId}` | Get tax code |
344
+ | `client.tax.listCodes` | `GET /openmeter/tax-codes` | List tax codes |
345
+ | `client.tax.upsertCode` | `PUT /openmeter/tax-codes/{taxCodeId}` | Upsert tax code |
346
+ | `client.tax.deleteCode` | `DELETE /openmeter/tax-codes/{taxCodeId}` | Delete tax code |
227
347
 
228
348
  ### Features
229
349
 
@@ -282,21 +402,107 @@ The full call path, HTTP route, and a short description are listed below.
282
402
 
283
403
  ### Defaults
284
404
 
285
- | Method | HTTP | Description |
286
- | -------------------------------------------- | ----------------------------------- | ----------- |
287
- | `client.defaults.getOrganizationTaxCodes` | `GET /openmeter/defaults/tax-codes` | |
288
- | `client.defaults.updateOrganizationTaxCodes` | `PUT /openmeter/defaults/tax-codes` | |
405
+ | Method | HTTP | Description |
406
+ | -------------------------------------------- | ----------------------------------- | ------------------------------------- |
407
+ | `client.defaults.getOrganizationTaxCodes` | `GET /openmeter/defaults/tax-codes` | Get organization default tax codes |
408
+ | `client.defaults.updateOrganizationTaxCodes` | `PUT /openmeter/defaults/tax-codes` | Update organization default tax codes |
409
+
410
+ ## Internal Operations
411
+
412
+ Operations marked internal in the API definition are exposed under
413
+ `client.internal.*`, quarantined from the customer surface. They are not
414
+ intended for customer use: they may require additional permissions, and
415
+ they can change or be removed without notice or semver consideration.
416
+
417
+ ### Internal Subscriptions
418
+
419
+ | Method | HTTP | Description |
420
+ | ------------------------------------------- | ------------------------------------------------------- | ----------------------------- |
421
+ | `client.internal.subscriptions.createAddon` | `POST /openmeter/subscriptions/{subscriptionId}/addons` | Add add-on to a subscription. |
422
+
423
+ ### Internal Currencies
424
+
425
+ | Method | HTTP | Description |
426
+ | ------------------------------------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
427
+ | `client.internal.currencies.list` | `GET /openmeter/currencies` | List currencies supported by the billing system. |
428
+ | `client.internal.currencies.createCustomCurrency` | `POST /openmeter/currencies/custom` | Create a custom currency. This operation allows defining your own custom currency for billing purposes. |
429
+ | `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. |
430
+ | `client.internal.currencies.createCostBasis` | `POST /openmeter/currencies/custom/{currencyId}/cost-bases` | Create a cost basis for a currency. |
431
+
432
+ ## Runtime Validation (validate option)
433
+
434
+ `validate` is off by default. The SDK's normal request/response mapping
435
+ only renames keys and converts dates — it never rejects a payload — so
436
+ an additive server-side change (a new response field, a new enum value)
437
+ never breaks a client running an older SDK version.
438
+
439
+ Set `validate: true` to additionally check the wire payload — the
440
+ request body after mapping to snake_case, and the raw response before
441
+ mapping back — against the generated `…Wire` schemas. Those schemas are
442
+ strict: an unknown field or an unrecognized enum value fails validation
443
+ instead of being silently accepted. That makes `validate` a tool for
444
+ catching SDK/server contract drift in development or CI, not something
445
+ to run in production, where forward compatibility with additive server
446
+ changes matters more than strict rejection.
447
+
448
+ ```typescript
449
+ import { OpenMeter, ValidationError } from '@openmeter/client'
450
+
451
+ const client = new OpenMeter({
452
+ baseUrl: 'https://openmeter.cloud/api/v3',
453
+ apiKey: process.env.OPENMETER_API_KEY,
454
+ validate: true,
455
+ })
456
+
457
+ try {
458
+ await client.meters.get({ meterId: 'meter_123' })
459
+ } catch (error) {
460
+ if (error instanceof ValidationError) {
461
+ console.error(error.issues)
462
+ }
463
+ }
464
+ ```
465
+
466
+ The standalone functions surface the same failure as a `Result` instead
467
+ of throwing — check `result.error instanceof ValidationError`.
468
+
469
+ ## Zod Schemas (./zod export)
470
+
471
+ `@openmeter/client/zod` exports every model twice: once shaped like the
472
+ SDK's public surface (camelCase keys, `Date` for date-time fields — the
473
+ same shape `meter.eventType`/`meter.createdAt` have in TypeScript) and
474
+ once as a strict `…Wire` schema shaped like the literal JSON the server
475
+ sends and accepts (snake_case keys, RFC 3339 date-time strings, unknown
476
+ fields rejected) — the same `…Wire` schemas the `validate` option checks
477
+ internally.
478
+
479
+ Use the public schemas to validate a payload the SDK did not produce —
480
+ a webhook body, a cached record, a test fixture — before trusting its
481
+ shape:
482
+
483
+ ```typescript
484
+ import * as schemas from '@openmeter/client/zod'
289
485
 
290
- ### Governance
486
+ const parsed = schemas.meter.safeParse({
487
+ id: '01HZY3W6VXQK6H3NPC6DFA0PJT',
488
+ name: 'Tokens',
489
+ key: 'tokens',
490
+ aggregation: 'sum',
491
+ eventType: 'request',
492
+ createdAt: new Date(),
493
+ updatedAt: new Date(),
494
+ })
291
495
 
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._ |
496
+ if (parsed.success) {
497
+ console.log(parsed.data.eventType)
498
+ }
499
+ ```
295
500
 
296
501
  ## Error Handling
297
502
 
298
- A non-2xx response rejects with an `HTTPError` carrying the problem-details
299
- fields (`status`, `type`, `title`, `url`) from the response.
503
+ A non-2xx response rejects with an `HTTPError` (`error.name === 'HTTPError'`)
504
+ carrying the problem-details fields (`status`, `type`, `title`, `url`)
505
+ from the response.
300
506
 
301
507
  ```typescript
302
508
  import { OpenMeter, HTTPError } from '@openmeter/client'
@@ -315,6 +521,46 @@ try {
315
521
  }
316
522
  ```
317
523
 
524
+ `error.retryAfter` is the delta-seconds form of a numeric `Retry-After`
525
+ header (the common case on 429 and 503 responses) and `undefined`
526
+ otherwise. A 400 Bad Request additionally carries a typed
527
+ `error.invalidParameters` array describing which fields failed
528
+ validation; `error.getField(key)` is an untyped escape hatch for any
529
+ other problem-details extension member:
530
+
531
+ ```typescript
532
+ import { OpenMeter, HTTPError } from '@openmeter/client'
533
+
534
+ const client = new OpenMeter({
535
+ baseUrl: 'https://openmeter.cloud/api/v3',
536
+ apiKey: process.env.OPENMETER_API_KEY,
537
+ })
538
+
539
+ try {
540
+ await client.meters.create({
541
+ name: 'Tokens',
542
+ key: 'tokens',
543
+ aggregation: 'sum',
544
+ eventType: 'request',
545
+ })
546
+ } catch (error) {
547
+ if (error instanceof HTTPError && error.status === 400) {
548
+ for (const param of error.invalidParameters ?? []) {
549
+ console.error(param)
550
+ }
551
+ }
552
+ }
553
+ ```
554
+
555
+ The SDK's other typed errors are `ValidationError` (see
556
+ [Runtime Validation (validate option)](#runtime-validation-validate-option)), `UnsafeIntegerError`
557
+ (an `int64`/`uint64` value exceeds what JSON can represent without
558
+ precision loss), `DepthLimitExceededError` (response data nested deeper
559
+ than the mapper's safety limit), and `PaginationLimitExceededError` (an
560
+ [Pagination](#pagination) iterable exceeded
561
+ its page-count safety limit) — each distinguished the same way, by
562
+ `instanceof` or by `.name`.
563
+
318
564
  ## Standalone Functions
319
565
 
320
566
  Every method is also available as a standalone, tree-shakeable function
@@ -335,3 +581,18 @@ if (result.ok) {
335
581
  console.error(result.error)
336
582
  }
337
583
  ```
584
+
585
+ `ok`, `err`, and `unwrap` — the helpers `Result` is built from — are
586
+ exported too, so a func call can be unwrapped back into a throwing call
587
+ where that is more convenient:
588
+
589
+ ```typescript
590
+ import { Client, funcs, unwrap } from '@openmeter/client'
591
+
592
+ const client = new Client({
593
+ baseUrl: 'https://openmeter.cloud/api/v3',
594
+ apiKey: process.env.OPENMETER_API_KEY,
595
+ })
596
+
597
+ const meters = unwrap(await funcs.listMeters(client))
598
+ ```
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
package/dist/core.js CHANGED
@@ -1,5 +1,7 @@
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
1
2
  import ky from 'ky';
2
3
  import { encodePath } from './lib/encodings.js';
4
+ import { SDK_VERSION } from './lib/version.js';
3
5
  export class Client {
4
6
  _options;
5
7
  _http;
@@ -20,6 +22,12 @@ export class Client {
20
22
  beforeRequest: [
21
23
  ...(options.hooks?.beforeRequest ?? []),
22
24
  async ({ request }) => {
25
+ // Browsers treat User-Agent as a forbidden header and silently drop
26
+ // it; that's fine here, this is only observable server-side (e.g.
27
+ // request logs) and Node/server callers get it.
28
+ if (!request.headers.has('User-Agent')) {
29
+ request.headers.set('User-Agent', `openmeter-node/${SDK_VERSION}`);
30
+ }
23
31
  const token = typeof options.apiKey === 'function'
24
32
  ? await options.apiKey()
25
33
  : options.apiKey;
@@ -35,4 +43,3 @@ export class Client {
35
43
  export function http(client) {
36
44
  return client._http;
37
45
  }
38
- //# sourceMappingURL=core.js.map
@@ -1,11 +1,59 @@
1
1
  import { type Client } from '../core.js';
2
2
  import { type Result, type RequestOptions } from '../lib/types.js';
3
3
  import type { ListAddonsRequest, ListAddonsResponse, CreateAddonRequest, CreateAddonResponse, UpdateAddonRequest, UpdateAddonResponse, GetAddonRequest, GetAddonResponse, DeleteAddonRequest, DeleteAddonResponse, ArchiveAddonRequest, ArchiveAddonResponse, PublishAddonRequest, PublishAddonResponse } from '../models/operations/addons.js';
4
+ /**
5
+ * List add-ons
6
+ *
7
+ * List all add-ons.
8
+ *
9
+ * GET /openmeter/addons
10
+ */
4
11
  export declare function listAddons(client: Client, req?: ListAddonsRequest, options?: RequestOptions): Promise<Result<ListAddonsResponse>>;
12
+ /**
13
+ * Create add-on
14
+ *
15
+ * Create a new add-on.
16
+ *
17
+ * POST /openmeter/addons
18
+ */
5
19
  export declare function createAddon(client: Client, req: CreateAddonRequest, options?: RequestOptions): Promise<Result<CreateAddonResponse>>;
20
+ /**
21
+ * Update add-on
22
+ *
23
+ * Update an add-on by id.
24
+ *
25
+ * PUT /openmeter/addons/{addonId}
26
+ */
6
27
  export declare function updateAddon(client: Client, req: UpdateAddonRequest, options?: RequestOptions): Promise<Result<UpdateAddonResponse>>;
28
+ /**
29
+ * Get add-on
30
+ *
31
+ * Get add-on by id.
32
+ *
33
+ * GET /openmeter/addons/{addonId}
34
+ */
7
35
  export declare function getAddon(client: Client, req: GetAddonRequest, options?: RequestOptions): Promise<Result<GetAddonResponse>>;
36
+ /**
37
+ * Soft delete add-on
38
+ *
39
+ * Soft delete add-on by id.
40
+ *
41
+ * DELETE /openmeter/addons/{addonId}
42
+ */
8
43
  export declare function deleteAddon(client: Client, req: DeleteAddonRequest, options?: RequestOptions): Promise<Result<DeleteAddonResponse>>;
44
+ /**
45
+ * Archive add-on version
46
+ *
47
+ * Archive an add-on version.
48
+ *
49
+ * POST /openmeter/addons/{addonId}/archive
50
+ */
9
51
  export declare function archiveAddon(client: Client, req: ArchiveAddonRequest, options?: RequestOptions): Promise<Result<ArchiveAddonResponse>>;
52
+ /**
53
+ * Publish add-on version
54
+ *
55
+ * Publish an add-on version.
56
+ *
57
+ * POST /openmeter/addons/{addonId}/publish
58
+ */
10
59
  export declare function publishAddon(client: Client, req: PublishAddonRequest, options?: RequestOptions): Promise<Result<PublishAddonResponse>>;
11
- //# sourceMappingURL=addons.d.ts.map