Skip to main content

Spending Policy

Control how much your wallet can spend across agents, tool calls, and self-improvement operations.

Per-agent budgets

Set spending limits per agent on daily, weekly, and monthly timeframes:

rickydata wallet settings

Budget tiers

TimeframeWhat it controls
DailyMaximum USDC spend per agent per day
WeeklyRolling 7-day limit per agent
MonthlyRolling 30-day limit per agent

When a budget limit is reached, further requests to that agent are rejected until the timeframe resets.

SDK SpendingWallet policy

For programmatic access, the SpendingWallet provides 8-layer defense-in-depth:

import { SpendingWallet } from 'rickydata';

const wallet = await SpendingWallet.fromPrivateKey(process.env.KEY!, {
maxPerCall: 0.01, // Max per individual tool call
maxPerSession: 1.0, // Max per SDK instance lifetime
maxPerDay: 5.0, // Rolling 24h limit
maxPerWeek: 20.0, // Rolling 7d limit
allowedEndpoints: ['mcp.rickydata.org'],
circuitBreakerThreshold: 5,
requireApprovalAbove: 0.05,
approvalCallback: async (details) => {
return await askUser(`Approve $${details.amountUsd}?`);
},
});

Defense layers

LayerWhat it does
Wallet isolationSeparate key with separate funds — limits exposure
Spending limitsPer-call, per-session, daily, weekly caps
Endpoint allowlistOnly pay to specific gateway URLs
Circuit breakerAuto-halt after N consecutive payment failures
DeduplicationPrevent duplicate payments within a time window
Approval callbackHuman-in-the-loop for amounts above a threshold
Balance monitoringEmits events when USDC balance is low
Dry run modeValidate everything without actually signing

Monitoring spending

wallet.on('payment:signed', (receipt) => {
console.log(`Paid $${receipt.amountUsd} for ${receipt.toolName}`);
});

wallet.on('balance:low', ({ balance }) => {
console.log(`Low balance: ${balance} USDC`);
});

console.log(wallet.getSpending());
// { totalSpent: 0.0005, sessionSpent: 0.0005, daySpent: 0.0005, callCount: 1 }

Wallet settings

Manage spending-related settings via the CLI:

rickydata wallet settings

Key settings:

SettingDescription
Auto-improveEnable/disable automatic self-improvement
Improve scheduleFrequency: after_each, daily, weekly, biweekly
Retention budgetHow much to allocate for session retention

Minimum balance enforcement

Before executing any chat or tool call, the Agent Gateway checks:

  1. Wallet has sufficient available balance
  2. Request would not exceed per-agent budget limits
  3. BYOK key is present (for agent chat)

If any check fails, the request is rejected with a clear error message before any execution or charging occurs.

Next steps