@openmeter/client 1.0.0-beta-4bc7392a70e6

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 (122) hide show
  1. package/README.md +318 -0
  2. package/dist/core.d.ts +10 -0
  3. package/dist/core.js +38 -0
  4. package/dist/funcs/addons.d.ts +11 -0
  5. package/dist/funcs/addons.js +53 -0
  6. package/dist/funcs/apps.d.ts +6 -0
  7. package/dist/funcs/apps.js +16 -0
  8. package/dist/funcs/billing.d.ts +9 -0
  9. package/dist/funcs/billing.js +33 -0
  10. package/dist/funcs/currencies.d.ts +8 -0
  11. package/dist/funcs/currencies.js +35 -0
  12. package/dist/funcs/customers.d.ts +21 -0
  13. package/dist/funcs/customers.js +141 -0
  14. package/dist/funcs/defaults.d.ts +6 -0
  15. package/dist/funcs/defaults.js +13 -0
  16. package/dist/funcs/entitlements.d.ts +5 -0
  17. package/dist/funcs/entitlements.js +10 -0
  18. package/dist/funcs/events.d.ts +6 -0
  19. package/dist/funcs/events.js +19 -0
  20. package/dist/funcs/features.d.ts +10 -0
  21. package/dist/funcs/features.js +49 -0
  22. package/dist/funcs/governance.d.ts +5 -0
  23. package/dist/funcs/governance.js +16 -0
  24. package/dist/funcs/index.d.ts +17 -0
  25. package/dist/funcs/index.js +17 -0
  26. package/dist/funcs/llmCost.d.ts +9 -0
  27. package/dist/funcs/llmCost.js +42 -0
  28. package/dist/funcs/meters.d.ts +10 -0
  29. package/dist/funcs/meters.js +49 -0
  30. package/dist/funcs/planAddons.d.ts +9 -0
  31. package/dist/funcs/planAddons.js +48 -0
  32. package/dist/funcs/plans.d.ts +11 -0
  33. package/dist/funcs/plans.js +47 -0
  34. package/dist/funcs/subscriptions.d.ts +12 -0
  35. package/dist/funcs/subscriptions.js +64 -0
  36. package/dist/funcs/tax.d.ts +9 -0
  37. package/dist/funcs/tax.js +40 -0
  38. package/dist/index.d.ts +42 -0
  39. package/dist/index.js +23 -0
  40. package/dist/lib/config.d.ts +14 -0
  41. package/dist/lib/config.js +7 -0
  42. package/dist/lib/encodings.d.ts +8 -0
  43. package/dist/lib/encodings.js +56 -0
  44. package/dist/lib/request.d.ts +3 -0
  45. package/dist/lib/request.js +11 -0
  46. package/dist/lib/to-error.d.ts +2 -0
  47. package/dist/lib/to-error.js +16 -0
  48. package/dist/lib/types.d.ts +15 -0
  49. package/dist/lib/types.js +13 -0
  50. package/dist/models/errors.d.ts +16 -0
  51. package/dist/models/errors.js +28 -0
  52. package/dist/models/operations/addons.d.ts +38 -0
  53. package/dist/models/operations/addons.js +2 -0
  54. package/dist/models/operations/apps.d.ts +17 -0
  55. package/dist/models/operations/apps.js +2 -0
  56. package/dist/models/operations/billing.d.ts +26 -0
  57. package/dist/models/operations/billing.js +2 -0
  58. package/dist/models/operations/currencies.d.ts +35 -0
  59. package/dist/models/operations/currencies.js +2 -0
  60. package/dist/models/operations/customers.d.ts +117 -0
  61. package/dist/models/operations/customers.js +2 -0
  62. package/dist/models/operations/defaults.d.ts +6 -0
  63. package/dist/models/operations/defaults.js +2 -0
  64. package/dist/models/operations/entitlements.d.ts +6 -0
  65. package/dist/models/operations/entitlements.js +2 -0
  66. package/dist/models/operations/events.d.ts +13 -0
  67. package/dist/models/operations/events.js +2 -0
  68. package/dist/models/operations/features.d.ts +35 -0
  69. package/dist/models/operations/features.js +2 -0
  70. package/dist/models/operations/governance.d.ts +9 -0
  71. package/dist/models/operations/governance.js +2 -0
  72. package/dist/models/operations/llmCost.d.ts +35 -0
  73. package/dist/models/operations/llmCost.js +2 -0
  74. package/dist/models/operations/meters.d.ts +35 -0
  75. package/dist/models/operations/meters.js +2 -0
  76. package/dist/models/operations/planAddons.d.ts +34 -0
  77. package/dist/models/operations/planAddons.js +2 -0
  78. package/dist/models/operations/plans.d.ts +38 -0
  79. package/dist/models/operations/plans.js +2 -0
  80. package/dist/models/operations/subscriptions.d.ts +52 -0
  81. package/dist/models/operations/subscriptions.js +2 -0
  82. package/dist/models/operations/tax.d.ts +28 -0
  83. package/dist/models/operations/tax.js +2 -0
  84. package/dist/models/schemas.d.ts +11372 -0
  85. package/dist/models/schemas.js +4023 -0
  86. package/dist/models/types.d.ts +3385 -0
  87. package/dist/models/types.js +2 -0
  88. package/dist/sdk/addons.d.ts +15 -0
  89. package/dist/sdk/addons.js +30 -0
  90. package/dist/sdk/apps.d.ts +10 -0
  91. package/dist/sdk/apps.js +15 -0
  92. package/dist/sdk/billing.d.ts +13 -0
  93. package/dist/sdk/billing.js +24 -0
  94. package/dist/sdk/currencies.d.ts +12 -0
  95. package/dist/sdk/currencies.js +21 -0
  96. package/dist/sdk/customers.d.ts +67 -0
  97. package/dist/sdk/customers.js +130 -0
  98. package/dist/sdk/defaults.d.ts +10 -0
  99. package/dist/sdk/defaults.js +15 -0
  100. package/dist/sdk/entitlements.d.ts +9 -0
  101. package/dist/sdk/entitlements.js +12 -0
  102. package/dist/sdk/events.d.ts +10 -0
  103. package/dist/sdk/events.js +15 -0
  104. package/dist/sdk/features.d.ts +14 -0
  105. package/dist/sdk/features.js +27 -0
  106. package/dist/sdk/governance.d.ts +9 -0
  107. package/dist/sdk/governance.js +12 -0
  108. package/dist/sdk/llmCost.d.ts +13 -0
  109. package/dist/sdk/llmCost.js +24 -0
  110. package/dist/sdk/meters.d.ts +14 -0
  111. package/dist/sdk/meters.js +27 -0
  112. package/dist/sdk/planAddons.d.ts +13 -0
  113. package/dist/sdk/planAddons.js +24 -0
  114. package/dist/sdk/plans.d.ts +15 -0
  115. package/dist/sdk/plans.js +30 -0
  116. package/dist/sdk/sdk.d.ts +52 -0
  117. package/dist/sdk/sdk.js +84 -0
  118. package/dist/sdk/subscriptions.d.ts +16 -0
  119. package/dist/sdk/subscriptions.js +33 -0
  120. package/dist/sdk/tax.d.ts +13 -0
  121. package/dist/sdk/tax.js +24 -0
  122. package/package.json +33 -0
