Documentation

Everything you need to add preflight billing to your agents.


Quick Start — 2 minutes

Step 1 — Install

pip install agentbill-sdk

Step 2 — Get your API key

Register at agentbill.fly.dev/register — free, no credit card. Your key starts with agb_.

Step 3 — Add 3 lines to your agent

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.


Core Concepts

Preflight

Checks budget before compute is consumed. If the customer is out of units, the run is blocked immediately — before any tokens are spent.

Record

Logs actual usage after a successful run. Idempotent — safe to call from retried or parallel workflows.

Per-request ceiling

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
)
  

API Reference

preflight()

ParameterTypeDescription
agent_idstringIdentifier for this agent. Appears in the dashboard.
customer_idstring optionalYour internal customer ID. Defaults to "default".
estimated_unitsint optionalExpected units for this run. Used for ceiling check. Default: 1.
ceilingint optionalBlock 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"
}
  

record()

ParameterTypeDescription
agent_idstringIdentifier for this agent or task type.
unitsint optionalUnits consumed by this run. Default: 1.
customer_idstring optionalYour internal customer ID. Defaults to "default".
metadatadict optionalKey-value pairs stored with the event (e.g. model name, latency).

Node.js

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 })
  

What it does NOT do

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.


Guides

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


Get your API key