Agent usage enforcement UsageFlow
Enforce usage limits on AI agents before the next step runs.
UsageFlow enforces per-customer token and spend limits on AI agents. Before each step, a policy reads the customer's usage and switches to a cheaper model, caps the budget, or blocks the call. No redeploy.
Free: 1 workflow with live policy. No credit card.
Why agent budgets fail when they live in code
A hard-coded step limit doesn't know which customer is running, what plan they are on, or what they already spent today. Changing it means a deploy, and every agent ends up with its own copy of the rule.
| Budget in code | Budget in a UsageFlow policy |
|---|---|
| Same limit for every customer | Limit per customer and plan |
| Counts steps, not tokens or spend | Reads the customer's running usage |
| Fails the run when hit | Can downgrade first, then block |
| Changing it needs a deploy | Edit in the Console; applies to the next call |
Per-customer limits for agent loops
Retries and loops are counted because every model call goes through the SDK with an identity and a workflow. The call that crosses a threshold still runs; the next one is checked against it.
Downgrade instead of failing
Set a ladder: at one threshold, route to a cheaper model; at the cap, block. Customers keep getting answers while spend stays bounded. Traces show the requested model next to the executed one.
Change limits without redeploying
Thresholds, models and who they apply to live in the UsageFlow Console and apply from the next call.
Usage enforcement vs. security guardrails
Both act before a call runs, but they answer different questions.
| Usage enforcement | Security guardrails | |
|---|---|---|
| Question | May this customer spend more? | May the agent use this tool or data? |
| Inputs | Identity, plan, current usage | Prompt, tool call, data access |
| Actions | Route, cap, block | Allow or deny a permission |
| UsageFlow | Yes | No — use a dedicated guardrail tool |
SDK example
Catch the rejection and end the run with a clear message. The provider is never contacted for a blocked call.
import { usage, VibeRejectionError } from '@usageflow/vibe';
try {
const turn = await usage.chat({
identity: customerId, // whose budget this step spends
workflow: 'research-agent', // the policy that sets the limit
provider: 'anthropic',
model: 'claude-sonnet-5',
messages,
});
} catch (err) {
if (err instanceof VibeRejectionError) {
return 'This run reached your usage limit.';
}
throw err;
}
Keep going
Agent usage enforcement FAQ
How do I enforce a token budget on an AI agent?
Pass the customer identity with each agent call. A UsageFlow policy checks that customer's current usage before the call runs and can route to a cheaper model, cap the budget, or block it.
Is this a security guardrail?
No. UsageFlow enforces usage and cost policies — budgets, quotas and model access by plan. Tool-permission and data-security guardrails are a different category.
Put a budget on every agent run
Free: 1 workflow with live policy. No credit card. TypeScript, Python and Go, with OpenAI and Anthropic.