@mixrpay/agent-sdk 0.4.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,83 @@
1
+ # @mixrpay/agent-sdk
2
+
3
+ Enable AI agents to make payments to MixrPay-powered APIs.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @mixrpay/agent-sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { AgentWallet } from '@mixrpay/agent-sdk';
15
+
16
+ const wallet = new AgentWallet({
17
+ sessionKey: process.env.MIXRPAY_SESSION_KEY!
18
+ });
19
+
20
+ // Call merchant APIs with automatic payment handling
21
+ const response = await wallet.callMerchantApi({
22
+ url: 'https://api.merchant.com/generate',
23
+ merchantPublicKey: 'pk_live_...',
24
+ body: { prompt: 'Hello world' }
25
+ });
26
+
27
+ const data = await response.json();
28
+ ```
29
+
30
+ Get session keys at [mixrpay.com/wallet/sessions](https://www.mixrpay.com/wallet/sessions).
31
+
32
+ ## Core Methods
33
+
34
+ ```typescript
35
+ // Call merchant API with session-based payments
36
+ await wallet.callMerchantApi({ url, merchantPublicKey, body });
37
+
38
+ // Auto-pay fetch (drop-in replacement for fetch)
39
+ await wallet.fetch(url, options);
40
+
41
+ // Get wallet balance
42
+ const balance = await wallet.getBalance();
43
+
44
+ // Track payments
45
+ const payments = wallet.getPaymentHistory();
46
+ const total = wallet.getTotalSpent();
47
+ ```
48
+
49
+ ## Configuration
50
+
51
+ ```typescript
52
+ const wallet = new AgentWallet({
53
+ sessionKey: 'sk_live_...', // Required
54
+ maxPaymentUsd: 5.0, // Optional: client-side limit
55
+ onPayment: (p) => console.log(p), // Optional: payment callback
56
+ });
57
+ ```
58
+
59
+ ## Error Handling
60
+
61
+ ```typescript
62
+ import {
63
+ AgentWallet,
64
+ InsufficientBalanceError,
65
+ SessionLimitExceededError,
66
+ } from '@mixrpay/agent-sdk';
67
+
68
+ try {
69
+ await wallet.callMerchantApi({ ... });
70
+ } catch (error) {
71
+ if (error instanceof InsufficientBalanceError) {
72
+ console.log(`Need $${error.required}, have $${error.available}`);
73
+ }
74
+ }
75
+ ```
76
+
77
+ ## Documentation
78
+
79
+ [mixrpay.com/build](https://www.mixrpay.com/build)
80
+
81
+ ## License
82
+
83
+ MIT