Skip to main content

Client Methods

Core methods available on the AgentFish client.

fetch(url, options?)

Drop-in replacement for fetch() with automatic x402 payment handling.

const response = await agent.fetch('https://api.example.com/data', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ prompt: 'Hello AI' }),

// AgentFish-specific options:
skipPayment: false, // Skip automatic payment (default: false)
maxPayment: 1.0, // Max payment in USDC (throws if exceeded)
metadata: { ... }, // Attach metadata to payment
});

Options

OptionTypeDefaultDescription
skipPaymentbooleanfalseSkip automatic payment handling
maxPaymentnumberundefinedMaximum payment amount in USDC
metadataobjectundefinedMetadata to attach to the payment

Plus all standard fetch options (method, headers, body, etc.)

fetchJson<T>(url, options?)

Convenience method that parses JSON response automatically.

interface ChatResponse {
reply: string;
tokens: number;
}

const data = await agent.fetchJson<ChatResponse>(
'https://api.example.com/chat',
{
method: 'POST',
body: JSON.stringify({ message: 'Hello' }),
}
);

console.log(data.reply);

getWallet()

Get current wallet information.

const wallet = await agent.getWallet();

console.log(wallet.address); // Wallet address
console.log(wallet.balance); // Balance in micro-USDC
console.log(wallet.dailyLimit); // Daily spending limit
console.log(wallet.perTxLimit); // Per-transaction limit
console.log(wallet.dailySpent); // Amount spent today

getBalance()

Get formatted balance information with human-readable values.

const balance = await agent.getBalance();

console.log(balance.balance); // Current balance in USDC
console.log(balance.dailyRemaining); // Remaining daily limit in USDC
console.log(balance.perTxLimit); // Per-transaction limit in USDC

getPayments(limit?)

Get recent payment history.

const payments = await agent.getPayments(10);

payments.forEach(payment => {
console.log(`${payment.amount} USDC to ${payment.merchant}`);
console.log(`Status: ${payment.status}`);
console.log(`Signature: ${payment.signature}`);
});

Payment Object

FieldTypeDescription
idstringPayment ID
amountnumberAmount in USDC
merchantstringMerchant URL or identifier
merchantAddressstringRecipient wallet address
signaturestringBlockchain transaction signature
statusstringpending, completed, or failed
createdAtstringISO timestamp