Per agent run
OnCap what one run can spend, and stop it when it repeats the same request or fires off calls in a tight loop.
"perTraceUsd": 3
UnitAI is an open-source gateway between your app and OpenAI or Anthropic. It prices every call as it happens, ties it to a customer and an agent run, and cuts it off before a bug or a power user turns your API bill into a crisis.
Change one line: your SDK's base URL. Zero dependencies. Your API keys pass straight through.
| Step | Context | Cost | Run total |
|---|
Request-count rate limits can't tell a $0.0001 autocomplete from a $1.50 reasoning loop. UnitAI sets limits in dollars.
Cap what one run can spend, and stop it when it repeats the same request or fires off calls in a tight loop.
"perTraceUsd": 3
Give free-tier users a daily AI budget. When they hit it, show an upgrade prompt instead of paying for their usage.
"perUserDailyUsd": 5
Connect Stripe. When a customer's margin after AI cost drops below 30%, their calls move to a cheaper model. Below zero, they stop.
"downgradeBelow": 0.3
Every call is tagged with a customer, a feature, and a run. Within a day you'll know which customers cost more than they pay, which workflows earn their tokens back, and which runs got stuck.
In this sample, one customer on the $29 plan burned $23 of Opus. UnitAI moved them to Sonnet at the 30% floor and held their margin positive, with no code change.
Enter your plan price and what your heaviest users actually do. The math runs in your browser.
List prices per million tokens, 30-day month, no prompt caching. Caching usually cuts input cost a lot, and UnitAI shows your real numbers.
git clone https://github.com/unitaihq/unitai
cd unitai && node src/cli.ts
new OpenAI({
baseURL: "http://localhost:8787/openai/v1",
defaultHeaders: { "x-unitai-user-id": customer.id }
})
UNITAI_GLOBAL_DAILY_USD=200
# per run, per customer, margin floor
# in unitai.config.json
Free
Self-host the gateway, dashboard, circuit breaker, and margin engine. Apache-2.0.
Get the code20 minutes
Run UnitAI on your traffic for a week. We'll walk through your cost per customer, your riskiest runs, and where a cheaper model would do the same job.
Book a teardownEarly access
Hosted, multi-region, with alerts, Stripe billing sync, and team views. Design partners get it free during beta.