Everything you need to add preflight billing to your agents.
pip install agentbill-sdk
Register at agentbill.fly.dev/register — free, no credit card. Your key starts with agb_.
from agentbill import AgentBillClient client = AgentBillClient(api_key="agb_your_key") # Before the run: check if the customer has budget check = client.preflight(agent_id="researcher", customer_id="user_123", estimated_units=10) if not check.approved: raise Exception(f"Blocked: {check.reason}") # budget_exhausted or ceiling_exceeded # ... run your agent here ... result = run_my_agent() # After the run: record what was actually used client.record(agent_id="researcher", customer_id="user_123", units=10)
That's it. The first 1,000 units per customer are free.
Checks budget before compute is consumed. If the customer is out of units, the run is blocked immediately — before any tokens are spent.
Logs actual usage after a successful run. Idempotent — safe to call from retried or parallel workflows.
Block any single run that would consume more than a set number of units. Set ceiling=N in preflight — if estimated_units exceeds it, the run is blocked before it starts.
check = client.preflight(
agent_id="researcher",
customer_id="user_123",
estimated_units=50,
ceiling=20 # block if this run would cost more than 20 units
)
| Parameter | Type | Description |
|---|---|---|
| agent_id | string | Identifier for this agent. Appears in the dashboard. |
| customer_id | string optional | Your internal customer ID. Defaults to "default". |
| estimated_units | int optional | Expected units for this run. Used for ceiling check. Default: 1. |
| ceiling | int optional | Block if estimated_units exceeds this value. |
Returns:
{
"approved": true,
"remaining_units": 990,
"estimated_units": 10
}
When blocked:
{
"approved": false,
"reason": "budget_exhausted", # or "ceiling_exceeded"
"remaining_units": 0,
"upgrade_url": "https://agentbill.fly.dev/upgrade"
}
| Parameter | Type | Description |
|---|---|---|
| agent_id | string | Identifier for this agent or task type. |
| units | int optional | Units consumed by this run. Default: 1. |
| customer_id | string optional | Your internal customer ID. Defaults to "default". |
| metadata | dict optional | Key-value pairs stored with the event (e.g. model name, latency). |
npm install agentbill
import { AgentBill } from 'agentbill'
const bill = new AgentBill({ apiKey: 'agb_your_key' })
// Before the run
const check = await bill.preflight({ agentId: 'researcher', customerId: 'user_123', estimatedUnits: 10 })
if (!check.approved) throw new Error('Blocked: ' + check.reason)
// After the run
await bill.record({ agentId: 'researcher', customerId: 'user_123', units: 10 })
AgentBill does not replace your payment processor — it sits in front of it. Multi-step workflows with state machines or reversal logic are out of scope.
How to limit cost per agent run
How to add billing to a LangChain agent
How to add a spend ceiling to an OpenAI agent