@relai-fi/x402 0.5.25 → 0.5.26
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 +83 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -300,6 +300,13 @@ import {
|
|
|
300
300
|
fromAtomicUnits,
|
|
301
301
|
} from '@relai-fi/x402/utils';
|
|
302
302
|
|
|
303
|
+
// Management API — create/manage APIs, pricing, analytics, agent bootstrap
|
|
304
|
+
import {
|
|
305
|
+
createManagementClient,
|
|
306
|
+
bootstrapAgentKeySolana,
|
|
307
|
+
bootstrapAgentKeyEvm,
|
|
308
|
+
} from '@relai-fi/x402/management';
|
|
309
|
+
|
|
303
310
|
// Types & constants
|
|
304
311
|
import {
|
|
305
312
|
RELAI_NETWORKS,
|
|
@@ -461,6 +468,82 @@ app.get('/api/solana-data', relai.protect({
|
|
|
461
468
|
|
|
462
469
|
---
|
|
463
470
|
|
|
471
|
+
## Management API
|
|
472
|
+
|
|
473
|
+
Programmatically create and manage monetised APIs, update pricing, and read analytics. Designed for agents and CI/CD — no browser needed.
|
|
474
|
+
|
|
475
|
+
```typescript
|
|
476
|
+
import { createManagementClient } from '@relai-fi/x402/management';
|
|
477
|
+
|
|
478
|
+
const mgmt = createManagementClient({ serviceKey: process.env.RELAI_SERVICE_KEY! });
|
|
479
|
+
|
|
480
|
+
// Create a monetised API
|
|
481
|
+
const api = await mgmt.createApi({
|
|
482
|
+
name: 'My ML API',
|
|
483
|
+
baseUrl: 'https://inference.example.com',
|
|
484
|
+
merchantWallet: '0xYourWallet',
|
|
485
|
+
network: 'base',
|
|
486
|
+
endpoints: [
|
|
487
|
+
{ path: '/v1/predict', method: 'post', usdPrice: 0.05 },
|
|
488
|
+
{ path: '/v1/status', method: 'get', usdPrice: 0.001 },
|
|
489
|
+
],
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
// List / get / update / delete
|
|
493
|
+
const all = await mgmt.listApis();
|
|
494
|
+
const one = await mgmt.getApi(api.apiId);
|
|
495
|
+
await mgmt.updateApi(api.apiId, { description: 'Updated description' });
|
|
496
|
+
await mgmt.deleteApi(api.apiId);
|
|
497
|
+
|
|
498
|
+
// Pricing
|
|
499
|
+
await mgmt.setPricing(api.apiId, [{ path: '/v1/predict', method: 'post', usdPrice: 0.10 }]);
|
|
500
|
+
const pricing = await mgmt.getPricing(api.apiId);
|
|
501
|
+
|
|
502
|
+
// Analytics
|
|
503
|
+
const stats = await mgmt.getStats(api.apiId);
|
|
504
|
+
const payments = await mgmt.getPayments(api.apiId, { limit: 20, from: '2025-01-01' });
|
|
505
|
+
const logs = await mgmt.getLogs(api.apiId, { limit: 20 });
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
### Agent self-setup (autonomous key provisioning)
|
|
509
|
+
|
|
510
|
+
Agents can provision their own service key with zero human involvement — no dashboard, no JWT, no copy-paste. Run once and store the key.
|
|
511
|
+
|
|
512
|
+
```typescript
|
|
513
|
+
import { bootstrapAgentKeySolana, bootstrapAgentKeyEvm } from '@relai-fi/x402/management';
|
|
514
|
+
import { Keypair } from '@solana/web3.js';
|
|
515
|
+
|
|
516
|
+
// Solana agent
|
|
517
|
+
const keypair = Keypair.fromSecretKey(Buffer.from(process.env.AGENT_PRIVATE_KEY!, 'base64'));
|
|
518
|
+
const { key } = await bootstrapAgentKeySolana(keypair, 'my-agent');
|
|
519
|
+
// → key: "sk_live_..." — store securely, never re-run
|
|
520
|
+
|
|
521
|
+
// EVM agent (ethers.js Wallet)
|
|
522
|
+
import { ethers } from 'ethers';
|
|
523
|
+
const wallet = new ethers.Wallet(process.env.AGENT_PRIVATE_KEY!);
|
|
524
|
+
const { key: evmKey } = await bootstrapAgentKeyEvm(wallet, 'my-evm-agent');
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
Once you have a service key, combine it with `createX402Client` for a fully autonomous agent:
|
|
528
|
+
|
|
529
|
+
```typescript
|
|
530
|
+
import { createX402Client } from '@relai-fi/x402/client';
|
|
531
|
+
import { createManagementClient } from '@relai-fi/x402/management';
|
|
532
|
+
|
|
533
|
+
const serviceKey = process.env.RELAI_SERVICE_KEY!;
|
|
534
|
+
|
|
535
|
+
// Pay for APIs
|
|
536
|
+
const client = createX402Client({
|
|
537
|
+
wallets: { solana: agentWallet },
|
|
538
|
+
defaultHeaders: { 'X-Service-Key': serviceKey },
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
// Manage APIs
|
|
542
|
+
const mgmt = createManagementClient({ serviceKey });
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
---
|
|
546
|
+
|
|
464
547
|
## Utilities
|
|
465
548
|
|
|
466
549
|
```typescript
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@relai-fi/x402",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.26",
|
|
4
4
|
"description": "Unified x402 payment SDK for Solana, Base, Avalanche, SKALE Base, SKALE BITE, Polygon, and Ethereum. Automatic 402 handling with zero gas fees.",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|