@agenttoll/sdk 1.0.0 → 1.0.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.
- package/README.md +56 -20
- package/package.json +1 -1
- package/tollbooth.js +3 -5
package/README.md
CHANGED
|
@@ -4,45 +4,81 @@ One-line micropayment integration for AI agents.
|
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
### From npm (recommended)
|
|
8
7
|
```bash
|
|
9
8
|
npm install @agenttoll/sdk
|
|
10
9
|
```
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### 1. Get Your API Key
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
// Via API
|
|
17
|
+
const response = await fetch('https://toll.agenttoll.io/api/publisher/register', {
|
|
18
|
+
method: 'POST',
|
|
19
|
+
headers: { 'Content-Type': 'application/json' },
|
|
20
|
+
body: JSON.stringify({
|
|
21
|
+
name: 'My API',
|
|
22
|
+
email: 'you@example.com',
|
|
23
|
+
wallet_address: 'YourSolanaWallet'
|
|
24
|
+
})
|
|
25
|
+
});
|
|
26
|
+
const { api_key } = await response.json();
|
|
15
27
|
```
|
|
16
28
|
|
|
17
|
-
|
|
18
|
-
Copy [tollbooth.js](./tollbooth.js) into your project.
|
|
29
|
+
Or use the web form at [toll.agenttoll.io](https://toll.agenttoll.io)
|
|
19
30
|
|
|
20
|
-
|
|
31
|
+
### 2. Add to Your Server
|
|
21
32
|
|
|
22
|
-
### Express
|
|
23
33
|
```javascript
|
|
24
34
|
import tollbooth from '@agenttoll/sdk';
|
|
25
|
-
// or if installed locally:
|
|
26
|
-
// import tollbooth from './tollbooth.js';
|
|
27
35
|
|
|
28
|
-
|
|
36
|
+
// Toll all agents, let humans through free
|
|
37
|
+
app.use(tollbooth(process.env.AGENTTOLL_KEY, {
|
|
38
|
+
amount: 0.005, // USDC per request
|
|
39
|
+
freeForHumans: true // Browsers pass free
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
// Or use the convenience method
|
|
43
|
+
app.use(tollbooth.agentsOnly(process.env.AGENTTOLL_KEY));
|
|
29
44
|
```
|
|
30
45
|
|
|
31
|
-
|
|
46
|
+
## SDK Options
|
|
47
|
+
|
|
32
48
|
```javascript
|
|
33
|
-
|
|
49
|
+
tollbooth(apiKey, {
|
|
50
|
+
amount: 0.005, // USDC to charge (default: 0.005)
|
|
51
|
+
freeForHumans: false, // Let browsers through free
|
|
52
|
+
paths: ['*'], // Routes to toll (glob patterns)
|
|
53
|
+
walletAddress: null, // Override default wallet
|
|
54
|
+
bypassHeader: null // Header for internal bypass
|
|
55
|
+
});
|
|
56
|
+
```
|
|
34
57
|
|
|
35
|
-
|
|
58
|
+
## Convenience Methods
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
// Toll only AI agents
|
|
62
|
+
tollbooth.agentsOnly(apiKey, options)
|
|
63
|
+
|
|
64
|
+
// Protect single route
|
|
65
|
+
tollbooth.protect(apiKey, options)
|
|
66
|
+
|
|
67
|
+
// Check if paid
|
|
68
|
+
tollbooth.hasPaid(req) // boolean
|
|
69
|
+
|
|
70
|
+
// Check if AI agent
|
|
71
|
+
tollbooth.isAgent(req) // boolean
|
|
36
72
|
```
|
|
37
73
|
|
|
38
|
-
|
|
74
|
+
## Cloudflare Workers / Edge
|
|
75
|
+
|
|
39
76
|
```javascript
|
|
40
|
-
import {
|
|
77
|
+
import { tollgate } from '@agenttoll/sdk/edge';
|
|
41
78
|
|
|
42
|
-
|
|
43
|
-
tools: [payTollTool]
|
|
79
|
+
export default tollgate(PUBLISHER_KEY, { amount: 0.01 });
|
|
44
80
|
```
|
|
45
81
|
|
|
46
|
-
##
|
|
82
|
+
## Full Documentation
|
|
47
83
|
|
|
48
|
-
See [
|
|
84
|
+
See [toll.agenttoll.io/docs](https://toll.agenttoll.io/docs)
|
package/package.json
CHANGED
package/tollbooth.js
CHANGED
|
@@ -285,8 +285,6 @@ tollbooth.hasPaid = function(req) {
|
|
|
285
285
|
*/
|
|
286
286
|
tollbooth.isAgent = isAgent;
|
|
287
287
|
|
|
288
|
-
//
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
module.exports.tollbooth = tollbooth;
|
|
292
|
-
module.exports.isAgent = isAgent;
|
|
288
|
+
// ES Module exports
|
|
289
|
+
export default tollbooth;
|
|
290
|
+
export { tollbooth, isAgent };
|