Analytics

Expense Tracking API
for AI Agents

An agent that earns $500/month but spends $450 on gas, fees, and API costs is barely profitable. Purple Flea's expense tracking API breaks down every cost category so you can see exactly where your agent's money goes โ€” and fix it.

Track Expenses Free โ†’ View Docs

Every Expense, Automatically Categorized

Four categories cover the full cost surface of an active Purple Flea agent. Each is tracked in real time and broken down by chain, venue, and service.

โ›ฝ
Gas Fees
On-chain transaction costs per chain

Every on-chain operation โ€” token transfers, DEX swaps, contract interactions โ€” consumes gas. We track gas costs per transaction, per day, and per chain, with USD conversion at time of payment. Includes L1 Ethereum, Polygon, Arbitrum, BSC, Solana, and Tron.

8 chains
๐Ÿ“‰
Trading Fees
Maker/taker fees and perpetual spreads

Spot trading fees, perpetual funding rates, and borrow costs are all tracked per trade and aggregated by venue. We break out maker vs. taker so you can see the fee impact of your order type choices. Negative maker fees (rebates) appear as income, reducing net trading costs.

maker + taker
๐ŸŽฒ
Casino Rake
House edge on casino games, already factored in

Casino games have an embedded house edge โ€” the expected loss per bet over time. We report the theoretical expected value (EV) loss per session separately from actual realized losses. This lets you distinguish bad luck from structural cost, and compare casino play ROI against other income streams.

EV-adjusted
๐ŸŒ
Domain Costs
Registration, renewal, and DNS management fees

Domain registrations, annual renewals, DNS configuration changes, and WHOIS privacy fees are tracked as operating expenses. Agents that earn referral income from domain registrations can compare domain costs against domain-referral income in one consolidated view.

TLD + renewal

Python Example

Query expenses and income for any time period, then compute net profit and margin in a few lines. All amounts are in USD, with original-currency amounts available as metadata on each line item.

import purpleflea

analytics = purpleflea.AnalyticsClient(api_key="YOUR_KEY")

# Get full expense breakdown for last 30 days
expenses = analytics.get_expenses(
    agent_id="agent_trader_001",
    period_days=30
)

print(f"Total expenses: ${expenses['total_usd']:.2f}")
print(f"  Gas fees:     ${expenses['categories']['gas_fees']:,.2f}")
print(f"  Trading fees: ${expenses['categories']['trading_fees']:,.2f}")
print(f"  Domain costs: ${expenses['categories']['domain_costs']:,.2f}")

# Get income for same period
income = analytics.get_income(agent_id="agent_trader_001", period_days=30)
print(f"Total income:  ${income['total_usd']:,.2f}")
print(f"  Trading P&L: ${income['categories']['trading_pnl']:,.2f}")
print(f"  Referrals:   ${income['categories']['referrals']:,.2f}")

# Net profitability
net = income['total_usd'] - expenses['total_usd']
margin = net / income['total_usd'] * 100 if income['total_usd'] > 0 else 0
print(f"Net profit:    ${net:,.2f} ({margin:.1f}% margin)")

Cut Costs Without Cutting Returns

The three highest-impact changes most agents can make to immediately improve their net margin โ€” without changing their trading strategy.

๐Ÿท๏ธ
Use Limit Orders to Earn Maker Rebates

Market orders pay taker fees (typically 0.05โ€“0.10%). Limit orders often earn maker rebates (0.01โ€“0.02% back). For an agent executing $50,000/month in trades, switching from market to limit orders can flip a $50 monthly fee cost into a $10 monthly rebate โ€” a $60/month swing before any improvement in fill price. The Purple Flea trading API supports both market and limit order types on all connected venues.

๐Ÿ“ฆ
Batch Transactions to Reduce Gas

An agent that sends 10 separate ETH transfers pays 10 base transaction fees. The same 10 transfers batched into one multicall transaction pays one base fee plus marginal execution cost โ€” often 60โ€“70% cheaper in total gas. Purple Flea's wallet API supports batch operations natively: wallet.batch_transfer(transfers=[]).

โ›“๏ธ
Choose Low-Fee Chains for Small Payments

A $5 gas fee on Ethereum Mainnet is a 10% overhead on a $50 transaction but negligible on a $50,000 trade. For small, frequent payments โ€” agent salaries, referral payouts, faucet claims โ€” use Polygon (gas typically $0.001โ€“0.01), Arbitrum (gas typically $0.05โ€“0.50), or Tron (near-zero fees). The expense tracking API flags transactions where gas represents more than 1% of value, so you can identify and migrate high-overhead operations.

See Your Agent's Full Unit Economics

The analytics dashboard visualizes income and expenses side-by-side with trend lines, expense breakdown charts, and fee-to-income ratios that update in real time.

agent_trader_001 โ€” Profitability
Last 30 days
$847.20
Total Income
$312.45
Total Expenses
63.1%
Net Margin
Trading P&L
+$634
Referral Income
+$213
Gas Fees
-$187
Trading Fees
-$98
Domain Costs
-$27
Daily net income โ€” last 15 days
Fee-to-Income Ratio Alert

Set a threshold alert that fires when your agent's total fees exceed a configured percentage of gross income. If trading fees + gas costs rise above 30% of gross, you receive a webhook so your orchestrator can pause activity and investigate. Prevents silent margin erosion during high-volatility periods when gas spikes.

Weekly Email Reports

Purple Flea sends automated weekly summary emails with income vs. expense breakdown, largest single-week expense items, and a trend comparison against the previous week. Configure delivery to the agent operator's email with analytics.set_report_email().

8
Chains with real-time gas fee tracking
Live
Expense data updates in real time โ€” no daily batch delays
Weekly
Automated P&L email reports delivered to agent operators

Track Every Income and Cost Source

Expense tracking integrates with every Purple Flea service. Referral income, casino winnings, trading P&L, domain commissions, escrow fees, and faucet claims all flow into the same unified analytics view.

Start Tracking Your Agent's Expenses

Expense tracking is included in every Purple Flea plan. Register your agent and your first expense report is available immediately โ€” no extra setup required.

Get API Key โ€” Free to Start โ†’