@openmeter/client 1.0.0-beta.230 → 1.0.0-beta.231
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.
- package/LICENSE +202 -0
- package/README.md +347 -68
- package/dist/core.d.ts +0 -1
- package/dist/core.js +8 -1
- package/dist/funcs/addons.d.ts +49 -1
- package/dist/funcs/addons.js +50 -1
- package/dist/funcs/apps.d.ts +14 -1
- package/dist/funcs/apps.js +15 -1
- package/dist/funcs/billing.d.ts +46 -1
- package/dist/funcs/billing.js +47 -1
- package/dist/funcs/currencies.d.ts +30 -1
- package/dist/funcs/currencies.js +31 -1
- package/dist/funcs/customers.d.ts +165 -2
- package/dist/funcs/customers.js +192 -1
- package/dist/funcs/defaults.d.ts +10 -1
- package/dist/funcs/defaults.js +11 -1
- package/dist/funcs/entitlements.d.ts +5 -1
- package/dist/funcs/entitlements.js +6 -1
- package/dist/funcs/events.d.ts +14 -1
- package/dist/funcs/events.js +15 -1
- package/dist/funcs/features.d.ts +42 -1
- package/dist/funcs/features.js +43 -1
- package/dist/funcs/governance.d.ts +14 -1
- package/dist/funcs/governance.js +15 -1
- package/dist/funcs/index.d.ts +0 -1
- package/dist/funcs/index.js +1 -1
- package/dist/funcs/invoices.d.ts +44 -1
- package/dist/funcs/invoices.js +45 -1
- package/dist/funcs/llmCost.d.ts +36 -1
- package/dist/funcs/llmCost.js +37 -1
- package/dist/funcs/meters.d.ts +53 -1
- package/dist/funcs/meters.js +54 -1
- package/dist/funcs/planAddons.d.ts +35 -1
- package/dist/funcs/planAddons.js +36 -1
- package/dist/funcs/plans.d.ts +49 -1
- package/dist/funcs/plans.js +50 -1
- package/dist/funcs/subscriptions.d.ts +59 -1
- package/dist/funcs/subscriptions.js +60 -1
- package/dist/funcs/tax.d.ts +25 -1
- package/dist/funcs/tax.js +26 -1
- package/dist/index.d.ts +4 -6
- package/dist/index.js +4 -5
- package/dist/lib/config.d.ts +0 -1
- package/dist/lib/config.js +1 -1
- package/dist/lib/encodings.d.ts +0 -1
- package/dist/lib/encodings.js +1 -1
- package/dist/lib/paginate.d.ts +56 -0
- package/dist/lib/paginate.js +60 -0
- package/dist/lib/request.d.ts +0 -1
- package/dist/lib/request.js +1 -1
- package/dist/lib/to-error.d.ts +0 -1
- package/dist/lib/to-error.js +1 -1
- package/dist/lib/types.d.ts +0 -1
- package/dist/lib/types.js +1 -1
- package/dist/lib/version.d.ts +1 -0
- package/dist/lib/version.js +5 -0
- package/dist/lib/wire.d.ts +3 -1
- package/dist/lib/wire.js +93 -4
- package/dist/models/errors.d.ts +13 -2
- package/dist/models/errors.js +31 -4
- package/dist/models/operations/addons.d.ts +0 -1
- package/dist/models/operations/addons.js +1 -1
- package/dist/models/operations/apps.d.ts +2 -5
- package/dist/models/operations/apps.js +1 -1
- package/dist/models/operations/billing.d.ts +0 -1
- package/dist/models/operations/billing.js +1 -1
- package/dist/models/operations/currencies.d.ts +0 -1
- package/dist/models/operations/currencies.js +1 -1
- package/dist/models/operations/customers.d.ts +9 -6
- package/dist/models/operations/customers.js +1 -1
- package/dist/models/operations/defaults.d.ts +0 -1
- package/dist/models/operations/defaults.js +1 -1
- package/dist/models/operations/entitlements.d.ts +0 -1
- package/dist/models/operations/entitlements.js +1 -1
- package/dist/models/operations/events.d.ts +0 -1
- package/dist/models/operations/events.js +1 -1
- package/dist/models/operations/features.d.ts +0 -1
- package/dist/models/operations/features.js +1 -1
- package/dist/models/operations/governance.d.ts +0 -1
- package/dist/models/operations/governance.js +1 -1
- package/dist/models/operations/invoices.d.ts +4 -7
- package/dist/models/operations/invoices.js +1 -1
- package/dist/models/operations/llmCost.d.ts +0 -1
- package/dist/models/operations/llmCost.js +1 -1
- package/dist/models/operations/meters.d.ts +0 -1
- package/dist/models/operations/meters.js +1 -1
- package/dist/models/operations/planAddons.d.ts +0 -1
- package/dist/models/operations/planAddons.js +1 -1
- package/dist/models/operations/plans.d.ts +0 -1
- package/dist/models/operations/plans.js +1 -1
- package/dist/models/operations/subscriptions.d.ts +0 -1
- package/dist/models/operations/subscriptions.js +1 -1
- package/dist/models/operations/tax.d.ts +0 -1
- package/dist/models/operations/tax.js +1 -1
- package/dist/models/schemas.d.ts +162 -1
- package/dist/models/schemas.js +37 -5
- package/dist/models/types.d.ts +464 -577
- package/dist/models/types.js +1 -1
- package/dist/sdk/addons.d.ts +60 -1
- package/dist/sdk/addons.js +63 -1
- package/dist/sdk/apps.d.ts +25 -1
- package/dist/sdk/apps.js +28 -1
- package/dist/sdk/billing.d.ts +57 -1
- package/dist/sdk/billing.js +60 -1
- package/dist/sdk/customers.d.ts +211 -2
- package/dist/sdk/customers.js +222 -2
- package/dist/sdk/defaults.d.ts +10 -1
- package/dist/sdk/defaults.js +11 -1
- package/dist/sdk/entitlements.d.ts +5 -1
- package/dist/sdk/entitlements.js +6 -1
- package/dist/sdk/events.d.ts +25 -1
- package/dist/sdk/events.js +28 -1
- package/dist/sdk/features.d.ts +53 -1
- package/dist/sdk/features.js +56 -1
- package/dist/sdk/internal.d.ts +180 -0
- package/dist/sdk/internal.js +224 -0
- package/dist/sdk/llmCost.d.ts +57 -1
- package/dist/sdk/llmCost.js +62 -1
- package/dist/sdk/meters.d.ts +64 -1
- package/dist/sdk/meters.js +67 -1
- package/dist/sdk/planAddons.d.ts +46 -1
- package/dist/sdk/planAddons.js +49 -1
- package/dist/sdk/plans.d.ts +60 -1
- package/dist/sdk/plans.js +63 -1
- package/dist/sdk/sdk.d.ts +9 -10
- package/dist/sdk/sdk.js +11 -15
- package/dist/sdk/subscriptions.d.ts +72 -3
- package/dist/sdk/subscriptions.js +77 -5
- package/dist/sdk/tax.d.ts +34 -1
- package/dist/sdk/tax.js +37 -1
- package/package.json +28 -4
- package/dist/sdk/currencies.d.ts +0 -12
- package/dist/sdk/currencies.js +0 -21
- package/dist/sdk/governance.d.ts +0 -9
- package/dist/sdk/governance.js +0 -12
- package/dist/sdk/invoices.d.ts +0 -12
- 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
|
-
>
|
|
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,20 @@ 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
|
-
|
|
37
|
+
- [Internal Operations](#internal-operations)
|
|
38
|
+
- [Internal Subscriptions](#internal-subscriptions)
|
|
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,45 +279,45 @@ 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.
|
|
159
|
-
| `client.customers.credits.
|
|
160
|
-
| `client.customers.
|
|
161
|
-
| `client.customers.charges.
|
|
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
|
|
|
@@ -197,33 +338,15 @@ The full call path, HTTP route, and a short description are listed below.
|
|
|
197
338
|
| `client.billing.updateProfile` | `PUT /openmeter/profiles/{id}` | Update a billing profile. |
|
|
198
339
|
| `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
340
|
|
|
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
341
|
### Tax
|
|
210
342
|
|
|
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. |
|
|
343
|
+
| Method | HTTP | Description |
|
|
344
|
+
| ----------------------- | ----------------------------------------- | --------------- |
|
|
345
|
+
| `client.tax.createCode` | `POST /openmeter/tax-codes` | Create tax code |
|
|
346
|
+
| `client.tax.getCode` | `GET /openmeter/tax-codes/{taxCodeId}` | Get tax code |
|
|
347
|
+
| `client.tax.listCodes` | `GET /openmeter/tax-codes` | List tax codes |
|
|
348
|
+
| `client.tax.upsertCode` | `PUT /openmeter/tax-codes/{taxCodeId}` | Upsert tax code |
|
|
349
|
+
| `client.tax.deleteCode` | `DELETE /openmeter/tax-codes/{taxCodeId}` | Delete tax code |
|
|
227
350
|
|
|
228
351
|
### Features
|
|
229
352
|
|
|
@@ -282,21 +405,122 @@ The full call path, HTTP route, and a short description are listed below.
|
|
|
282
405
|
|
|
283
406
|
### Defaults
|
|
284
407
|
|
|
285
|
-
| Method | HTTP | Description
|
|
286
|
-
| -------------------------------------------- | ----------------------------------- |
|
|
287
|
-
| `client.defaults.getOrganizationTaxCodes` | `GET /openmeter/defaults/tax-codes` |
|
|
288
|
-
| `client.defaults.updateOrganizationTaxCodes` | `PUT /openmeter/defaults/tax-codes` |
|
|
408
|
+
| Method | HTTP | Description |
|
|
409
|
+
| -------------------------------------------- | ----------------------------------- | ------------------------------------- |
|
|
410
|
+
| `client.defaults.getOrganizationTaxCodes` | `GET /openmeter/defaults/tax-codes` | Get organization default tax codes |
|
|
411
|
+
| `client.defaults.updateOrganizationTaxCodes` | `PUT /openmeter/defaults/tax-codes` | Update organization default tax codes |
|
|
412
|
+
|
|
413
|
+
## Internal Operations
|
|
414
|
+
|
|
415
|
+
Operations marked internal in the API definition are exposed under
|
|
416
|
+
`client.internal.*`, quarantined from the customer surface. They are not
|
|
417
|
+
intended for customer use: they may require additional permissions, and
|
|
418
|
+
they can change or be removed without notice or semver consideration.
|
|
419
|
+
|
|
420
|
+
### Internal Subscriptions
|
|
421
|
+
|
|
422
|
+
| Method | HTTP | Description |
|
|
423
|
+
| ------------------------------------------- | ------------------------------------------------------- | ----------------------------- |
|
|
424
|
+
| `client.internal.subscriptions.createAddon` | `POST /openmeter/subscriptions/{subscriptionId}/addons` | Add add-on to a subscription. |
|
|
425
|
+
|
|
426
|
+
### Internal Invoices
|
|
427
|
+
|
|
428
|
+
| Method | HTTP | Description |
|
|
429
|
+
| --------------------------------- | ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
430
|
+
| `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. |
|
|
431
|
+
| `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. |
|
|
432
|
+
| `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. |
|
|
433
|
+
| `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. |
|
|
434
|
+
|
|
435
|
+
### Internal Currencies
|
|
436
|
+
|
|
437
|
+
| Method | HTTP | Description |
|
|
438
|
+
| ------------------------------------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
|
439
|
+
| `client.internal.currencies.list` | `GET /openmeter/currencies` | List currencies supported by the billing system. |
|
|
440
|
+
| `client.internal.currencies.createCustomCurrency` | `POST /openmeter/currencies/custom` | Create a custom currency. This operation allows defining your own custom currency for billing purposes. |
|
|
441
|
+
| `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. |
|
|
442
|
+
| `client.internal.currencies.createCostBasis` | `POST /openmeter/currencies/custom/{currencyId}/cost-bases` | Create a cost basis for a currency. |
|
|
443
|
+
|
|
444
|
+
### Internal Governance
|
|
445
|
+
|
|
446
|
+
| Method | HTTP | Description |
|
|
447
|
+
| ---------------------------------------- | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
448
|
+
| `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._ |
|
|
449
|
+
|
|
450
|
+
## Runtime Validation (validate option)
|
|
451
|
+
|
|
452
|
+
`validate` is off by default. The SDK's normal request/response mapping
|
|
453
|
+
only renames keys and converts dates — it never rejects a payload — so
|
|
454
|
+
an additive server-side change (a new response field, a new enum value)
|
|
455
|
+
never breaks a client running an older SDK version.
|
|
456
|
+
|
|
457
|
+
Set `validate: true` to additionally check the wire payload — the
|
|
458
|
+
request body after mapping to snake_case, and the raw response before
|
|
459
|
+
mapping back — against the generated `…Wire` schemas. Those schemas are
|
|
460
|
+
strict: an unknown field or an unrecognized enum value fails validation
|
|
461
|
+
instead of being silently accepted. That makes `validate` a tool for
|
|
462
|
+
catching SDK/server contract drift in development or CI, not something
|
|
463
|
+
to run in production, where forward compatibility with additive server
|
|
464
|
+
changes matters more than strict rejection.
|
|
465
|
+
|
|
466
|
+
```typescript
|
|
467
|
+
import { OpenMeter, ValidationError } from '@openmeter/client'
|
|
468
|
+
|
|
469
|
+
const client = new OpenMeter({
|
|
470
|
+
baseUrl: 'https://openmeter.cloud/api/v3',
|
|
471
|
+
apiKey: process.env.OPENMETER_API_KEY,
|
|
472
|
+
validate: true,
|
|
473
|
+
})
|
|
474
|
+
|
|
475
|
+
try {
|
|
476
|
+
await client.meters.get({ meterId: 'meter_123' })
|
|
477
|
+
} catch (error) {
|
|
478
|
+
if (error instanceof ValidationError) {
|
|
479
|
+
console.error(error.issues)
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
The standalone functions surface the same failure as a `Result` instead
|
|
485
|
+
of throwing — check `result.error instanceof ValidationError`.
|
|
486
|
+
|
|
487
|
+
## Zod Schemas (./zod export)
|
|
488
|
+
|
|
489
|
+
`@openmeter/client/zod` exports every model twice: once shaped like the
|
|
490
|
+
SDK's public surface (camelCase keys, `Date` for date-time fields — the
|
|
491
|
+
same shape `meter.eventType`/`meter.createdAt` have in TypeScript) and
|
|
492
|
+
once as a strict `…Wire` schema shaped like the literal JSON the server
|
|
493
|
+
sends and accepts (snake_case keys, RFC 3339 date-time strings, unknown
|
|
494
|
+
fields rejected) — the same `…Wire` schemas the `validate` option checks
|
|
495
|
+
internally.
|
|
496
|
+
|
|
497
|
+
Use the public schemas to validate a payload the SDK did not produce —
|
|
498
|
+
a webhook body, a cached record, a test fixture — before trusting its
|
|
499
|
+
shape:
|
|
500
|
+
|
|
501
|
+
```typescript
|
|
502
|
+
import * as schemas from '@openmeter/client/zod'
|
|
289
503
|
|
|
290
|
-
|
|
504
|
+
const parsed = schemas.meter.safeParse({
|
|
505
|
+
id: '01HZY3W6VXQK6H3NPC6DFA0PJT',
|
|
506
|
+
name: 'Tokens',
|
|
507
|
+
key: 'tokens',
|
|
508
|
+
aggregation: 'sum',
|
|
509
|
+
eventType: 'request',
|
|
510
|
+
createdAt: new Date(),
|
|
511
|
+
updatedAt: new Date(),
|
|
512
|
+
})
|
|
291
513
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
514
|
+
if (parsed.success) {
|
|
515
|
+
console.log(parsed.data.eventType)
|
|
516
|
+
}
|
|
517
|
+
```
|
|
295
518
|
|
|
296
519
|
## Error Handling
|
|
297
520
|
|
|
298
|
-
A non-2xx response rejects with an `HTTPError`
|
|
299
|
-
fields (`status`, `type`, `title`, `url`)
|
|
521
|
+
A non-2xx response rejects with an `HTTPError` (`error.name === 'HTTPError'`)
|
|
522
|
+
carrying the problem-details fields (`status`, `type`, `title`, `url`)
|
|
523
|
+
from the response.
|
|
300
524
|
|
|
301
525
|
```typescript
|
|
302
526
|
import { OpenMeter, HTTPError } from '@openmeter/client'
|
|
@@ -315,6 +539,46 @@ try {
|
|
|
315
539
|
}
|
|
316
540
|
```
|
|
317
541
|
|
|
542
|
+
`error.retryAfter` is the delta-seconds form of a numeric `Retry-After`
|
|
543
|
+
header (the common case on 429 and 503 responses) and `undefined`
|
|
544
|
+
otherwise. A 400 Bad Request additionally carries a typed
|
|
545
|
+
`error.invalidParameters` array describing which fields failed
|
|
546
|
+
validation; `error.getField(key)` is an untyped escape hatch for any
|
|
547
|
+
other problem-details extension member:
|
|
548
|
+
|
|
549
|
+
```typescript
|
|
550
|
+
import { OpenMeter, HTTPError } from '@openmeter/client'
|
|
551
|
+
|
|
552
|
+
const client = new OpenMeter({
|
|
553
|
+
baseUrl: 'https://openmeter.cloud/api/v3',
|
|
554
|
+
apiKey: process.env.OPENMETER_API_KEY,
|
|
555
|
+
})
|
|
556
|
+
|
|
557
|
+
try {
|
|
558
|
+
await client.meters.create({
|
|
559
|
+
name: 'Tokens',
|
|
560
|
+
key: 'tokens',
|
|
561
|
+
aggregation: 'sum',
|
|
562
|
+
eventType: 'request',
|
|
563
|
+
})
|
|
564
|
+
} catch (error) {
|
|
565
|
+
if (error instanceof HTTPError && error.status === 400) {
|
|
566
|
+
for (const param of error.invalidParameters ?? []) {
|
|
567
|
+
console.error(param)
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
The SDK's other typed errors are `ValidationError` (see
|
|
574
|
+
[Runtime Validation (validate option)](#runtime-validation-validate-option)), `UnsafeIntegerError`
|
|
575
|
+
(an `int64`/`uint64` value exceeds what JSON can represent without
|
|
576
|
+
precision loss), `DepthLimitExceededError` (response data nested deeper
|
|
577
|
+
than the mapper's safety limit), and `PaginationLimitExceededError` (an
|
|
578
|
+
[Pagination](#pagination) iterable exceeded
|
|
579
|
+
its page-count safety limit) — each distinguished the same way, by
|
|
580
|
+
`instanceof` or by `.name`.
|
|
581
|
+
|
|
318
582
|
## Standalone Functions
|
|
319
583
|
|
|
320
584
|
Every method is also available as a standalone, tree-shakeable function
|
|
@@ -335,3 +599,18 @@ if (result.ok) {
|
|
|
335
599
|
console.error(result.error)
|
|
336
600
|
}
|
|
337
601
|
```
|
|
602
|
+
|
|
603
|
+
`ok`, `err`, and `unwrap` — the helpers `Result` is built from — are
|
|
604
|
+
exported too, so a func call can be unwrapped back into a throwing call
|
|
605
|
+
where that is more convenient:
|
|
606
|
+
|
|
607
|
+
```typescript
|
|
608
|
+
import { Client, funcs, unwrap } from '@openmeter/client'
|
|
609
|
+
|
|
610
|
+
const client = new Client({
|
|
611
|
+
baseUrl: 'https://openmeter.cloud/api/v3',
|
|
612
|
+
apiKey: process.env.OPENMETER_API_KEY,
|
|
613
|
+
})
|
|
614
|
+
|
|
615
|
+
const meters = unwrap(await funcs.listMeters(client))
|
|
616
|
+
```
|
package/dist/core.d.ts
CHANGED
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
|