P402 SDKs
Accelerate your agent development with official libraries.
Installation
npm install @p402/sdk
A2A Client
Interact with any A2A-compliant agent or router.
import { P402A2AClient } from '@p402/sdk';
const client = new P402A2AClient({
baseUrl: 'https://p402.io',
tenantId: 'your-tenant-id', // Optional
apiKey: 'your-api-key' // Optional
});
// 1. Send a Message (Google A2A Protocol)
const { task } = await client.sendMessage({
message: {
role: 'user',
parts: [{ type: 'text', text: 'Analyze market trends for Q3' }]
},
configuration: { mode: 'quality' }
});
console.log(task.status.state);
// 2. Submit Payment (x402 Extension)
const receipt = await client.submitPayment({
payment_id: 'pay_123...',
scheme: 'onchain',
tx_hash: '0x...'
});
console.log('Payment Status:', receipt.status);x402 Payment Client
Unified SDK for simple on-chain payments and protocol coordination.
import { P402Client } from '@p402/sdk';
const client = new P402Client({
routerUrl: 'https://p402.io',
debug: true
});
// Complete flow: Plan -> Sign -> Settle
const result = await client.checkout(
{
amount: "10.00",
network: "eip155:8453" // Base Mainnet
},
// Wallet bridging
async (to, data, value) => {
const hash = await wallet.sendTransaction({ to, data, value });
return hash;
}
);
if (result.success) {
console.log('Receipt:', result.receipt);
} else {
console.error('Error:', result.error.message);
}Intelligence SDK (v3)
Access the Protocol Economist and Sentinel for autonomous optimization.
import { P402Intelligence } from '@p402/sdk';
const intellect = new P402Intelligence({ apiKey: 'your-api-key' });
// 1. Run Autonomous Optimization Audit
const audit = await intellect.runAudit({
days: 7,
execute: true // Enabling autonomous 'Hands'
});
console.log('Total Saved:', audit.totalSavings);
// 2. Stream Real-time Thinking Trace
intellect.streamTrace((step) => {
console.log('[AGENT THINK]:', step.content);
});
// 3. Security Code Audit
const report = await intellect.auditCode(`
function runLoop() {
while(true) { fetch('openai.com'); }
}
`);