ledgerby Novadyne
LedgerGuides › Track agent spend

Tracking an AI agent's spending and revenue

To track what an autonomous agent earns and spends, give it four accounts — a wallet (asset), revenue, expenses, and equity for starting capital — and record every earn/spend event as a balanced transaction. A trial balance then shows, at any moment, exactly how much the agent has made and where it went. Below is a complete worked example against the live Ledger API.

The scenario

An agent is funded with $20 of starting capital, completes a task for a $50 fee, and pays $0.30 in x402 tool calls to do it. We want a clean answer to "is this agent profitable?" at the end.

Step 1 — set up accounts

# Owner scope creates accounts
POST /ledger/accounts {"name":"Wallet","type":"asset"}        # id 1
POST /ledger/accounts {"name":"Owner Capital","type":"equity"} # id 2
POST /ledger/accounts {"name":"Task Revenue","type":"revenue"} # id 3
POST /ledger/accounts {"name":"Tool Costs","type":"expense"}   # id 4

Step 2 — fund the agent

Starting capital increases the wallet (asset) and is recorded against equity:

POST /ledger/transactions
{"date":"2026-06-16","description":"Initial funding",
 "entries":[{"account_id":1,"amount":2000},     # Wallet  +$20.00
            {"account_id":2,"amount":-2000}]}   # Equity  -$20.00

Step 3 — record revenue and expenses

# Earned a $50 fee
POST /ledger/transactions
{"date":"2026-06-16","description":"Task #1402 fee",
 "entries":[{"account_id":1,"amount":5000},     # Wallet   +$50.00
            {"account_id":3,"amount":-5000}]}   # Revenue  -$50.00

# Paid $0.30 of x402 tool calls
POST /ledger/transactions
{"date":"2026-06-16","description":"x402 tool calls (30x reads)",
 "entries":[{"account_id":4,"amount":30},       # Expense  +$0.30
            {"account_id":1,"amount":-30}]}     # Wallet   -$0.30

Step 4 — read the result

Per-account balances answer the profitability question directly:

GET /ledger/accounts/1   # Wallet  -> balance 6970  ($69.70 on hand)
GET /ledger/accounts/3   # Revenue -> 5000  ($50.00 earned)
GET /ledger/accounts/4   # Expense -> 30    ($0.30 spent)
# Profit on the task = revenue 5000 - expense 30 = 4970 ($49.70)

GET /ledger/reports/trial-balance
# {"total_debits":7000,"total_credits":7000,"balanced":true}

Why model it this way

  • Provenance. Each balance is the sum of recorded events — you can always trace a number back to the transactions that produced it.
  • Self-check. If the trial balance is ever unbalanced, an event was recorded wrong; you find out immediately instead of trusting a silent total.
  • Auditability. The general ledger (GET /ledger/reports/general-ledger) is a full, immutable history a human or another agent can review.
  • Metered cost tracking. Recording every x402 micropayment as an expense entry gives you exact per-task unit economics.

New to the model? Start with double-entry accounting for AI agents. New to x402 payments? See what is x402.

FAQ

How do I get a profit-and-loss view?

Sum your revenue accounts and subtract your expense accounts. Each account's balance comes from GET /ledger/accounts/{id}; the general-ledger report gives the line-by-line detail behind them.

Can I track multiple agents in one ledger?

Yes — give each agent its own accounts (or its own ledger instance) and tag transactions by description. Capability token scopes let you isolate which agent can write where.

How precise are the amounts?

Amounts are integers in minor units, so they're exact — no floating-point drift. A $0.002 x402 read is recorded as the integer it is.

Does recording an expense cost money?

Posting a transaction is a write ($0.01 via x402), or free if you hold a capability token. For high-frequency micro-expense logging, a Writer-scoped token is usually the right call.

Model your agent's books on the live API today — pay per call or use a capability token.

View the live API →

Written and verified by Novadyne, June 2026. Ledger is a production double-entry accounting API at ledger-api.novadyne.ai. Examples are illustrative; the live /.well-known/x402 discovery endpoint is the source of truth for current payment requirements.