agent-payments 0.1.1

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/README.md ADDED
@@ -0,0 +1,188 @@
1
+ # agent-pay
2
+
3
+ **The payments API for AI agents. No crypto. No complexity.**
4
+
5
+ A2A payments between agents = AgentPay. Human checkout flows = Stripe.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install agent-pay
11
+ ```
12
+
13
+ ## Quickstart
14
+
15
+ ```typescript
16
+ import { AgentPay, register } from 'agent-pay';
17
+
18
+ // Register your agent once
19
+ const { id, api_key } = await register({ name: 'My Bot', email: 'bot@example.com' });
20
+ // Save api_key securely — shown only once
21
+
22
+ const ap = new AgentPay(process.env.AGENTPAY_API_KEY);
23
+
24
+ // Send a payment
25
+ await ap.pay({ to: 'agent_abc123', amount: 0.50, purpose: 'tool usage fee' });
26
+
27
+ // Accept/request a payment (merchant side)
28
+ const request = await ap.accept({ amount: 0.50, purpose: 'data enrichment' });
29
+
30
+ // Check balance
31
+ const { balance } = await ap.balance(id);
32
+ console.log(`Balance: $${balance}`);
33
+ ```
34
+
35
+ ## When to use AgentPay vs Stripe
36
+
37
+ | Use case | Tool |
38
+ |----------|------|
39
+ | A2A payments between agents | **AgentPay** |
40
+ | Human checkout flows | Stripe |
41
+ | Crypto / blockchain | Neither |
42
+
43
+ ## Full API Reference
44
+
45
+ ### `new AgentPay(apiKey)`
46
+
47
+ Initialize the client with your API key.
48
+
49
+ ```typescript
50
+ const ap = new AgentPay(process.env.AGENTPAY_API_KEY);
51
+ ```
52
+
53
+ ### `register({ name, email })`
54
+
55
+ Register a new agent and get an API key. Call this once before you have a key.
56
+
57
+ ```typescript
58
+ import { register } from 'agent-pay';
59
+
60
+ const { id, api_key } = await register({ name: 'My Bot', email: 'bot@example.com' });
61
+ // Store api_key securely — shown only once
62
+ ```
63
+
64
+ ### `ap.pay({ to, amount, purpose? })`
65
+
66
+ Send a USD payment to another agent. Debits your wallet, credits theirs instantly.
67
+
68
+ ```typescript
69
+ await ap.pay({
70
+ to: 'agent_def456',
71
+ amount: 0.25,
72
+ purpose: 'Used parser tool',
73
+ });
74
+ ```
75
+
76
+ ### `ap.accept({ amount, purpose?, currency? })`
77
+
78
+ Create a payment request (merchant side). Use this when your agent is the one receiving payment.
79
+
80
+ ```typescript
81
+ const request = await ap.accept({
82
+ amount: 0.50,
83
+ purpose: 'data enrichment',
84
+ });
85
+ // Returns { id, amount, currency, purpose, status, created_at }
86
+ ```
87
+
88
+ ### `ap.balance(agentId)`
89
+
90
+ Get current wallet balance.
91
+
92
+ ```typescript
93
+ const { balance, currency } = await ap.balance('agent_abc123');
94
+ console.log(`Balance: $${balance}`);
95
+ ```
96
+
97
+ ### `ap.subscribe({ plan })`
98
+
99
+ Subscribe to Growth or Scale plan. Returns a Stripe Checkout URL.
100
+
101
+ ```typescript
102
+ const { checkout_url } = await ap.subscribe({ plan: 'growth' });
103
+ // Redirect user to checkout_url
104
+ ```
105
+
106
+ ### `ap.fund(agentId, { amount })`
107
+
108
+ Top up a wallet via Stripe Checkout.
109
+
110
+ ```typescript
111
+ const { checkout_url } = await ap.fund('agent_abc123', { amount: 10.00 });
112
+ ```
113
+
114
+ ### `ap.transactions({ limit?, offset? })`
115
+
116
+ List sent and received transactions.
117
+
118
+ ```typescript
119
+ const { transactions } = await ap.transactions({ limit: 20 });
120
+ ```
121
+
122
+ ## MCP Integration (Claude / Cursor)
123
+
124
+ ```json
125
+ {
126
+ "mcpServers": {
127
+ "agent-pay": {
128
+ "command": "npx",
129
+ "args": ["agent-pay-mcp"],
130
+ "env": {
131
+ "AGENTPAY_API_KEY": "your_key_here"
132
+ }
133
+ }
134
+ }
135
+ }
136
+ ```
137
+
138
+ ## Framework Examples
139
+
140
+ **LangChain (Python):**
141
+ ```python
142
+ from langchain.tools import tool
143
+
144
+ @tool
145
+ def pay_agent(to: str, amount: float, purpose: str) -> dict:
146
+ """Send a USD payment to another agent via AgentPay."""
147
+ import subprocess, json
148
+ result = subprocess.run(
149
+ ["node", "-e",
150
+ f"const {{AgentPay}}=require('agent-pay');"
151
+ f"new AgentPay(process.env.AGENTPAY_API_KEY)"
152
+ f".pay({{to:'{to}',amount:{amount},purpose:'{purpose}'}})"
153
+ f".then(r=>console.log(JSON.stringify(r)))"],
154
+ capture_output=True, text=True
155
+ )
156
+ return json.loads(result.stdout)
157
+ ```
158
+
159
+ **TypeScript / Node.js:**
160
+ ```typescript
161
+ import { AgentPay, register } from 'agent-pay';
162
+
163
+ const ap = new AgentPay(process.env.AGENTPAY_API_KEY!);
164
+ await ap.pay({ to: 'agent_xyz', amount: 0.10, purpose: 'API call fee' });
165
+ ```
166
+
167
+ **AutoGen / CrewAI:**
168
+ ```python
169
+ import os
170
+ from agent_pay_client import AgentPayClient # thin wrapper
171
+
172
+ ap = AgentPayClient(os.environ["AGENTPAY_API_KEY"])
173
+ ap.pay(to="agent_xyz", amount=0.05, purpose="web search fee")
174
+ ```
175
+
176
+ ## Pricing
177
+
178
+ | Tier | Price | Transactions |
179
+ |------|-------|-------------|
180
+ | Starter | $29/mo | 1,000/mo |
181
+ | Growth | $99/mo | 10,000/mo |
182
+ | Scale | $299/mo | Unlimited |
183
+
184
+ ## Links
185
+
186
+ - **Docs:** [https://agent-pay.pro/docs](https://agent-pay.pro/docs)
187
+ - **Dashboard:** [https://agent-pay.pro](https://agent-pay.pro)
188
+ - **npm:** [https://www.npmjs.com/package/agent-pay](https://www.npmjs.com/package/agent-pay)
@@ -0,0 +1,181 @@
1
+ /**
2
+ * agent-payments SDK
3
+ * The simplest way to add USD payments between AI agents. Powered by Stripe.
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * import { AgentPay } from 'agent-payments';
8
+ *
9
+ * const ap = new AgentPay(process.env.AGENTPAY_API_KEY);
10
+ *
11
+ * // Send a payment
12
+ * await ap.pay({ to: 'agent_abc123', amount: 0.50, purpose: 'tool usage fee' });
13
+ *
14
+ * // Accept a payment (merchant side)
15
+ * await ap.accept({ amount: 0.50, purpose: 'data enrichment' });
16
+ *
17
+ * // Check balance
18
+ * const { balance } = await ap.balance('your_agent_id');
19
+ * ```
20
+ */
21
+ interface AgentPayConfig {
22
+ /** Your AgentPay API key (sk_live_...) */
23
+ apiKey: string;
24
+ /** Base URL of the AgentPay API. Defaults to https://agent-pay.pro */
25
+ baseUrl?: string;
26
+ }
27
+ interface Agent {
28
+ id: string;
29
+ name: string;
30
+ email: string;
31
+ balance: number;
32
+ currency: string;
33
+ stripe_connected: boolean;
34
+ created_at: string;
35
+ }
36
+ interface RegisterParams {
37
+ name: string;
38
+ email: string;
39
+ }
40
+ interface RegisterResult extends Agent {
41
+ /** API key — returned only on registration. Store it securely. */
42
+ api_key: string;
43
+ }
44
+ interface PayParams {
45
+ /** Recipient agent ID */
46
+ to: string;
47
+ /** Amount in USD (e.g. 0.25 = $0.25) */
48
+ amount: number;
49
+ /** Optional human-readable purpose */
50
+ purpose?: string;
51
+ /** Currency code. Defaults to 'usd' */
52
+ currency?: string;
53
+ }
54
+ interface PayResult {
55
+ id: string;
56
+ from_agent_id: string;
57
+ to_agent_id: string;
58
+ amount: number;
59
+ currency: string;
60
+ purpose: string | null;
61
+ status: string;
62
+ stripe_payment_intent_id: string;
63
+ client_secret: string;
64
+ created_at: string;
65
+ }
66
+ interface SubscribeParams {
67
+ /** Plan to subscribe to: 'growth' | 'scale' */
68
+ plan: 'growth' | 'scale';
69
+ }
70
+ interface SubscribeResult {
71
+ checkout_url: string;
72
+ session_id: string;
73
+ }
74
+ interface BalanceResult {
75
+ agent_id: string;
76
+ balance: number;
77
+ currency: string;
78
+ }
79
+ interface FundParams {
80
+ /** Amount in USD to add to wallet */
81
+ amount: number;
82
+ }
83
+ interface FundResult {
84
+ checkout_url: string;
85
+ }
86
+ interface AcceptParams {
87
+ /** Amount in USD to request */
88
+ amount: number;
89
+ /** Optional human-readable purpose */
90
+ purpose?: string;
91
+ /** Currency code. Defaults to 'usd' */
92
+ currency?: string;
93
+ }
94
+ interface AcceptResult {
95
+ id: string;
96
+ amount: number;
97
+ currency: string;
98
+ purpose: string | null;
99
+ status: string;
100
+ created_at: string;
101
+ }
102
+ interface Transaction {
103
+ id: string;
104
+ from_agent_id: string | null;
105
+ to_agent_id: string | null;
106
+ amount: number;
107
+ currency: string;
108
+ purpose: string | null;
109
+ status: string;
110
+ stripe_status?: string;
111
+ created_at: string;
112
+ }
113
+ declare class AgentPayError extends Error {
114
+ status: number;
115
+ constructor(message: string, status: number);
116
+ }
117
+ declare class AgentPay {
118
+ private apiKey;
119
+ private baseUrl;
120
+ constructor(config: string | AgentPayConfig);
121
+ private request;
122
+ /**
123
+ * Send a payment to another agent.
124
+ * Debits your wallet and credits the recipient instantly.
125
+ */
126
+ pay(params: PayParams): Promise<PayResult>;
127
+ /**
128
+ * Create a payment request (merchant side).
129
+ * Use this when your agent is receiving payment for a service.
130
+ */
131
+ accept(params: AcceptParams): Promise<AcceptResult>;
132
+ /**
133
+ * Subscribe to a Growth or Scale plan via Stripe Checkout.
134
+ * Returns a checkout_url — redirect the user there to complete payment.
135
+ */
136
+ subscribe(params: SubscribeParams): Promise<SubscribeResult>;
137
+ /**
138
+ * Get the current balance for an agent.
139
+ */
140
+ balance(agentId: string): Promise<BalanceResult>;
141
+ /**
142
+ * Fund an agent wallet via Stripe Checkout.
143
+ * Returns a checkout_url — redirect the user there to complete payment.
144
+ */
145
+ fund(agentId: string, params: FundParams): Promise<FundResult>;
146
+ /**
147
+ * Get a specific payment/transaction by ID.
148
+ */
149
+ getPayment(id: string): Promise<Transaction>;
150
+ /**
151
+ * List transactions for the authenticated agent (sent and received).
152
+ */
153
+ transactions(params?: {
154
+ limit?: number;
155
+ offset?: number;
156
+ }): Promise<{
157
+ transactions: Transaction[];
158
+ pagination: {
159
+ limit: number;
160
+ offset: number;
161
+ };
162
+ }>;
163
+ }
164
+
165
+ /**
166
+ * Register a new agent and get an API key.
167
+ * Static helper — use before you have an API key.
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * const { id, api_key } = await register(
172
+ * { name: 'My Bot', email: 'bot@example.com' }
173
+ * );
174
+ * const ap = new AgentPay(api_key);
175
+ * ```
176
+ */
177
+ declare function register(params: RegisterParams, config?: {
178
+ baseUrl?: string;
179
+ }): Promise<RegisterResult>;
180
+
181
+ export { type AcceptParams, type AcceptResult, type Agent, AgentPay, type AgentPayConfig, AgentPayError, type BalanceResult, type FundParams, type FundResult, type PayParams, type PayResult, type RegisterParams, type RegisterResult, type SubscribeParams, type SubscribeResult, type Transaction, AgentPay as default, register };
@@ -0,0 +1,181 @@
1
+ /**
2
+ * agent-payments SDK
3
+ * The simplest way to add USD payments between AI agents. Powered by Stripe.
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * import { AgentPay } from 'agent-payments';
8
+ *
9
+ * const ap = new AgentPay(process.env.AGENTPAY_API_KEY);
10
+ *
11
+ * // Send a payment
12
+ * await ap.pay({ to: 'agent_abc123', amount: 0.50, purpose: 'tool usage fee' });
13
+ *
14
+ * // Accept a payment (merchant side)
15
+ * await ap.accept({ amount: 0.50, purpose: 'data enrichment' });
16
+ *
17
+ * // Check balance
18
+ * const { balance } = await ap.balance('your_agent_id');
19
+ * ```
20
+ */
21
+ interface AgentPayConfig {
22
+ /** Your AgentPay API key (sk_live_...) */
23
+ apiKey: string;
24
+ /** Base URL of the AgentPay API. Defaults to https://agent-pay.pro */
25
+ baseUrl?: string;
26
+ }
27
+ interface Agent {
28
+ id: string;
29
+ name: string;
30
+ email: string;
31
+ balance: number;
32
+ currency: string;
33
+ stripe_connected: boolean;
34
+ created_at: string;
35
+ }
36
+ interface RegisterParams {
37
+ name: string;
38
+ email: string;
39
+ }
40
+ interface RegisterResult extends Agent {
41
+ /** API key — returned only on registration. Store it securely. */
42
+ api_key: string;
43
+ }
44
+ interface PayParams {
45
+ /** Recipient agent ID */
46
+ to: string;
47
+ /** Amount in USD (e.g. 0.25 = $0.25) */
48
+ amount: number;
49
+ /** Optional human-readable purpose */
50
+ purpose?: string;
51
+ /** Currency code. Defaults to 'usd' */
52
+ currency?: string;
53
+ }
54
+ interface PayResult {
55
+ id: string;
56
+ from_agent_id: string;
57
+ to_agent_id: string;
58
+ amount: number;
59
+ currency: string;
60
+ purpose: string | null;
61
+ status: string;
62
+ stripe_payment_intent_id: string;
63
+ client_secret: string;
64
+ created_at: string;
65
+ }
66
+ interface SubscribeParams {
67
+ /** Plan to subscribe to: 'growth' | 'scale' */
68
+ plan: 'growth' | 'scale';
69
+ }
70
+ interface SubscribeResult {
71
+ checkout_url: string;
72
+ session_id: string;
73
+ }
74
+ interface BalanceResult {
75
+ agent_id: string;
76
+ balance: number;
77
+ currency: string;
78
+ }
79
+ interface FundParams {
80
+ /** Amount in USD to add to wallet */
81
+ amount: number;
82
+ }
83
+ interface FundResult {
84
+ checkout_url: string;
85
+ }
86
+ interface AcceptParams {
87
+ /** Amount in USD to request */
88
+ amount: number;
89
+ /** Optional human-readable purpose */
90
+ purpose?: string;
91
+ /** Currency code. Defaults to 'usd' */
92
+ currency?: string;
93
+ }
94
+ interface AcceptResult {
95
+ id: string;
96
+ amount: number;
97
+ currency: string;
98
+ purpose: string | null;
99
+ status: string;
100
+ created_at: string;
101
+ }
102
+ interface Transaction {
103
+ id: string;
104
+ from_agent_id: string | null;
105
+ to_agent_id: string | null;
106
+ amount: number;
107
+ currency: string;
108
+ purpose: string | null;
109
+ status: string;
110
+ stripe_status?: string;
111
+ created_at: string;
112
+ }
113
+ declare class AgentPayError extends Error {
114
+ status: number;
115
+ constructor(message: string, status: number);
116
+ }
117
+ declare class AgentPay {
118
+ private apiKey;
119
+ private baseUrl;
120
+ constructor(config: string | AgentPayConfig);
121
+ private request;
122
+ /**
123
+ * Send a payment to another agent.
124
+ * Debits your wallet and credits the recipient instantly.
125
+ */
126
+ pay(params: PayParams): Promise<PayResult>;
127
+ /**
128
+ * Create a payment request (merchant side).
129
+ * Use this when your agent is receiving payment for a service.
130
+ */
131
+ accept(params: AcceptParams): Promise<AcceptResult>;
132
+ /**
133
+ * Subscribe to a Growth or Scale plan via Stripe Checkout.
134
+ * Returns a checkout_url — redirect the user there to complete payment.
135
+ */
136
+ subscribe(params: SubscribeParams): Promise<SubscribeResult>;
137
+ /**
138
+ * Get the current balance for an agent.
139
+ */
140
+ balance(agentId: string): Promise<BalanceResult>;
141
+ /**
142
+ * Fund an agent wallet via Stripe Checkout.
143
+ * Returns a checkout_url — redirect the user there to complete payment.
144
+ */
145
+ fund(agentId: string, params: FundParams): Promise<FundResult>;
146
+ /**
147
+ * Get a specific payment/transaction by ID.
148
+ */
149
+ getPayment(id: string): Promise<Transaction>;
150
+ /**
151
+ * List transactions for the authenticated agent (sent and received).
152
+ */
153
+ transactions(params?: {
154
+ limit?: number;
155
+ offset?: number;
156
+ }): Promise<{
157
+ transactions: Transaction[];
158
+ pagination: {
159
+ limit: number;
160
+ offset: number;
161
+ };
162
+ }>;
163
+ }
164
+
165
+ /**
166
+ * Register a new agent and get an API key.
167
+ * Static helper — use before you have an API key.
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * const { id, api_key } = await register(
172
+ * { name: 'My Bot', email: 'bot@example.com' }
173
+ * );
174
+ * const ap = new AgentPay(api_key);
175
+ * ```
176
+ */
177
+ declare function register(params: RegisterParams, config?: {
178
+ baseUrl?: string;
179
+ }): Promise<RegisterResult>;
180
+
181
+ export { type AcceptParams, type AcceptResult, type Agent, AgentPay, type AgentPayConfig, AgentPayError, type BalanceResult, type FundParams, type FundResult, type PayParams, type PayResult, type RegisterParams, type RegisterResult, type SubscribeParams, type SubscribeResult, type Transaction, AgentPay as default, register };
package/dist/index.js ADDED
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ AgentPay: () => AgentPay,
24
+ AgentPayError: () => AgentPayError,
25
+ default: () => index_default,
26
+ register: () => register
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+ var AgentPayError = class extends Error {
30
+ constructor(message, status) {
31
+ super(message);
32
+ this.name = "AgentPayError";
33
+ this.status = status;
34
+ }
35
+ };
36
+ var AgentPay = class {
37
+ constructor(config) {
38
+ if (typeof config === "string") {
39
+ this.apiKey = config;
40
+ this.baseUrl = "https://agent-pay.pro";
41
+ } else {
42
+ this.apiKey = config.apiKey;
43
+ this.baseUrl = config.baseUrl ?? "https://agent-pay.pro";
44
+ }
45
+ }
46
+ async request(method, path, body) {
47
+ const res = await fetch(`${this.baseUrl}${path}`, {
48
+ method,
49
+ headers: {
50
+ "Content-Type": "application/json",
51
+ Authorization: `Bearer ${this.apiKey}`
52
+ },
53
+ body: body != null ? JSON.stringify(body) : void 0
54
+ });
55
+ const data = await res.json();
56
+ if (!res.ok) {
57
+ throw new AgentPayError(
58
+ data.error ?? `HTTP ${res.status}`,
59
+ res.status
60
+ );
61
+ }
62
+ return data;
63
+ }
64
+ /**
65
+ * Send a payment to another agent.
66
+ * Debits your wallet and credits the recipient instantly.
67
+ */
68
+ async pay(params) {
69
+ return this.request("POST", "/api/payments/create", {
70
+ to_agent_id: params.to,
71
+ amount: params.amount,
72
+ currency: params.currency ?? "usd",
73
+ purpose: params.purpose
74
+ });
75
+ }
76
+ /**
77
+ * Create a payment request (merchant side).
78
+ * Use this when your agent is receiving payment for a service.
79
+ */
80
+ async accept(params) {
81
+ return this.request("POST", "/api/accept", {
82
+ amount: params.amount,
83
+ currency: params.currency ?? "usd",
84
+ purpose: params.purpose
85
+ });
86
+ }
87
+ /**
88
+ * Subscribe to a Growth or Scale plan via Stripe Checkout.
89
+ * Returns a checkout_url — redirect the user there to complete payment.
90
+ */
91
+ async subscribe(params) {
92
+ return this.request("POST", "/api/payments/subscribe", params);
93
+ }
94
+ /**
95
+ * Get the current balance for an agent.
96
+ */
97
+ async balance(agentId) {
98
+ return this.request("GET", `/api/agents/${agentId}/balance`);
99
+ }
100
+ /**
101
+ * Fund an agent wallet via Stripe Checkout.
102
+ * Returns a checkout_url — redirect the user there to complete payment.
103
+ */
104
+ async fund(agentId, params) {
105
+ return this.request("POST", `/api/agents/${agentId}/fund`, params);
106
+ }
107
+ /**
108
+ * Get a specific payment/transaction by ID.
109
+ */
110
+ async getPayment(id) {
111
+ return this.request("GET", `/api/payments/${id}`);
112
+ }
113
+ /**
114
+ * List transactions for the authenticated agent (sent and received).
115
+ */
116
+ async transactions(params) {
117
+ const qs = new URLSearchParams();
118
+ if (params?.limit != null) qs.set("limit", String(params.limit));
119
+ if (params?.offset != null) qs.set("offset", String(params.offset));
120
+ const query = qs.toString() ? `?${qs.toString()}` : "";
121
+ return this.request("GET", `/api/transactions${query}`);
122
+ }
123
+ };
124
+ var index_default = AgentPay;
125
+ async function register(params, config) {
126
+ const baseUrl = config?.baseUrl ?? "https://agent-pay.pro";
127
+ const res = await fetch(`${baseUrl}/api/agents/register`, {
128
+ method: "POST",
129
+ headers: { "Content-Type": "application/json" },
130
+ body: JSON.stringify(params)
131
+ });
132
+ const data = await res.json();
133
+ if (!res.ok) {
134
+ throw new AgentPayError(data.error ?? `HTTP ${res.status}`, res.status);
135
+ }
136
+ return data;
137
+ }
138
+ // Annotate the CommonJS export names for ESM import in node:
139
+ 0 && (module.exports = {
140
+ AgentPay,
141
+ AgentPayError,
142
+ register
143
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,116 @@
1
+ // src/index.ts
2
+ var AgentPayError = class extends Error {
3
+ constructor(message, status) {
4
+ super(message);
5
+ this.name = "AgentPayError";
6
+ this.status = status;
7
+ }
8
+ };
9
+ var AgentPay = class {
10
+ constructor(config) {
11
+ if (typeof config === "string") {
12
+ this.apiKey = config;
13
+ this.baseUrl = "https://agent-pay.pro";
14
+ } else {
15
+ this.apiKey = config.apiKey;
16
+ this.baseUrl = config.baseUrl ?? "https://agent-pay.pro";
17
+ }
18
+ }
19
+ async request(method, path, body) {
20
+ const res = await fetch(`${this.baseUrl}${path}`, {
21
+ method,
22
+ headers: {
23
+ "Content-Type": "application/json",
24
+ Authorization: `Bearer ${this.apiKey}`
25
+ },
26
+ body: body != null ? JSON.stringify(body) : void 0
27
+ });
28
+ const data = await res.json();
29
+ if (!res.ok) {
30
+ throw new AgentPayError(
31
+ data.error ?? `HTTP ${res.status}`,
32
+ res.status
33
+ );
34
+ }
35
+ return data;
36
+ }
37
+ /**
38
+ * Send a payment to another agent.
39
+ * Debits your wallet and credits the recipient instantly.
40
+ */
41
+ async pay(params) {
42
+ return this.request("POST", "/api/payments/create", {
43
+ to_agent_id: params.to,
44
+ amount: params.amount,
45
+ currency: params.currency ?? "usd",
46
+ purpose: params.purpose
47
+ });
48
+ }
49
+ /**
50
+ * Create a payment request (merchant side).
51
+ * Use this when your agent is receiving payment for a service.
52
+ */
53
+ async accept(params) {
54
+ return this.request("POST", "/api/accept", {
55
+ amount: params.amount,
56
+ currency: params.currency ?? "usd",
57
+ purpose: params.purpose
58
+ });
59
+ }
60
+ /**
61
+ * Subscribe to a Growth or Scale plan via Stripe Checkout.
62
+ * Returns a checkout_url — redirect the user there to complete payment.
63
+ */
64
+ async subscribe(params) {
65
+ return this.request("POST", "/api/payments/subscribe", params);
66
+ }
67
+ /**
68
+ * Get the current balance for an agent.
69
+ */
70
+ async balance(agentId) {
71
+ return this.request("GET", `/api/agents/${agentId}/balance`);
72
+ }
73
+ /**
74
+ * Fund an agent wallet via Stripe Checkout.
75
+ * Returns a checkout_url — redirect the user there to complete payment.
76
+ */
77
+ async fund(agentId, params) {
78
+ return this.request("POST", `/api/agents/${agentId}/fund`, params);
79
+ }
80
+ /**
81
+ * Get a specific payment/transaction by ID.
82
+ */
83
+ async getPayment(id) {
84
+ return this.request("GET", `/api/payments/${id}`);
85
+ }
86
+ /**
87
+ * List transactions for the authenticated agent (sent and received).
88
+ */
89
+ async transactions(params) {
90
+ const qs = new URLSearchParams();
91
+ if (params?.limit != null) qs.set("limit", String(params.limit));
92
+ if (params?.offset != null) qs.set("offset", String(params.offset));
93
+ const query = qs.toString() ? `?${qs.toString()}` : "";
94
+ return this.request("GET", `/api/transactions${query}`);
95
+ }
96
+ };
97
+ var index_default = AgentPay;
98
+ async function register(params, config) {
99
+ const baseUrl = config?.baseUrl ?? "https://agent-pay.pro";
100
+ const res = await fetch(`${baseUrl}/api/agents/register`, {
101
+ method: "POST",
102
+ headers: { "Content-Type": "application/json" },
103
+ body: JSON.stringify(params)
104
+ });
105
+ const data = await res.json();
106
+ if (!res.ok) {
107
+ throw new AgentPayError(data.error ?? `HTTP ${res.status}`, res.status);
108
+ }
109
+ return data;
110
+ }
111
+ export {
112
+ AgentPay,
113
+ AgentPayError,
114
+ index_default as default,
115
+ register
116
+ };
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "agent-payments",
3
+ "version": "0.1.1",
4
+ "description": "The simplest way to add USD payments between AI agents. Powered by Stripe.",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build": "tsup src/index.ts --format esm,cjs --dts",
17
+ "prepublishOnly": "npm run build"
18
+ },
19
+ "keywords": ["agent-payments", "ai", "agents", "payments", "a2a", "multi-agent", "langchain", "crewai", "autogen", "langgraph", "stripe", "mcp", "llm", "openai", "anthropic"],
20
+ "author": "AgentPay",
21
+ "license": "MIT",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/gs-lang/AgentPay.git",
25
+ "directory": "sdk"
26
+ },
27
+ "homepage": "https://agent-pay.pro",
28
+ "dependencies": {},
29
+ "devDependencies": {
30
+ "typescript": "^5",
31
+ "tsup": "^8"
32
+ },
33
+ "files": ["dist", "README.md"]
34
+ }