@paygentic/sdk 0.6.33 → 0.6.36
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/FUNCTIONS.md +13 -9
- package/README.md +97 -48
- package/dist/commonjs/lib/config.d.ts +2 -2
- package/dist/commonjs/lib/config.js +2 -2
- package/dist/esm/lib/config.d.ts +2 -2
- package/dist/esm/lib/config.js +2 -2
- package/examples/customersCreate.example.ts +37 -0
- package/jsr.json +6 -4
- package/package.json +1 -1
- package/src/lib/config.ts +2 -2
package/FUNCTIONS.md
CHANGED
|
@@ -20,7 +20,7 @@ specific category of applications.
|
|
|
20
20
|
|
|
21
21
|
```typescript
|
|
22
22
|
import { PaygenticCore } from "@paygentic/sdk/core.js";
|
|
23
|
-
import {
|
|
23
|
+
import { customersCreate } from "@paygentic/sdk/funcs/customersCreate.js";
|
|
24
24
|
|
|
25
25
|
// Use `PaygenticCore` for best tree-shaking performance.
|
|
26
26
|
// You can create one instance of it to use across an application.
|
|
@@ -29,19 +29,23 @@ const paygentic = new PaygenticCore({
|
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
async function run() {
|
|
32
|
-
const res = await
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
const res = await customersCreate(paygentic, {
|
|
33
|
+
consumer: {
|
|
34
|
+
name: "Jane Smith",
|
|
35
|
+
email: "jane@example.com",
|
|
36
|
+
address: {
|
|
37
|
+
city: "San Francisco",
|
|
38
|
+
state: "CA",
|
|
39
|
+
country: "US",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
merchantId: "org_YS8jkP59V71TdUvj",
|
|
39
43
|
});
|
|
40
44
|
if (res.ok) {
|
|
41
45
|
const { value: result } = res;
|
|
42
46
|
console.log(result);
|
|
43
47
|
} else {
|
|
44
|
-
console.log("
|
|
48
|
+
console.log("customersCreate failed:", res.error);
|
|
45
49
|
}
|
|
46
50
|
}
|
|
47
51
|
|
package/README.md
CHANGED
|
@@ -14,31 +14,19 @@ Developer-friendly & type-safe Typescript SDK specifically catered to leverage *
|
|
|
14
14
|
<!-- Start Summary [summary] -->
|
|
15
15
|
## Summary
|
|
16
16
|
|
|
17
|
-
Paygentic API: The Paygentic API provides
|
|
17
|
+
Paygentic API: The Paygentic API provides billing infrastructure for usage-based and subscription monetization — customers, subscriptions, usage metering, invoicing, entitlements, and payments.
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
All API requests require authentication using an API key passed in the `Authorization` header:
|
|
21
|
-
```
|
|
22
|
-
Authorization: Bearer YOUR_API_KEY
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Base URL
|
|
26
|
-
All API requests should be made to:
|
|
27
|
-
```
|
|
28
|
-
https://api.paygentic.io/v0
|
|
29
|
-
```
|
|
19
|
+
See the [Quickstart](https://docs.paygentic.io/getting-started/quickstart) to go from zero to billing in a handful of steps.
|
|
30
20
|
<!-- End Summary [summary] -->
|
|
31
21
|
|
|
32
22
|
<!-- Start Table of Contents [toc] -->
|
|
33
23
|
## Table of Contents
|
|
34
24
|
<!-- $toc-max-depth=2 -->
|
|
35
25
|
* [paygentic](#paygentic)
|
|
36
|
-
* [Authentication](#authentication)
|
|
37
|
-
* [Base URL](#base-url)
|
|
38
26
|
* [SDK Installation](#sdk-installation)
|
|
39
27
|
* [Requirements](#requirements)
|
|
40
28
|
* [SDK Example Usage](#sdk-example-usage)
|
|
41
|
-
* [Authentication](#authentication
|
|
29
|
+
* [Authentication](#authentication)
|
|
42
30
|
* [Available Resources and Operations](#available-resources-and-operations)
|
|
43
31
|
* [Standalone functions](#standalone-functions)
|
|
44
32
|
* [Retries](#retries)
|
|
@@ -94,7 +82,9 @@ For supported JavaScript runtimes, please consult [RUNTIMES.md](RUNTIMES.md).
|
|
|
94
82
|
<!-- Start SDK Example Usage [usage] -->
|
|
95
83
|
## SDK Example Usage
|
|
96
84
|
|
|
97
|
-
###
|
|
85
|
+
### Create a customer
|
|
86
|
+
|
|
87
|
+
Create a customer for each organization you bill. This is the first step in the billing setup — see the [Quickstart](https://docs.paygentic.io/getting-started/quickstart) for the full flow.
|
|
98
88
|
|
|
99
89
|
```typescript
|
|
100
90
|
import { Paygentic } from "@paygentic/sdk";
|
|
@@ -104,13 +94,72 @@ const paygentic = new Paygentic({
|
|
|
104
94
|
});
|
|
105
95
|
|
|
106
96
|
async function run() {
|
|
107
|
-
const result = await paygentic.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
97
|
+
const result = await paygentic.customers.create({
|
|
98
|
+
consumer: {
|
|
99
|
+
name: "Jane Smith",
|
|
100
|
+
email: "jane@example.com",
|
|
101
|
+
address: {
|
|
102
|
+
city: "San Francisco",
|
|
103
|
+
state: "CA",
|
|
104
|
+
country: "US",
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
merchantId: "org_YS8jkP59V71TdUvj",
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
console.log(result);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
run();
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Create a subscription
|
|
118
|
+
|
|
119
|
+
Subscribe a customer to a plan. If the plan includes in-advance charges, Paygentic generates an initial invoice and the subscription activates once paid.
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { Paygentic } from "@paygentic/sdk";
|
|
123
|
+
|
|
124
|
+
const paygentic = new Paygentic({
|
|
125
|
+
bearerAuth: process.env["PAYGENTIC_BEARER_AUTH"] ?? "",
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
async function run() {
|
|
129
|
+
const result = await paygentic.subscriptions.create({
|
|
130
|
+
customerId: "cus_abc123",
|
|
131
|
+
name: "Monthly API Service",
|
|
132
|
+
planId: "plan_abc123",
|
|
133
|
+
startedAt: new Date("2024-01-15T00:00:00Z"),
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
console.log(result);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
run();
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Report usage
|
|
144
|
+
|
|
145
|
+
Send meter events to record consumption once a subscription is active. The endpoint is fire-and-forget — it always returns `202 Accepted`.
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
import { Paygentic } from "@paygentic/sdk";
|
|
149
|
+
|
|
150
|
+
const paygentic = new Paygentic({
|
|
151
|
+
bearerAuth: process.env["PAYGENTIC_BEARER_AUTH"] ?? "",
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
async function run() {
|
|
155
|
+
const result = await paygentic.events.ingest({
|
|
156
|
+
type: "ai.inference",
|
|
157
|
+
source: "https://api.myapp.com",
|
|
158
|
+
subject: "cus_abc123",
|
|
159
|
+
data: {
|
|
160
|
+
"tokens": 1500,
|
|
161
|
+
"model": "gpt-4o",
|
|
162
|
+
},
|
|
114
163
|
});
|
|
115
164
|
|
|
116
165
|
console.log(result);
|
|
@@ -143,11 +192,11 @@ const paygentic = new Paygentic({
|
|
|
143
192
|
async function run() {
|
|
144
193
|
const result = await paygentic.billableMetrics.create({
|
|
145
194
|
aggregation: "SUM",
|
|
146
|
-
description: "
|
|
147
|
-
merchantId: "
|
|
148
|
-
name: "
|
|
149
|
-
productId: "
|
|
150
|
-
unit: "
|
|
195
|
+
description: "Tracks total tokens consumed per API call.",
|
|
196
|
+
merchantId: "org_YS8jkP59V71TdUvj",
|
|
197
|
+
name: "Token Counter",
|
|
198
|
+
productId: "prod_abc123",
|
|
199
|
+
unit: "tokens",
|
|
151
200
|
});
|
|
152
201
|
|
|
153
202
|
console.log(result);
|
|
@@ -461,11 +510,11 @@ const paygentic = new Paygentic({
|
|
|
461
510
|
async function run() {
|
|
462
511
|
const result = await paygentic.billableMetrics.create({
|
|
463
512
|
aggregation: "SUM",
|
|
464
|
-
description: "
|
|
465
|
-
merchantId: "
|
|
466
|
-
name: "
|
|
467
|
-
productId: "
|
|
468
|
-
unit: "
|
|
513
|
+
description: "Tracks total tokens consumed per API call.",
|
|
514
|
+
merchantId: "org_YS8jkP59V71TdUvj",
|
|
515
|
+
name: "Token Counter",
|
|
516
|
+
productId: "prod_abc123",
|
|
517
|
+
unit: "tokens",
|
|
469
518
|
}, {
|
|
470
519
|
retries: {
|
|
471
520
|
strategy: "backoff",
|
|
@@ -507,11 +556,11 @@ const paygentic = new Paygentic({
|
|
|
507
556
|
async function run() {
|
|
508
557
|
const result = await paygentic.billableMetrics.create({
|
|
509
558
|
aggregation: "SUM",
|
|
510
|
-
description: "
|
|
511
|
-
merchantId: "
|
|
512
|
-
name: "
|
|
513
|
-
productId: "
|
|
514
|
-
unit: "
|
|
559
|
+
description: "Tracks total tokens consumed per API call.",
|
|
560
|
+
merchantId: "org_YS8jkP59V71TdUvj",
|
|
561
|
+
name: "Token Counter",
|
|
562
|
+
productId: "prod_abc123",
|
|
563
|
+
unit: "tokens",
|
|
515
564
|
});
|
|
516
565
|
|
|
517
566
|
console.log(result);
|
|
@@ -549,11 +598,11 @@ async function run() {
|
|
|
549
598
|
try {
|
|
550
599
|
const result = await paygentic.billableMetrics.create({
|
|
551
600
|
aggregation: "SUM",
|
|
552
|
-
description: "
|
|
553
|
-
merchantId: "
|
|
554
|
-
name: "
|
|
555
|
-
productId: "
|
|
556
|
-
unit: "
|
|
601
|
+
description: "Tracks total tokens consumed per API call.",
|
|
602
|
+
merchantId: "org_YS8jkP59V71TdUvj",
|
|
603
|
+
name: "Token Counter",
|
|
604
|
+
productId: "prod_abc123",
|
|
605
|
+
unit: "tokens",
|
|
557
606
|
});
|
|
558
607
|
|
|
559
608
|
console.log(result);
|
|
@@ -624,11 +673,11 @@ const paygentic = new Paygentic({
|
|
|
624
673
|
async function run() {
|
|
625
674
|
const result = await paygentic.billableMetrics.create({
|
|
626
675
|
aggregation: "SUM",
|
|
627
|
-
description: "
|
|
628
|
-
merchantId: "
|
|
629
|
-
name: "
|
|
630
|
-
productId: "
|
|
631
|
-
unit: "
|
|
676
|
+
description: "Tracks total tokens consumed per API call.",
|
|
677
|
+
merchantId: "org_YS8jkP59V71TdUvj",
|
|
678
|
+
name: "Token Counter",
|
|
679
|
+
productId: "prod_abc123",
|
|
680
|
+
unit: "tokens",
|
|
632
681
|
});
|
|
633
682
|
|
|
634
683
|
console.log(result);
|
|
@@ -31,8 +31,8 @@ export declare function serverURLFromOptions(options: SDKOptions): URL | null;
|
|
|
31
31
|
export declare const SDK_METADATA: {
|
|
32
32
|
readonly language: "typescript";
|
|
33
33
|
readonly openapiDocVersion: "0.1.0";
|
|
34
|
-
readonly sdkVersion: "0.6.
|
|
34
|
+
readonly sdkVersion: "0.6.36";
|
|
35
35
|
readonly genVersion: "2.879.13";
|
|
36
|
-
readonly userAgent: "speakeasy-sdk/typescript 0.6.
|
|
36
|
+
readonly userAgent: "speakeasy-sdk/typescript 0.6.36 2.879.13 0.1.0 @paygentic/sdk";
|
|
37
37
|
};
|
|
38
38
|
//# sourceMappingURL=config.d.ts.map
|
|
@@ -31,8 +31,8 @@ function serverURLFromOptions(options) {
|
|
|
31
31
|
exports.SDK_METADATA = {
|
|
32
32
|
language: "typescript",
|
|
33
33
|
openapiDocVersion: "0.1.0",
|
|
34
|
-
sdkVersion: "0.6.
|
|
34
|
+
sdkVersion: "0.6.36",
|
|
35
35
|
genVersion: "2.879.13",
|
|
36
|
-
userAgent: "speakeasy-sdk/typescript 0.6.
|
|
36
|
+
userAgent: "speakeasy-sdk/typescript 0.6.36 2.879.13 0.1.0 @paygentic/sdk",
|
|
37
37
|
};
|
|
38
38
|
//# sourceMappingURL=config.js.map
|
package/dist/esm/lib/config.d.ts
CHANGED
|
@@ -31,8 +31,8 @@ export declare function serverURLFromOptions(options: SDKOptions): URL | null;
|
|
|
31
31
|
export declare const SDK_METADATA: {
|
|
32
32
|
readonly language: "typescript";
|
|
33
33
|
readonly openapiDocVersion: "0.1.0";
|
|
34
|
-
readonly sdkVersion: "0.6.
|
|
34
|
+
readonly sdkVersion: "0.6.36";
|
|
35
35
|
readonly genVersion: "2.879.13";
|
|
36
|
-
readonly userAgent: "speakeasy-sdk/typescript 0.6.
|
|
36
|
+
readonly userAgent: "speakeasy-sdk/typescript 0.6.36 2.879.13 0.1.0 @paygentic/sdk";
|
|
37
37
|
};
|
|
38
38
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/esm/lib/config.js
CHANGED
|
@@ -27,8 +27,8 @@ export function serverURLFromOptions(options) {
|
|
|
27
27
|
export const SDK_METADATA = {
|
|
28
28
|
language: "typescript",
|
|
29
29
|
openapiDocVersion: "0.1.0",
|
|
30
|
-
sdkVersion: "0.6.
|
|
30
|
+
sdkVersion: "0.6.36",
|
|
31
31
|
genVersion: "2.879.13",
|
|
32
|
-
userAgent: "speakeasy-sdk/typescript 0.6.
|
|
32
|
+
userAgent: "speakeasy-sdk/typescript 0.6.36 2.879.13 0.1.0 @paygentic/sdk",
|
|
33
33
|
};
|
|
34
34
|
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import dotenv from "dotenv";
|
|
6
|
+
dotenv.config();
|
|
7
|
+
/**
|
|
8
|
+
* Example usage of the @paygentic/sdk SDK
|
|
9
|
+
*
|
|
10
|
+
* To run this example from the examples directory:
|
|
11
|
+
* npm run build && npx tsx customersCreate.example.ts
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { Paygentic } from "@paygentic/sdk";
|
|
15
|
+
|
|
16
|
+
const paygentic = new Paygentic({
|
|
17
|
+
bearerAuth: process.env["PAYGENTIC_BEARER_AUTH"] ?? "",
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
async function main() {
|
|
21
|
+
const result = await paygentic.customers.create({
|
|
22
|
+
consumer: {
|
|
23
|
+
name: "Jane Smith",
|
|
24
|
+
email: "jane@example.com",
|
|
25
|
+
address: {
|
|
26
|
+
city: "San Francisco",
|
|
27
|
+
state: "CA",
|
|
28
|
+
country: "US",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
merchantId: "org_YS8jkP59V71TdUvj",
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
console.log(result);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
main().catch(console.error);
|
package/jsr.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
1
3
|
{
|
|
2
4
|
"name": "@paygentic/sdk",
|
|
3
|
-
"version": "0.6.
|
|
5
|
+
"version": "0.6.36",
|
|
4
6
|
"exports": {
|
|
5
|
-
".": "./src/index.ts",
|
|
6
|
-
"./models/errors": "./src/models/errors/index.ts",
|
|
7
|
-
"./models": "./src/models/index.ts",
|
|
7
|
+
".": "./src/index.ts",
|
|
8
|
+
"./models/errors": "./src/models/errors/index.ts",
|
|
9
|
+
"./models": "./src/models/index.ts",
|
|
8
10
|
"./models/operations": "./src/models/operations/index.ts",
|
|
9
11
|
"./lib/config": "./src/lib/config.ts",
|
|
10
12
|
"./lib/http": "./src/lib/http.ts",
|
package/package.json
CHANGED
package/src/lib/config.ts
CHANGED
|
@@ -61,7 +61,7 @@ export function serverURLFromOptions(options: SDKOptions): URL | null {
|
|
|
61
61
|
export const SDK_METADATA = {
|
|
62
62
|
language: "typescript",
|
|
63
63
|
openapiDocVersion: "0.1.0",
|
|
64
|
-
sdkVersion: "0.6.
|
|
64
|
+
sdkVersion: "0.6.36",
|
|
65
65
|
genVersion: "2.879.13",
|
|
66
|
-
userAgent: "speakeasy-sdk/typescript 0.6.
|
|
66
|
+
userAgent: "speakeasy-sdk/typescript 0.6.36 2.879.13 0.1.0 @paygentic/sdk",
|
|
67
67
|
} as const;
|