Give each of your end users their own scoped AIgateway key with a spend cap, rate limit, default cost tag, and isolated analytics. One POST per customer.
If you're shipping an AI product to multiple end users, you eventually face four problems: (1) one customer burning through your monthly budget, (2) another customer wanting their own usage report, (3) suspect activity you can't trace to a tenant, (4) a billing page that needs per-customer cost data.
The standard fix is to build it: tag every request internally, query a usage table, run nightly aggregation. Six months of work, plus on-call.
AIgateway's sub-account API replaces all of that with one POST. Each call mints a scoped key with its own spend cap, rate limit, default tag, and per-customer analytics.
Call this once per customer signup. Hand the returned key to your customer or use it server-side per-request — your choice.
curl -X POST https://api.aigateway.sh/v1/sub-accounts \
-H "Authorization: Bearer sk-aig-..." \
-H "Content-Type: application/json" \
-d '{
"name": "acme-corp",
"spend_cap_cents": 50000,
"rate_limit_rpm": 300,
"default_tag": "acme"
}'
# => { "id": "sa_9f3k...",
# "key": "sk-aig-...",
# "spend_cap_cents": 50000 }From there, you (or your customer) call the gateway with the new key. Spend, rate limits, and analytics are all isolated.
from openai import OpenAI
# This is the customer-scoped key from /v1/sub-accounts.
client = OpenAI(
base_url="https://api.aigateway.sh/v1",
api_key="sk-aig-...", # sub-account key
)
resp = client.chat.completions.create(
model="anthropic/claude-sonnet-4.6",
messages=[{"role": "user", "content": "..."}],
)Pull a single customer's spend by sub-account ID, broken down by model + day.
curl https://api.aigateway.sh/v1/sub-accounts/sa_9f3k.../usage?window=30d \
-H "Authorization: Bearer sk-aig-..."
# => { "summary": { "requests": 14210, "cost_cents": 3402, ... },
# "by_model": [ { "model_id": "anthropic/claude-sonnet-4.6", ... } ],
# "by_day": [ { "date": "2026-04-21", "requests": 612, ... } ] }Bump or revoke a customer's cap any time. Enforcement runs before dispatch — they can never silently exceed their cap.
curl -X PATCH https://api.aigateway.sh/v1/sub-accounts/sa_9f3k... \
-H "Authorization: Bearer sk-aig-..." \
-d '{ "spend_cap_cents": 100000 }'