import { StellarX402Client } from '@stellar-x402/client';
const client = new StellarX402Client({
payerSecretKey: process.env.AGENT_STELLAR_SECRET!,
maxSpendPerCall: '0.05', // Maximum 0.05 USDC per individual request
maxDailySpend: '2.50', // Maximum 2.50 USDC total spend per 24 hours
network: 'stellar:testnet',
});
// Calling a paywalled endpoint
try {
const response = await client.fetch('https://api.example.com/api/v1/inference', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prompt: 'Analyze ledger volume' }),
});
const data = await response.json();
console.log('Result:', data);
} catch (err: any) {
if (err.message.includes('Budget exceeded')) {
console.error('Call halted by local spending guardrail:', err.message);
}
}