package/README.md ADDED
@@ -0,0 +1,318 @@
1
+ # OpenMeter SDK
2
+
3
+ TypeScript client for the OpenMeter API — usage metering and billing for
4
+ AI and DevTool companies. This package is generated from the OpenMeter
5
+ TypeSpec definitions and ships fully-typed request and response models.
6
+
7
+ > [!IMPORTANT]
8
+ > This SDK is a work in progress.
9
+ >
10
+ > This SDK targets the [OpenMeter API v3](https://openmeter.io/docs/api/v3),
11
+ > a rewrite of the OpenMeter API following AIP (API Improvement Proposal)
12
+ > standardization.
13
+
14
+ ## Table of Contents
15
+
16
+ - [Installation](#installation)
17
+ - [Initialization](#initialization)
18
+ - [Usage](#usage)
19
+ - [Available Resources and Operations](#available-resources-and-operations)
20
+ - [Events](#events)
21
+ - [Meters](#meters)
22
+ - [Customers](#customers)
23
+ - [Entitlements](#entitlements)
24
+ - [Subscriptions](#subscriptions)
25
+ - [Apps](#apps)
26
+ - [Billing](#billing)
27
+ - [Tax](#tax)
28
+ - [Currencies](#currencies)
29
+ - [Features](#features)
30
+ - [LLMCost](#llmcost)
31
+ - [Plans](#plans)
32
+ - [Addons](#addons)
33
+ - [PlanAddons](#planaddons)
34
+ - [Defaults](#defaults)
35
+ - [Governance](#governance)
36
+ - [Error Handling](#error-handling)
37
+ - [Standalone Functions](#standalone-functions)
38
+
39
+ ## Installation
40
+
41
+ ```bash
42
+ npm install @openmeter/client
43
+ ```
44
+
45
+ Or with your package manager of choice:
46
+
47
+ ```bash
48
+ pnpm add @openmeter/client
49
+ yarn add @openmeter/client
50
+ ```
51
+
52
+ ## Initialization
53
+
54
+ Create a client with a base URL and an API key. The API key is sent as a
55
+ `Bearer` token on every request.
56
+
57
+ ```typescript
58
+ import { OpenMeter } from '@openmeter/client'
59
+
60
+ const client = new OpenMeter({
61
+ baseUrl: 'https://openmeter.cloud/api/v3',
62
+ apiKey: process.env.OPENMETER_API_KEY,
63
+ })
64
+ ```
65
+
66
+ Konnect regions are addressed with a server template and a `region`
67
+ variable:
68
+
69
+ ```typescript
70
+ import { OpenMeter, ServerList } from '@openmeter/client'
71
+
72
+ const client = new OpenMeter({
73
+ baseUrl: ServerList[0],
74
+ serverVariables: { region: 'eu' },
75
+ apiKey: process.env.OPENMETER_API_KEY,
76
+ })
77
+ ```
78
+
79
+ The `apiKey` may also be a function returning a `string` or
80
+ `Promise<string>`, so tokens can be refreshed per request.
81
+
82
+ ## Usage
83
+
84
+ Every operation is reachable through a fluent, namespaced client and
85
+ returns a typed response (or throws an `HTTPError` on a non-2xx status).
86
+
87
+ ```typescript
88
+ import { OpenMeter } from '@openmeter/client'
89
+
90
+ const client = new OpenMeter({
91
+ baseUrl: 'https://openmeter.cloud/api/v3',
92
+ apiKey: process.env.OPENMETER_API_KEY,
93
+ })
94
+
95
+ const meter = await client.meters.create({
96
+ name: 'Tokens',
97
+ key: 'tokens',
98
+ aggregation: 'sum',
99
+ event_type: 'request',
100
+ value_property: '$.tokens',
101
+ })
102
+
103
+ const meters = await client.meters.list()
104
+ ```
105
+
106
+ Each method takes the request object as its first argument and an optional
107
+ per-request options object (`RequestOptions`) as its second.
108
+
109
+ ## Available Resources and Operations
110
+
111
+ Operations are grouped by resource and exposed as methods on the client.
112
+ The full call path, HTTP route, and a short description are listed below.
113
+
114
+ ### Events
115
+
116
+ | Method | HTTP | Description |
117
+ | ---------------------- | ------------------------ | ---------------------------------------------------------------------------- |
118
+ | `client.events.list` | `GET /openmeter/events` | List ingested events. |
119
+ | `client.events.ingest` | `POST /openmeter/events` | Ingests an event or batch of events following the CloudEvents specification. |
120
+
121
+ ### Meters
122
+
123
+ | Method | HTTP | Description |
124
+ | ---------------------- | ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
125
+ | `client.meters.create` | `POST /openmeter/meters` | Create a meter. |
126
+ | `client.meters.get` | `GET /openmeter/meters/{meterId}` | Get a meter by ID. |
127
+ | `client.meters.list` | `GET /openmeter/meters` | List meters. |
128
+ | `client.meters.update` | `PUT /openmeter/meters/{meterId}` | Update a meter. |
129
+ | `client.meters.delete` | `DELETE /openmeter/meters/{meterId}` | Delete a meter. |
130
+ | `client.meters.query` | `POST /openmeter/meters/{meterId}/query` | Query a meter for usage. Set `Accept: application/json` (the default) to get a structured JSON response. Set `Accept: text/csv` to download the same data as a CSV file suitable for spreadsheets. The CSV columns, in order, are: `from, to, [subject,] [customer_id, customer_key, customer_name,] <dimensions...>, value` The `subject` column is emitted only when `subject` is in the query's `group_by_dimensions`. The three `customer_*` columns are emitted together only when `customer_id` is in the query's `group_by_dimensions`. |
131
+
132
+ ### Customers
133
+
134
+ | Method | HTTP | Description |
135
+ | ------------------------------------------------------ | ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
136
+ | `client.customers.create` | `POST /openmeter/customers` | |
137
+ | `client.customers.get` | `GET /openmeter/customers/{customerId}` | |
138
+ | `client.customers.list` | `GET /openmeter/customers` | |
139
+ | `client.customers.upsert` | `PUT /openmeter/customers/{customerId}` | |
140
+ | `client.customers.delete` | `DELETE /openmeter/customers/{customerId}` | |
141
+ | `client.customers.billing.get` | `GET /openmeter/customers/{customerId}/billing` | |
142
+ | `client.customers.billing.update` | `PUT /openmeter/customers/{customerId}/billing` | |
143
+ | `client.customers.billing.updateAppData` | `PUT /openmeter/customers/{customerId}/billing/app-data` | |
144
+ | `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. |
145
+ | `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. |
146
+ | `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. |
147
+ | `client.customers.credits.grants.get` | `GET /openmeter/customers/{customerId}/credits/grants/{creditGrantId}` | Get a credit grant. |
148
+ | `client.customers.credits.grants.list` | `GET /openmeter/customers/{customerId}/credits/grants` | List credit grants. |
149
+ | `client.customers.credits.balance.get` | `GET /openmeter/customers/{customerId}/credits/balance` | Get a credit balance. |
150
+ | `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 |
151
+ | `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. |
152
+ | `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. |
153
+
154
+ ### Entitlements
155
+
156
+ | Method | HTTP | Description |
157
+ | ---------------------------------------- | ---------------------------------------------------------- | ----------- |
158
+ | `client.entitlements.listCustomerAccess` | `GET /openmeter/customers/{customerId}/entitlement-access` | |
159
+
160
+ ### Subscriptions
161
+
162
+ | Method | HTTP | Description |
163
+ | -------------------------------------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
164
+ | `client.subscriptions.create` | `POST /openmeter/subscriptions` | |
165
+ | `client.subscriptions.list` | `GET /openmeter/subscriptions` | |
166
+ | `client.subscriptions.get` | `GET /openmeter/subscriptions/{subscriptionId}` | |
167
+ | `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. |
168
+ | `client.subscriptions.unscheduleCancelation` | `POST /openmeter/subscriptions/{subscriptionId}/unschedule-cancelation` | Unschedules the subscription cancelation. |
169
+ | `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. |
170
+ | `client.subscriptions.listAddons` | `GET /openmeter/subscriptions/{subscriptionId}/addons` | List the addons of a subscription. |
171
+ | `client.subscriptions.getAddon` | `GET /openmeter/subscriptions/{subscriptionId}/addons/{subscriptionAddonId}` | Get an add-on association for a subscription. |
172
+
173
+ ### Apps
174
+
175
+ | Method | HTTP | Description |
176
+ | ------------------ | ----------------------------- | --------------------- |
177
+ | `client.apps.list` | `GET /openmeter/apps` | List installed apps. |
178
+ | `client.apps.get` | `GET /openmeter/apps/{appId}` | Get an installed app. |
179
+
180
+ ### Billing
181
+
182
+ | Method | HTTP | Description |
183
+ | ------------------------------ | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
184
+ | `client.billing.listProfiles` | `GET /openmeter/profiles` | List billing profiles. |
185
+ | `client.billing.createProfile` | `POST /openmeter/profiles` | Create a new billing profile. Billing profiles contain the settings for billing and controls invoice generation. An organization can have multiple billing profiles defined. A billing profile is linked to a specific app. This association is established during the billing profile's creation and remains immutable. |
186
+ | `client.billing.getProfile` | `GET /openmeter/profiles/{id}` | Get a billing profile. |
187
+ | `client.billing.updateProfile` | `PUT /openmeter/profiles/{id}` | Update a billing profile. |
188
+ | `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 |
189
+
190
+ ### Tax
191
+
192
+ | Method | HTTP | Description |
193
+ | ----------------------- | ----------------------------------------- | ----------- |
194
+ | `client.tax.createCode` | `POST /openmeter/tax-codes` | |
195
+ | `client.tax.getCode` | `GET /openmeter/tax-codes/{taxCodeId}` | |
196
+ | `client.tax.listCodes` | `GET /openmeter/tax-codes` | |
197
+ | `client.tax.upsertCode` | `PUT /openmeter/tax-codes/{taxCodeId}` | |
198
+ | `client.tax.deleteCode` | `DELETE /openmeter/tax-codes/{taxCodeId}` | |
199
+
200
+ ### Currencies
201
+
202
+ | Method | HTTP | Description |
203
+ | ---------------------------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
204
+ | `client.currencies.list` | `GET /openmeter/currencies` | List currencies supported by the billing system. |
205
+ | `client.currencies.createCustomCurrency` | `POST /openmeter/currencies/custom` | Create a custom currency. This operation allows defining your own custom currency for billing purposes. |
206
+ | `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. |
207
+ | `client.currencies.createCostBasis` | `POST /openmeter/currencies/custom/{currencyId}/cost-bases` | Create a cost basis for a currency. |
208
+
209
+ ### Features
210
+
211
+ | Method | HTTP | Description |
212
+ | --------------------------- | ------------------------------------------------- | -------------------------------------------------------------------------- |
213
+ | `client.features.list` | `GET /openmeter/features` | List all features. |
214
+ | `client.features.create` | `POST /openmeter/features` | Create a feature. |
215
+ | `client.features.get` | `GET /openmeter/features/{featureId}` | Get a feature by id. |
216
+ | `client.features.update` | `PATCH /openmeter/features/{featureId}` | Update a feature by id. Currently only the unit_cost field can be updated. |
217
+ | `client.features.delete` | `DELETE /openmeter/features/{featureId}` | Delete a feature by id. |
218
+ | `client.features.queryCost` | `POST /openmeter/features/{featureId}/cost/query` | Query the cost of a feature. |
219
+
220
+ ### LLMCost
221
+
222
+ | Method | HTTP | Description |
223
+ | ------------------------------- | ------------------------------------------------ | ------------------------------------------------------------------------------------- |
224
+ | `client.llmCost.listPrices` | `GET /openmeter/llm-cost/prices` | List global LLM cost prices. Returns prices with overrides applied if any. |
225
+ | `client.llmCost.getPrice` | `GET /openmeter/llm-cost/prices/{priceId}` | Get a specific LLM cost price by ID. Returns the price with overrides applied if any. |
226
+ | `client.llmCost.listOverrides` | `GET /openmeter/llm-cost/overrides` | List per-namespace price overrides. |
227
+ | `client.llmCost.createOverride` | `POST /openmeter/llm-cost/overrides` | Create a per-namespace price override. |
228
+ | `client.llmCost.deleteOverride` | `DELETE /openmeter/llm-cost/overrides/{priceId}` | Delete a per-namespace price override. |
229
+
230
+ ### Plans
231
+
232
+ | Method | HTTP | Description |
233
+ | ---------------------- | ---------------------------------------- | ----------------------- |
234
+ | `client.plans.list` | `GET /openmeter/plans` | List all plans. |
235
+ | `client.plans.create` | `POST /openmeter/plans` | Create a new plan. |
236
+ | `client.plans.update` | `PUT /openmeter/plans/{planId}` | Update a plan by id. |
237
+ | `client.plans.get` | `GET /openmeter/plans/{planId}` | Get a plan by id. |
238
+ | `client.plans.delete` | `DELETE /openmeter/plans/{planId}` | Delete a plan by id. |
239
+ | `client.plans.archive` | `POST /openmeter/plans/{planId}/archive` | Archive a plan version. |
240
+ | `client.plans.publish` | `POST /openmeter/plans/{planId}/publish` | Publish a plan version. |
241
+
242
+ ### Addons
243
+
244
+ | Method | HTTP | Description |
245
+ | ----------------------- | ------------------------------------------ | -------------------------- |
246
+ | `client.addons.list` | `GET /openmeter/addons` | List all add-ons. |
247
+ | `client.addons.create` | `POST /openmeter/addons` | Create a new add-on. |
248
+ | `client.addons.update` | `PUT /openmeter/addons/{addonId}` | Update an add-on by id. |
249
+ | `client.addons.get` | `GET /openmeter/addons/{addonId}` | Get add-on by id. |
250
+ | `client.addons.delete` | `DELETE /openmeter/addons/{addonId}` | Soft delete add-on by id. |
251
+ | `client.addons.archive` | `POST /openmeter/addons/{addonId}/archive` | Archive an add-on version. |
252
+ | `client.addons.publish` | `POST /openmeter/addons/{addonId}/publish` | Publish an add-on version. |
253
+
254
+ ### PlanAddons
255
+
256
+ | Method | HTTP | Description |
257
+ | -------------------------- | ------------------------------------------------------- | ---------------------------------------- |
258
+ | `client.planAddons.list` | `GET /openmeter/plans/{planId}/addons` | List add-ons associated with a plan. |
259
+ | `client.planAddons.create` | `POST /openmeter/plans/{planId}/addons` | Add an add-on to a plan. |
260
+ | `client.planAddons.get` | `GET /openmeter/plans/{planId}/addons/{planAddonId}` | Get an add-on association for a plan. |
261
+ | `client.planAddons.update` | `PUT /openmeter/plans/{planId}/addons/{planAddonId}` | Update an add-on association for a plan. |
262
+ | `client.planAddons.delete` | `DELETE /openmeter/plans/{planId}/addons/{planAddonId}` | Remove an add-on from a plan. |
263
+
264
+ ### Defaults
265
+
266
+ | Method | HTTP | Description |
267
+ | -------------------------------------------- | ----------------------------------- | ----------- |
268
+ | `client.defaults.getOrganizationTaxCodes` | `GET /openmeter/defaults/tax-codes` | |
269
+ | `client.defaults.updateOrganizationTaxCodes` | `PUT /openmeter/defaults/tax-codes` | |
270
+
271
+ ### Governance
272
+
273
+ | Method | HTTP | Description |
274
+ | ------------------------------- | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
275
+ | `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._ |
276
+
277
+ ## Error Handling
278
+
279
+ A non-2xx response rejects with an `HTTPError` carrying the problem-details
280
+ fields (`status`, `type`, `title`, `url`) from the response.
281
+
282
+ ```typescript
283
+ import { OpenMeter, HTTPError } from '@openmeter/client'
284
+
285
+ const client = new OpenMeter({
286
+ baseUrl: 'https://openmeter.cloud/api/v3',
287
+ apiKey: process.env.OPENMETER_API_KEY,
288
+ })
289
+
290
+ try {
291
+ await client.meters.get({ meterId: 'unknown' })
292
+ } catch (error) {
293
+ if (error instanceof HTTPError) {
294
+ console.error(error.status, error.title, error.type)
295
+ }
296
+ }
297
+ ```
298
+
299
+ ## Standalone Functions
300
+
301
+ Every method is also available as a standalone, tree-shakeable function
302
+ that takes a `Client` and returns a `Result` instead of throwing.
303
+
304
+ ```typescript
305
+ import { Client, funcs } from '@openmeter/client'
306
+
307
+ const client = new Client({
308
+ baseUrl: 'https://openmeter.cloud/api/v3',
309
+ apiKey: process.env.OPENMETER_API_KEY,
310
+ })
311
+
312
+ const result = await funcs.listMeters(client)
313
+ if (result.ok) {
314
+ console.log(result.value)
315
+ } else {
316
+ console.error(result.error)
317
+ }
318
+ ```
package/dist/core.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { type KyInstance as HTTPClient } from 'ky';
2
+ import { type SDKOptions } from './lib/config.js';
3
+ export declare class Client {
4
+ readonly _options: SDKOptions;
5
+ readonly _http: HTTPClient;
6
+ constructor(options: SDKOptions);
7
+ }
8
+ export declare function http(client: Client): HTTPClient;
9
+ export type { HTTPClient };
10
+ //# sourceMappingURL=core.d.ts.map
package/dist/core.js ADDED
@@ -0,0 +1,38 @@
1
+ import ky from 'ky';
2
+ import { encodePath } from './lib/encodings.js';
3
+ export class Client {
4
+ _options;
5
+ _http;
6
+ constructor(options) {
7
+ this._options = options;
8
+ let baseUrl = typeof options.baseUrl === 'string'
9
+ ? encodePath(options.baseUrl, options.serverVariables ?? {})
10
+ : String(options.baseUrl);
11
+ if (!baseUrl.endsWith('/')) {
12
+ baseUrl = `${baseUrl}/`;
13
+ }
14
+ this._http = ky.create({
15
+ ...options,
16
+ baseUrl,
17
+ prefix: undefined,
18
+ hooks: {
19
+ ...options.hooks,
20
+ beforeRequest: [
21
+ ...(options.hooks?.beforeRequest ?? []),
22
+ async ({ request }) => {
23
+ const token = typeof options.apiKey === 'function'
24
+ ? await options.apiKey()
25
+ : options.apiKey;
26
+ if (token) {
27
+ request.headers.set('Authorization', `Bearer ${token}`);
28
+ }
29
+ },
30
+ ],
31
+ },
32
+ });
33
+ }
34
+ }
35
+ export function http(client) {
36
+ return client._http;
37
+ }
38
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1,11 @@
1
+ import { type Client } from '../core.js';
2
+ import { type Result, type RequestOptions } from '../lib/types.js';
3
+ import type { ListAddonsRequest, ListAddonsResponse, CreateAddonRequest, CreateAddonResponse, UpdateAddonRequest, UpdateAddonResponse, GetAddonRequest, GetAddonResponse, DeleteAddonRequest, DeleteAddonResponse, ArchiveAddonRequest, ArchiveAddonResponse, PublishAddonRequest, PublishAddonResponse } from '../models/operations/addons.js';
4
+ export declare function listAddons(client: Client, req?: ListAddonsRequest, options?: RequestOptions): Promise<Result<ListAddonsResponse>>;
5
+ export declare function createAddon(client: Client, req: CreateAddonRequest, options?: RequestOptions): Promise<Result<CreateAddonResponse>>;
6
+ export declare function updateAddon(client: Client, req: UpdateAddonRequest, options?: RequestOptions): Promise<Result<UpdateAddonResponse>>;
7
+ export declare function getAddon(client: Client, req: GetAddonRequest, options?: RequestOptions): Promise<Result<GetAddonResponse>>;
8
+ export declare function deleteAddon(client: Client, req: DeleteAddonRequest, options?: RequestOptions): Promise<Result<DeleteAddonResponse>>;
9
+ export declare function archiveAddon(client: Client, req: ArchiveAddonRequest, options?: RequestOptions): Promise<Result<ArchiveAddonResponse>>;
10
+ export declare function publishAddon(client: Client, req: PublishAddonRequest, options?: RequestOptions): Promise<Result<PublishAddonResponse>>;
11
+ //# sourceMappingURL=addons.d.ts.map
@@ -0,0 +1,53 @@
1
+ import { http } from '../core.js';
2
+ import { request } from '../lib/request.js';
3
+ import { encodePath, toURLSearchParams, encodeSort } from '../lib/encodings.js';
4
+ export function listAddons(client, req = {}, options) {
5
+ const searchParams = toURLSearchParams({
6
+ page: req.page,
7
+ sort: encodeSort(req.sort),
8
+ filter: req.filter,
9
+ });
10
+ return request(() => http(client)
11
+ .get('openmeter/addons', { ...options, searchParams })
12
+ .json());
13
+ }
14
+ export function createAddon(client, req, options) {
15
+ return request(() => http(client)
16
+ .post('openmeter/addons', { ...options, json: req })
17
+ .json());
18
+ }
19
+ export function updateAddon(client, req, options) {
20
+ const path = encodePath('openmeter/addons/{addonId}', {
21
+ addonId: req.addonId,
22
+ });
23
+ return request(() => http(client)
24
+ .put(path, { ...options, json: req.body })
25
+ .json());
26
+ }
27
+ export function getAddon(client, req, options) {
28
+ const path = encodePath('openmeter/addons/{addonId}', {
29
+ addonId: req.addonId,
30
+ });
31
+ return request(() => http(client).get(path, options).json());
32
+ }
33
+ export function deleteAddon(client, req, options) {
34
+ const path = encodePath('openmeter/addons/{addonId}', {
35
+ addonId: req.addonId,
36
+ });
37
+ return request(async () => {
38
+ await http(client).delete(path, options);
39
+ });
40
+ }
41
+ export function archiveAddon(client, req, options) {
42
+ const path = encodePath('openmeter/addons/{addonId}/archive', {
43
+ addonId: req.addonId,
44
+ });
45
+ return request(() => http(client).post(path, options).json());
46
+ }
47
+ export function publishAddon(client, req, options) {
48
+ const path = encodePath('openmeter/addons/{addonId}/publish', {
49
+ addonId: req.addonId,
50
+ });
51
+ return request(() => http(client).post(path, options).json());
52
+ }
53
+ //# sourceMappingURL=addons.js.map
@@ -0,0 +1,6 @@
1
+ import { type Client } from '../core.js';
2
+ import { type Result, type RequestOptions } from '../lib/types.js';
3
+ import type { ListAppsRequest, ListAppsResponse, GetAppRequest, GetAppResponse } from '../models/operations/apps.js';
4
+ export declare function listApps(client: Client, req?: ListAppsRequest, options?: RequestOptions): Promise<Result<ListAppsResponse>>;
5
+ export declare function getApp(client: Client, req: GetAppRequest, options?: RequestOptions): Promise<Result<GetAppResponse>>;
6
+ //# sourceMappingURL=apps.d.ts.map
@@ -0,0 +1,16 @@
1
+ import { http } from '../core.js';
2
+ import { request } from '../lib/request.js';
3
+ import { encodePath, toURLSearchParams } from '../lib/encodings.js';
4
+ export function listApps(client, req = {}, options) {
5
+ const searchParams = toURLSearchParams({
6
+ page: req.page,
7
+ });
8
+ return request(() => http(client)
9
+ .get('openmeter/apps', { ...options, searchParams })
10
+ .json());
11
+ }
12
+ export function getApp(client, req, options) {
13
+ const path = encodePath('openmeter/apps/{appId}', { appId: req.appId });
14
+ return request(() => http(client).get(path, options).json());
15
+ }
16
+ //# sourceMappingURL=apps.js.map
@@ -0,0 +1,9 @@
1
+ import { type Client } from '../core.js';
2
+ import { type Result, type RequestOptions } from '../lib/types.js';
3
+ import type { ListBillingProfilesRequest, ListBillingProfilesResponse, CreateBillingProfileRequest, CreateBillingProfileResponse, GetBillingProfileRequest, GetBillingProfileResponse, UpdateBillingProfileRequest, UpdateBillingProfileResponse, DeleteBillingProfileRequest, DeleteBillingProfileResponse } from '../models/operations/billing.js';
4
+ export declare function listBillingProfiles(client: Client, req?: ListBillingProfilesRequest, options?: RequestOptions): Promise<Result<ListBillingProfilesResponse>>;
5
+ export declare function createBillingProfile(client: Client, req: CreateBillingProfileRequest, options?: RequestOptions): Promise<Result<CreateBillingProfileResponse>>;
6
+ export declare function getBillingProfile(client: Client, req: GetBillingProfileRequest, options?: RequestOptions): Promise<Result<GetBillingProfileResponse>>;
7
+ export declare function updateBillingProfile(client: Client, req: UpdateBillingProfileRequest, options?: RequestOptions): Promise<Result<UpdateBillingProfileResponse>>;
8
+ export declare function deleteBillingProfile(client: Client, req: DeleteBillingProfileRequest, options?: RequestOptions): Promise<Result<DeleteBillingProfileResponse>>;
9
+ //# sourceMappingURL=billing.d.ts.map
@@ -0,0 +1,33 @@
1
+ import { http } from '../core.js';
2
+ import { request } from '../lib/request.js';
3
+ import { encodePath, toURLSearchParams } from '../lib/encodings.js';
4
+ export function listBillingProfiles(client, req = {}, options) {
5
+ const searchParams = toURLSearchParams({
6
+ page: req.page,
7
+ });
8
+ return request(() => http(client)
9
+ .get('openmeter/profiles', { ...options, searchParams })
10
+ .json());
11
+ }
12
+ export function createBillingProfile(client, req, options) {
13
+ return request(() => http(client)
14
+ .post('openmeter/profiles', { ...options, json: req })
15
+ .json());
16
+ }
17
+ export function getBillingProfile(client, req, options) {
18
+ const path = encodePath('openmeter/profiles/{id}', { id: req.id });
19
+ return request(() => http(client).get(path, options).json());
20
+ }
21
+ export function updateBillingProfile(client, req, options) {
22
+ const path = encodePath('openmeter/profiles/{id}', { id: req.id });
23
+ return request(() => http(client)
24
+ .put(path, { ...options, json: req.body })
25
+ .json());
26
+ }
27
+ export function deleteBillingProfile(client, req, options) {
28
+ const path = encodePath('openmeter/profiles/{id}', { id: req.id });
29
+ return request(async () => {
30
+ await http(client).delete(path, options);
31
+ });
32
+ }
33
+ //# sourceMappingURL=billing.js.map
@@ -0,0 +1,8 @@
1
+ import { type Client } from '../core.js';
2
+ import { type Result, type RequestOptions } from '../lib/types.js';
3
+ import type { ListCurrenciesRequest, ListCurrenciesResponse, CreateCustomCurrencyRequest, CreateCustomCurrencyResponse, ListCostBasesRequest, ListCostBasesResponse, CreateCostBasisRequest, CreateCostBasisResponse } from '../models/operations/currencies.js';
4
+ export declare function listCurrencies(client: Client, req?: ListCurrenciesRequest, options?: RequestOptions): Promise<Result<ListCurrenciesResponse>>;
5
+ export declare function createCustomCurrency(client: Client, req: CreateCustomCurrencyRequest, options?: RequestOptions): Promise<Result<CreateCustomCurrencyResponse>>;
6
+ export declare function listCostBases(client: Client, req: ListCostBasesRequest, options?: RequestOptions): Promise<Result<ListCostBasesResponse>>;
7
+ export declare function createCostBasis(client: Client, req: CreateCostBasisRequest, options?: RequestOptions): Promise<Result<CreateCostBasisResponse>>;
8
+ //# sourceMappingURL=currencies.d.ts.map
@@ -0,0 +1,35 @@
1
+ import { http } from '../core.js';
2
+ import { request } from '../lib/request.js';
3
+ import { encodePath, toURLSearchParams, encodeSort } from '../lib/encodings.js';
4
+ export function listCurrencies(client, req = {}, options) {
5
+ const searchParams = toURLSearchParams({
6
+ page: req.page,
7
+ sort: encodeSort(req.sort),
8
+ filter: req.filter,
9
+ });
10
+ return request(() => http(client)
11
+ .get('openmeter/currencies', { ...options, searchParams })
12
+ .json());
13
+ }
14
+ export function createCustomCurrency(client, req, options) {
15
+ return request(() => http(client)
16
+ .post('openmeter/currencies/custom', { ...options, json: req })
17
+ .json());
18
+ }
19
+ export function listCostBases(client, req, options) {
20
+ const searchParams = toURLSearchParams({
21
+ filter: req.filter,
22
+ page: req.page,
23
+ });
24
+ const path = encodePath('openmeter/currencies/custom/{currencyId}/cost-bases', { currencyId: req.currencyId });
25
+ return request(() => http(client)
26
+ .get(path, { ...options, searchParams })
27
+ .json());
28
+ }
29
+ export function createCostBasis(client, req, options) {
30
+ const path = encodePath('openmeter/currencies/custom/{currencyId}/cost-bases', { currencyId: req.currencyId });
31
+ return request(() => http(client)
32
+ .post(path, { ...options, json: req.body })
33
+ .json());
34
+ }
35
+ //# sourceMappingURL=currencies.js.map
@@ -0,0 +1,21 @@
1
+ import { type Client } from '../core.js';
2
+ import { type Result, type RequestOptions } from '../lib/types.js';
3
+ import type { CreateCustomerRequest, CreateCustomerResponse, GetCustomerRequest, GetCustomerResponse, ListCustomersRequest, ListCustomersResponse, UpsertCustomerRequest, UpsertCustomerResponse, DeleteCustomerRequest, DeleteCustomerResponse, GetCustomerBillingRequest, GetCustomerBillingResponse, UpdateCustomerBillingRequest, UpdateCustomerBillingResponse, UpdateCustomerBillingAppDataRequest, UpdateCustomerBillingAppDataResponse, CreateCustomerStripeCheckoutSessionRequest, CreateCustomerStripeCheckoutSessionResponse, CreateCustomerStripePortalSessionRequest, CreateCustomerStripePortalSessionResponse, CreateCreditGrantRequest, CreateCreditGrantResponse, GetCreditGrantRequest, GetCreditGrantResponse, ListCreditGrantsRequest, ListCreditGrantsResponse, GetCustomerCreditBalanceRequest, GetCustomerCreditBalanceResponse, CreateCreditAdjustmentRequest, CreateCreditAdjustmentResponse, ListCreditTransactionsRequest, ListCreditTransactionsResponse, ListCustomerChargesRequest, ListCustomerChargesResponse } from '../models/operations/customers.js';
4
+ export declare function createCustomer(client: Client, req: CreateCustomerRequest, options?: RequestOptions): Promise<Result<CreateCustomerResponse>>;
5
+ export declare function getCustomer(client: Client, req: GetCustomerRequest, options?: RequestOptions): Promise<Result<GetCustomerResponse>>;
6
+ export declare function listCustomers(client: Client, req?: ListCustomersRequest, options?: RequestOptions): Promise<Result<ListCustomersResponse>>;
7
+ export declare function upsertCustomer(client: Client, req: UpsertCustomerRequest, options?: RequestOptions): Promise<Result<UpsertCustomerResponse>>;
8
+ export declare function deleteCustomer(client: Client, req: DeleteCustomerRequest, options?: RequestOptions): Promise<Result<DeleteCustomerResponse>>;
9
+ export declare function getCustomerBilling(client: Client, req: GetCustomerBillingRequest, options?: RequestOptions): Promise<Result<GetCustomerBillingResponse>>;
10
+ export declare function updateCustomerBilling(client: Client, req: UpdateCustomerBillingRequest, options?: RequestOptions): Promise<Result<UpdateCustomerBillingResponse>>;
11
+ export declare function updateCustomerBillingAppData(client: Client, req: UpdateCustomerBillingAppDataRequest, options?: RequestOptions): Promise<Result<UpdateCustomerBillingAppDataResponse>>;
12
+ export declare function createCustomerStripeCheckoutSession(client: Client, req: CreateCustomerStripeCheckoutSessionRequest, options?: RequestOptions): Promise<Result<CreateCustomerStripeCheckoutSessionResponse>>;
13
+ export declare function createCustomerStripePortalSession(client: Client, req: CreateCustomerStripePortalSessionRequest, options?: RequestOptions): Promise<Result<CreateCustomerStripePortalSessionResponse>>;
14
+ export declare function createCreditGrant(client: Client, req: CreateCreditGrantRequest, options?: RequestOptions): Promise<Result<CreateCreditGrantResponse>>;
15
+ export declare function getCreditGrant(client: Client, req: GetCreditGrantRequest, options?: RequestOptions): Promise<Result<GetCreditGrantResponse>>;
16
+ export declare function listCreditGrants(client: Client, req: ListCreditGrantsRequest, options?: RequestOptions): Promise<Result<ListCreditGrantsResponse>>;
17
+ export declare function getCustomerCreditBalance(client: Client, req: GetCustomerCreditBalanceRequest, options?: RequestOptions): Promise<Result<GetCustomerCreditBalanceResponse>>;
18
+ export declare function createCreditAdjustment(client: Client, req: CreateCreditAdjustmentRequest, options?: RequestOptions): Promise<Result<CreateCreditAdjustmentResponse>>;
19
+ export declare function listCreditTransactions(client: Client, req: ListCreditTransactionsRequest, options?: RequestOptions): Promise<Result<ListCreditTransactionsResponse>>;
20
+ export declare function listCustomerCharges(client: Client, req: ListCustomerChargesRequest, options?: RequestOptions): Promise<Result<ListCustomerChargesResponse>>;
21
+ //# sourceMappingURL=customers.d.ts.map