A spend cap is a daily usage limit per user that protects AI routes from overuse. Without a spend cap, a single user can drain your OpenAI, Anthropic, or other AI provider budget by making unlimited requests.
Cap provides a hosted API gate you call before executing expensive operations. One atomic consume() call checks and records usage. When a user exceeds their daily limit, Cap returns HTTP 402 Payment Required, and your route denies the request.
Instead of adding a remaining_credits column to your Supabase database, call the Cap hosted API:
const response = await fetch('https://cap-alpha-one.vercel.app/v1/consume', {
method: 'POST',
headers: {
'Authorization': 'Bearer cap_...',
'Content-Type': 'application/json'
},
body: JSON.stringify({
userId: req.user.id,
units: 1
})
});
const gate = await response.json();
if (!gate.ok) {
// HTTP 402: User exceeded daily limit
return res.status(402).json({
error: 'Daily limit exceeded',
remaining: gate.remaining
});
}
// HTTP 200: Allowed - proceed with AI route
const completion = await openai.chat.completions.create({...});
res.json(completion);
consume() fails, deny the requestidempotencyKey to safely retry requestsYou could create a remaining_credits integer in your database, but you'll need to handle:
Cap handles all of this. Just call https://cap-alpha-one.vercel.app/v1/consume.
Cap is a gate, not a billing system:
Mint a sandbox API key (no signup required):
curl -X POST https://cap-alpha-one.vercel.app/v1/mint_sandbox_key
# Returns: { "projectId": "...", "apiKey": "cap_..." }
Then gate your AI routes with one consume() call.