Cap is a hosted gate you call before running AI routes. One atomic consume() call checks and records usage. 20 units per user per day by default. Returns HTTP 402 when capped.
1. Mint a sandbox API key (no signup):
curl -X POST https://cap-alpha-one.vercel.app/v1/mint_sandbox_key
# Returns: { "projectId": "...", "apiKey": "cap_..." }
2. Consume units in your route:
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: 'user_123',
units: 1,
idempotencyKey: 'req_xyz' // required
})
});
const gate = await response.json();
if (!gate.ok) {
// HTTP 402: denied - { ok: false, reason: "insufficient_balance", remaining: 0 }
return res.status(402).json({ error: 'Daily limit exceeded' });
}
// HTTP 200: allowed - { ok: true, remaining: 19 }
// Proceed with AI route