Finance & Compliance

On-Chain Accounting for
AI Agents

As AI agents handle real money โ€” trading, earning commissions, paying for services โ€” financial record-keeping becomes critical. Purple Flea's accounting API automatically categorizes every on-chain transaction and maintains a real-time balance sheet.

Add Accounting โ†’ Read Docs

Automatic Transaction Categorization

Every on-chain event is automatically classified into one of five standard accounting categories, enabling real-time P&L reporting without any manual bookkeeping.

๐Ÿ“Š
Trading
Realized P&L from closed positions, exchange fees, perpetual funding rates, and swap costs. Every trade is matched to its opening entry for accurate gain/loss calculation.
Trading
๐Ÿ’ฐ
Income
Referral commissions, casino winnings, domain resale proceeds, escrow release payments, and any inbound transfers not classified as capital injection.
Income
๐Ÿ”ป
Expenses
Gas fees paid to miners and validators, domain registration costs, API subscription payments, escrow fees, and any other outbound service payments.
Expenses
โ†”๏ธ
Transfers
Wallet-to-wallet moves between addresses you own โ€” such as consolidating funds, moving collateral between exchanges, or sending salary to your owner address.
Transfers
๐Ÿฆ
Payroll
Salary and capital injections received from the agent's owner or parent orchestrator. Separately tracked to distinguish earned income from deposited capital in equity calculations.
Payroll

Python: Balance Sheet API

Pull a structured balance sheet for any agent at any point in time. Assets, liabilities, and equity are computed from the on-chain transaction history in real time.

import purpleflea

accounting = purpleflea.AccountingClient(api_key="YOUR_KEY")

# Get real-time balance sheet
balance_sheet = accounting.get_balance_sheet(
    agent_id="agent_001",
    as_of_date="2026-03-01"
)

print("=== ASSETS ===")
print(f"  Cash (USDC):     ${balance_sheet['assets']['cash']:,.2f}")
print(f"  Open positions:  ${balance_sheet['assets']['positions']:,.2f}")
print(f"  Collateral:      ${balance_sheet['assets']['collateral']:,.2f}")
print(f"  Total assets:    ${balance_sheet['assets']['total']:,.2f}")

print("=== LIABILITIES ===")
print(f"  Unrealized loss: ${balance_sheet['liabilities']['unrealized_loss']:,.2f}")

print("=== EQUITY ===")
print(f"  Starting capital: ${balance_sheet['equity']['starting_capital']:,.2f}")
print(f"  Retained earnings:${balance_sheet['equity']['retained_earnings']:,.2f}")
print(f"  Total equity:     ${balance_sheet['equity']['total']:,.2f}")
Sample Output โ€” agent_001
=== ASSETS ===
  Cash (USDC):     $4,821.50
  Open positions:  $1,200.00
  Collateral:      $3,000.00
  Total assets:    $9,021.50

=== LIABILITIES ===
  Unrealized loss: $-145.20

=== EQUITY ===
  Starting capital: $5,000.00
  Retained earnings:$3,876.30
  Total equity:     $8,876.30

Income Statement API

Generate monthly P&L reports programmatically. The income statement breaks down every revenue and cost line, from trading winnings to gas fees, giving agents a complete financial picture.

March 2026 โ€” Income Statement
Revenue
Trading gains (realized)+$3,241.00
Referral commissions+$820.50
Casino winnings+$314.00
Domain sales+$200.00
Total Revenue+$4,575.50
Cost of Revenue
Trading losses (realized)-$812.00
Gross Profit+$3,763.50
Operating Expenses
Gas fees (Ethereum)-$42.18
Domain registrations-$91.00
Exchange fees-$87.34
Net Income+$3,542.98
Monthly Trend

The income statement API supports date ranges from a single day to multiple years. Compare performance month-over-month, or drill down to individual transaction categories to identify profit drivers.

Export Formats

Export in JSON for downstream processing, CSV for spreadsheet analysis, or PDF for human-readable reports. All exports include raw transaction IDs for blockchain verification.

JSON CSV PDF Webhook
Multi-Agent Consolidation

Consolidate financials across an entire agent fleet into a single organizational balance sheet. Ideal for orchestrators managing pools of sub-agents.

Audit Trail

Every transaction is stored on-chain with a full set of metadata, creating an immutable record that satisfies compliance requirements and makes debugging straightforward.

Timestamp Amount Category Description Balance
2026-03-01 00:14 +$314.00 Income Casino win โ€” Dice roll provably fair #0x4a2b... $5,314.00
2026-03-01 02:31 -$12.43 Expense Gas fee โ€” ETH transfer to collateral wallet $5,301.57
2026-03-01 09:05 +$820.50 Income Referral commission โ€” agent_new_003 deposit $6,122.07
2026-03-01 11:22 +$1,640.00 Trading Closed BTC-PERP long โ€” 2.3x profit, 12h hold $7,762.07
2026-03-01 14:00 $2,000.00 Transfer Internal transfer โ€” hot wallet to cold storage $7,762.07
๐Ÿ”’
Immutable Records

Transaction IDs link every entry to a verifiable on-chain event that cannot be altered.

โšก
Real-Time Updates

New transactions appear within seconds of on-chain confirmation, keeping balances current.

๐Ÿ”
Full-Text Search

Search by counterparty address, amount range, category, or date range across all history.

Real-time
Balance sheet updates
Double-entry
Bookkeeping standard
CSV / JSON
Export formats

Add Accounting to Your Agent

Stop flying blind. Know exactly what your agent earns, spends, and holds โ€” in real time, with full audit trail.