AI agent unit economics is the number most builders running autonomous pipelines have never calculated — and it’s the number that determines whether the entire operation is a business or an expensive hobby that occasionally generates revenue.
The framing that makes this concrete: an agent calling Claude Opus to power a $0.05 data API call isn’t making money. It’s losing money. Opus input costs roughly $15 per million tokens — a single 1,000-token call costs $0.015. If that call generates $0.05 in revenue, the gross margin before infrastructure, hosting, and any post-July-1 compliance overhead is 70%. That sounds reasonable until you add the output tokens, the tool calls, and the orchestration overhead — and realize the actual cost per useful agent action is typically three to five times higher than the input-token cost alone.

This post gives you the exact formula for calculating AI agent unit economics per action, the model-routing logic to make each action profitable, and the one metric — Token-to-Revenue ratio — that every agent operation needs to track before scaling.
Why AI Agent Unit Economics Goes Negative Without Active Governance
The x402 ecosystem is processing 18,670 agent-to-agent transactions daily at $0.01 each, per live data from x402scan.com as of March 2026. That’s real revenue flowing through real agent pipelines. But the same data source that shows that transaction volume also shows the hidden margin problem: agents calling frontier models to process sub-cent transactions are structurally unprofitable unless model routing is explicitly optimized for the revenue tier of each call.
The pattern compounds at scale. An agent that looks profitable at 100 calls per day often turns unprofitable at 10,000 calls per day — because token costs scale with volume while revenue may not. A $0.01 transaction processed with a $0.008 total cost leaves a 20% margin at any volume. A $0.01 transaction processed with a $0.012 total cost loses money faster the more volume you run. AI agent unit economics is the discipline of knowing which category every action falls into before you scale it.
The compliance layer adds to this. The Colorado AI Act that went live yesterday and the EU AI Act arriving August 2 both require immutable audit trails, annual risk assessments, and human review paths for in-scope deployments. Each of those requirements has an operational cost that doesn’t show up in your token invoice — but does show up in your unit economics if you’re running agents in covered decision domains.
The Token-to-Revenue Formula: AI Agent Unit Economics in One Metric
The Token-to-Revenue ratio (T/R) is the cleanest single metric for AI agent unit economics: total token cost divided by revenue generated per agent action. T/R below 1.0 means costs exceed revenue — the agent is burning cash. T/R above 1.0 means the action is profitable. Target T/R for a sustainable agent business is 0.3 or lower — meaning token costs are 30% or less of revenue generated.
Step 1 — Install dependencies
pip install anthropic python-dotenv
Step 2 — Unit economics tracker
import os
from decimal import Decimal
from dataclasses import dataclass
from typing import Optional
import anthropic
from dotenv import load_dotenv
load_dotenv()
client = anthropic.Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
# Published rates per million tokens (update monthly — these shift)
MODEL_RATES = {
"claude-opus-4-6": {"input": Decimal("5.00"), "output": Decimal("25.00")},
"claude-sonnet-4-6": {"input": Decimal("3.00"), "output": Decimal("15.00")},
"claude-haiku-4-5-20251001": {"input": Decimal("0.80"), "output": Decimal("4.00")},
}
TARGET_TR_RATIO = Decimal("0.30") # token cost should be ≤30% of revenue
@dataclass
class ActionEconomics:
model: str
input_tokens: int
output_tokens: int
token_cost_usd: Decimal
revenue_usd: Decimal
tr_ratio: Decimal # token cost / revenue
profitable: bool
margin_pct: Decimal
def calculate_token_cost(model: str, input_tokens: int, output_tokens: int) -> Decimal:
rates = MODEL_RATES.get(model, {"input": Decimal("5.00"), "output": Decimal("25.00")})
input_cost = (Decimal(input_tokens) / Decimal("1000000")) * rates["input"]
output_cost = (Decimal(output_tokens) / Decimal("1000000")) * rates["output"]
return (input_cost + output_cost).quantize(Decimal("0.000001"))
def run_agent_action(
prompt: str,
revenue_per_action_usd: Decimal,
preferred_model: str = "claude-opus-4-6",
fallback_models: Optional[list[str]] = None
) -> ActionEconomics:
"""
Runs an agent action and calculates its unit economics immediately.
If the preferred model produces a T/R ratio above target, logs a
warning to route this action to a cheaper model — the same
fallback-routing principle from the Model Fallback Routing post,
now applied at the unit-economics layer rather than just availability.
"""
if fallback_models is None:
fallback_models = ["claude-sonnet-4-6", "claude-haiku-4-5-20251001"]
response = client.messages.create(
model=preferred_model,
max_tokens=500,
messages=[{"role": "user", "content": prompt}]
)
token_cost = calculate_token_cost(
preferred_model,
response.usage.input_tokens,
response.usage.output_tokens
)
tr_ratio = (token_cost / revenue_per_action_usd).quantize(Decimal("0.0001"))
margin_pct = ((revenue_per_action_usd - token_cost) / revenue_per_action_usd * 100).quantize(Decimal("0.1"))
economics = ActionEconomics(
model=preferred_model,
input_tokens=response.usage.input_tokens,
output_tokens=response.usage.output_tokens,
token_cost_usd=token_cost,
revenue_usd=revenue_per_action_usd,
tr_ratio=tr_ratio,
profitable=token_cost < revenue_per_action_usd,
margin_pct=margin_pct
)
if tr_ratio > TARGET_TR_RATIO:
print(f"[UNIT ECONOMICS WARNING] T/R ratio {tr_ratio} exceeds target "
f"{TARGET_TR_RATIO} on {preferred_model}. "
f"Route this action to {fallback_models[0]} instead.")
else:
print(f"[UNIT ECONOMICS OK] T/R {tr_ratio} | margin {margin_pct}% | "
f"cost ${token_cost} vs revenue ${revenue_per_action_usd}")
return economics
if __name__ == "__main__":
# Example: an agent that earns $0.05 per x402 API call
economics = run_agent_action(
prompt="Classify this transaction as high-risk or low-risk: "
"Payment of $47.00 from new account, first transaction, "
"international IP address.",
revenue_per_action_usd=Decimal("0.05"),
preferred_model="claude-opus-4-6",
fallback_models=["claude-sonnet-4-6", "claude-haiku-4-5-20251001"]
)
print(f"\n[ECONOMICS SUMMARY]")
print(f" Model: {economics.model}")
print(f" Token cost: ${economics.token_cost_usd}")
print(f" Revenue: ${economics.revenue_usd}")
print(f" T/R ratio: {economics.tr_ratio} (target: ≤{TARGET_TR_RATIO})")
print(f" Margin: {economics.margin_pct}%")
print(f" Profitable: {economics.profitable}")
Run this against a $0.05 revenue action on Opus and you’ll almost certainly see a T/R warning — Opus is priced for tasks where the output quality justifies the cost, not for high-volume sub-cent operations. The same action on Haiku produces a T/R ratio that makes the business work. That’s the entire model-routing decision made explicit, at the moment of each action, rather than discovered in a monthly bill.
Connecting AI Agent Unit Economics to the Full Revenue Stack
The T/R ratio is the foundation, not the ceiling. Three additional levers matter once you have the baseline:
- Idle capital yield. If your agent business holds USDC reserves for x402 settlement, those idle funds should be earning yield. At $10,000 idle USDC in a Morpho vault via Coinbase’s CDP SDK, the current yield produces roughly $600 per year — passive revenue on capital that would otherwise sit idle. The x402 Payment Protocol post covers the settlement infrastructure; the yield layer is a one-day build on top of it.
- Model routing by action type. The Model Fallback Routing post built the infrastructure for this. Apply it specifically to T/R thresholds: route any action with target revenue below $0.10 to Haiku by default, anything below $0.50 to Sonnet, and reserve Opus for actions where revenue justifies its cost.
- Compliance cost allocation. Post-Colorado AI Act, any in-scope agent action carries an audit record cost — storage, retention, human review infrastructure. This belongs in your unit economics calculation as an overhead rate, not ignored until enforcement forces the accounting.
For the full x402 revenue data behind these numbers, see RelayPlane’s 2026 agent revenue analysis.
The Builder’s Takeaway
AI agent unit economics is what separates a business from a cost center that occasionally produces revenue. The T/R ratio, calculated per action type rather than across a monthly average, tells you exactly which operations to scale and which to reroute to a cheaper model before the economics compound in the wrong direction. The builders who instrument this from the first deployed action will know their margins in real time. The ones who discover it from a monthly invoice will be fixing a structural problem under cost pressure rather than designing around it from the start.
This post is part of The Agentic Protocol’s Wealth series — the autonomous capital layer beneath every agent pipeline. See also: AI Agent Monetization.