thedotmack/claude-mem · error
quota_exceeded
quota_exceeded
Error message
Monthly ${opts.kind} quota reached (${opts.cap}) What it means
enforceMonthlyQuota returns 402 Payment Required with code quota_exceeded when the team's usage count (repo.total for the current UTC month) has reached opts.cap for the given quota kind. The response body includes the used count and cap.
Solutions
- Check the response's used and cap fields to confirm the quota state.
- Wait for the UTC month to roll over (quota resets at monthStartUtc).
- Upgrade the team's plan or raise opts.cap in server configuration.
- Reduce usage or move heavy workloads to a team/key with remaining quota.
Example fix
// before
await client.createEvent(data); // 402 quota_exceeded, silently retried in a loop
// after
const { used, cap } = await client.getQuota();
if (used < cap) await client.createEvent(data);
else scheduleForNextMonth(data); Defensive patterns
Strategy: fallback
Validate before calling
async function hasQuotaRemaining(client, kind, cap) {
const { used } = await client.getUsage(kind);
return used < cap;
} Try / catch
const res = await fetch(url, opts);
if (res.status === 402) {
const { used, cap } = await res.json();
queueForNextBillingMonth(job);
} Prevention
- Track monthly usage client-side and alert before reaching the cap.
- Schedule bulk jobs early in the month to leave headroom.
- Handle 402 distinctly from other errors — retrying never helps within the month.
- Set budget alerts or upgrade the plan if caps are routinely hit.
When it happens
Trigger: A team makes a request whose kind (e.g. events/generations) is counted and used >= opts.cap since monthStartUtc; every further request of that kind in the same month is rejected.
Common situations: End-of-month usage spikes; automated pipelines exhausting the free tier cap; a plan downgrade lowered the cap mid-month; shared team key consumed by many services.
Related errors
- Aborting session for quota guard
- device_limit_exceeded
- Forbidden
- Gemini HTTP error (status )
- Generator paused for
AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17).
Data as JSON: /api/errors/235a44a4d18ec50e.
Report an issue: GitHub.
Appendix: source
Thrown at src/server/middleware/rate-limit.ts:77
logger.warn('HTTP', 'rate limit check failed; allowing request (fail open)', {
error: error instanceof Error ? error.message : String(error),
});
return next();
}
};
}
/** Checks month-to-date usage against the cap and answers 402 / next(). */
async function enforceMonthlyQuota(
repo: PostgresUsageRepository,
opts: { kind: string; cap: number },
teamId: string,
res: Response,
next: NextFunction,
): Promise<Response | void> {
const used = await repo.total({ teamId, kind: opts.kind, since: monthStartUtc(new Date()) });
if (used >= opts.cap) {
return res.status(402).json({
error: 'quota_exceeded',
message: `Monthly ${opts.kind} quota reached (${opts.cap})`,
used,
cap: opts.cap,
});
}
return next();
}
/** Monthly per-team quota on a usage `kind` (e.g. 'request'). 402 when reached. */
export function requireMonthlyQuota(pool: PostgresPool, opts: { kind: string; cap: number }): RequestHandler {
const repo = new PostgresUsageRepository(pool);
return async (req: Request, res: Response, next: NextFunction) => {
const teamId = req.authContext?.teamId;
if (!teamId) return next();
try {
return await enforceMonthlyQuota(repo, opts, teamId, res, next);
} catch (error) {View on GitHub (pinned to d8bc9755e7)