@agentspend/sdk 0.3.1 → 0.3.2

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 (2) hide show
  1. package/README.md +86 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # @agentspend/sdk
2
+
3
+ SDK for services to accept AI agent payments — cards (Stripe) and crypto (x402/USDC on Base).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @agentspend/sdk
9
+ ```
10
+
11
+ ## Paywall middleware (Hono)
12
+
13
+ Add a paywall to any endpoint. Accepts both card and crypto payments automatically.
14
+
15
+ ```ts
16
+ import { createAgentSpend, getPaymentContext } from "@agentspend/sdk";
17
+
18
+ const spend = createAgentSpend({
19
+ serviceApiKey: process.env.AGENTSPEND_SERVICE_API_KEY,
20
+ crypto: {
21
+ receiverAddress: "0x...", // your USDC address on Base
22
+ },
23
+ });
24
+
25
+ app.post("/api/generate", spend.paywall({ amount: 100 }), async (c) => {
26
+ const payment = getPaymentContext(c);
27
+ // payment.method === "card" | "crypto"
28
+ // payment.amount_cents === 100
29
+ return c.json({ result: "..." });
30
+ });
31
+ ```
32
+
33
+ ### Dynamic pricing
34
+
35
+ ```ts
36
+ // Read amount from request body field
37
+ spend.paywall({ amount: "amount_cents" });
38
+
39
+ // Custom pricing function
40
+ spend.paywall({ amount: (body) => calculatePrice(body) });
41
+ ```
42
+
43
+ ## Direct charge (card only)
44
+
45
+ ```ts
46
+ const result = await spend.charge("card_abc123", {
47
+ amount_cents: 500,
48
+ description: "API call",
49
+ });
50
+ ```
51
+
52
+ ## How agents pay
53
+
54
+ **Card:** Agent sends `x-card-id: card_xxx` header or `card_id` in the request body.
55
+
56
+ **Crypto:** Agent sends `x-payment` header with a signed x402 payment payload.
57
+
58
+ If neither is provided, the service returns `402 Payment Required` with x402 payment requirements.
59
+
60
+ ## Configuration
61
+
62
+ ```ts
63
+ const spend = createAgentSpend({
64
+ // Stripe card payments (get key from service onboarding)
65
+ serviceApiKey: "sk_...",
66
+
67
+ // Crypto payments (optional)
68
+ crypto: {
69
+ receiverAddress: "0x...", // static payTo address
70
+ network: "eip155:8453", // default: Base
71
+ facilitatorUrl: "https://...", // default: x402.org
72
+ },
73
+
74
+ // Override platform API URL (optional)
75
+ platformApiBaseUrl: "https://api.agentspend.co",
76
+ });
77
+ ```
78
+
79
+ At least one of `serviceApiKey` or `crypto` must be provided.
80
+
81
+ ## Environment variables
82
+
83
+ | Variable | Description |
84
+ |----------|-------------|
85
+ | `AGENTSPEND_API_URL` | Platform API base URL (default: `https://api.agentspend.co`) |
86
+ | `AGENTSPEND_SERVICE_API_KEY` | Service API key (from service onboarding) |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentspend/sdk",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "publishConfig": {