UnitAI

Your agent looped all night. The breaker should have tripped at $2.

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.

research-bot · run 001 · claude-opus-5-5
StepContextCostRun total

Three limits, checked before every call

Request-count rate limits can't tell a $0.0001 autocomplete from a $1.50 reasoning loop. UnitAI sets limits in dollars.

Per agent run

On

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

Per customer

On

Give free-tier users a daily AI budget. When they hit it, show an upgrade prompt instead of paying for their usage.

"perUserDailyUsd": 5

Margin floor

On

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

See who's eating your margin

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.

UnitAI dashboard: AI spend, revenue and margin per customer, workflow ROI, model costs, and recent circuit-breaker blocks

Is your heaviest user profitable?

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.

Running in three steps

  1. Start the gateway

    git clone https://github.com/unitaihq/unitai
    cd unitai && node src/cli.ts
  2. Point your SDK at it

    new OpenAI({
      baseURL: "http://localhost:8787/openai/v1",
      defaultHeaders: { "x-unitai-user-id": customer.id }
    })
  3. Set your limits

    UNITAI_GLOBAL_DAILY_USD=200
    # per run, per customer, margin floor
    # in unitai.config.json

Pricing

Open source

Free

Self-host the gateway, dashboard, circuit breaker, and margin engine. Apache-2.0.

Get the code

Free margin teardown

20 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 teardown

UnitAI Cloud

Early access

Hosted, multi-region, with alerts, Stripe billing sync, and team views. Design partners get it free during beta.