How to Add Spending Limits to Your AI Agent in 5 Minutes
Your AI agent needs to spend money. You need to control how much. Here is how to add budget limits, vendor rules, and rate controls — two paths, both under 5 minutes.
Prerequisites
- Create an account at app.quetra.dev
- Create an organization (happens automatically after signup)
That is it. No credit card required — the free tier includes 500 evaluations per month.
Path 1: MCP Server (Zero Code)
If your agent runs on Claude Desktop, Claude Code, or any MCP-compatible platform, this is the fastest path. No npm packages, no code changes.
Step 1: Register an Agent
Go to Agents → Register Agent in the dashboard. Give it a name and description. The description is critical — it is used by the MCP server for LLM agent routing when you have multiple agents.
Step 2: Create a Mandate
Go to Mandates → Create Mandate. Select your agent and configure the rules:
api.openai.com and api.anthropic.comClick Activate to make it live. The mandate is now enforced on every transaction.
Step 3: Generate an API Key
Go to API Keys → Create Key. Copy the key (starts with sk_).
Step 3.5: Connect Your Stripe Account (Optional)
If your agent needs to make credit card charges via quetra_stripe_charge, go to Settings → Payment Integrations and add your Stripe secret key (sk_test_... for testing or sk_live_... for production). Your key is encrypted at rest and never exposed in API responses. Without this step, Stripe charges will run in mock mode.
Step 4: Connect
Your MCP server URL is:
https://mcp.quetra.dev/<your-api-key>/mcpAdd it to your platform:
- Claude Code: Settings → MCP Servers → Add Remote Server → paste the URL
- Claude Desktop: Settings → Connectors → Add → paste the URL
Done. Your agent now has 8 governance tools available: quetra_evaluate, quetra_check_budget, quetra_can_spend, quetra_fetch, quetra_transactions, quetra_list_agents, quetra_acp_checkout, and quetra_stripe_charge. The agent will check its budget before every purchase.
Path 2: SDK (Custom Agents)
For LangChain, CrewAI, custom frameworks, or any TypeScript/JavaScript agent, use the SDK.
Step 1: Install
npm install @quetra/sdkStep 2: Set Up (Same as Above)
Register an agent, create a mandate with your rules, and generate an API key in the dashboard. Same steps as Path 1.
Step 3: Initialize the Client
import { QuetraClient } from '@quetra/sdk';
const quetra = new QuetraClient({
apiKey: process.env.QUETRA_API_KEY,
agentId: process.env.QUETRA_AGENT_ID,
});Step 4: Check Before You Spend
// Pre-flight check — will this transaction be approved?
const canSpend = await quetra.canSpend({
amount: 500, // $5.00 in cents
vendor: 'api.openai.com',
category: 'generation',
});
if (canSpend) {
// Proceed with the API call
const result = await callOpenAI(prompt);
}
// Or use quetra.fetch() for automatic x402 payment handling
const data = await quetra.fetch('https://paid-api.example.com/research', {
amount: 300, // $3.00
category: 'research',
});Step 5: Check Budget Status
const budget = await quetra.getBudgetStatus();
console.log(budget);
// {
// totalBudget: 10000, // $100.00
// spent: 2500, // $25.00
// remaining: 7500, // $75.00
// resetPeriod: 'monthly',
// nextReset: '2026-05-01T00:00:00Z'
// }What Happens When a Rule Fails?
The evaluation response tells you exactly which rule rejected the transaction and why:
{
"approved": false,
"reason": "vendor_blocklist",
"details": "Vendor 'sketchy-api.com' is not in the allowlist",
"rules": [
{ "type": "budget", "passed": true },
{ "type": "vendor_allowlist", "passed": false,
"reason": "Vendor not in allowlist" },
{ "type": "rate_limit", "passed": true }
]
}Every evaluation — approved or rejected — is logged to the transaction history with full context. Check it anytime via the dashboard or quetra.getTransactions().
Available Rule Types
Mandates support 7 rule types, combined with AND logic (all must pass):
| Rule | What It Controls | Example |
|---|---|---|
| Budget | Total + per-transaction limits | $100/month, max $10/tx |
| Vendor Allowlist | Which vendors are permitted | Only api.openai.com, api.anthropic.com |
| Vendor Blocklist | Which vendors are blocked | Block competitor-api.com |
| Category | Spending categories | Only "research" and "generation" |
| Rate Limit | Transaction frequency | Max 50 transactions/hour |
| Time Window | When spending is allowed | Weekdays 9am–6pm EST |
| Custom (JSONLogic) | Any custom logic | Arbitrary boolean expressions |
Next Steps
- Quickstart guide — detailed setup with screenshots
- SDK reference — full API documentation
- Webhook integration — get notified on budget warnings and exhaustion
- What is AI agent spending governance? — the concepts behind the system
Free tier: 500 evaluations/month
No credit card required. Create an account and start governing agent spending today.
Create Free Account