Set Budgets and Per-Hiker Quotas

Your cost report says what a thousand questions cost, but nothing stops a script from asking ten thousand in the August rush, and the trust pays for every token. You’ll set a budget and an alert, give each hiker a daily token allowance, and cap answer length, then measure what the heaviest hiker costs before and after.

Set a Budget and an Alert

The simulator’s August sends 11,850 questions. At $2.15 per thousand from Order Prompts for the Prompt Cache, that’s about $25. Doubled for headroom, the trust’s monthly budget is $50.

Treat a provider’s console limit as a last resort:

On December 2, 2026, an OpenAI project’s budget only sent alerts unless its hard limit was on. The hard limit returned a 429 project_spend_limit_exceeded. An Anthropic workspace’s spend limit returned a 400, and a usage tier’s cap a 429 without retry-after. Give evals their own project or workspace.

Either provider’s limit turns every hiker away at once, so set an enforced limit above your $50 budget, say $75.

An alert fires at a share of the budget. At 60 percent, or $30, it catches a script the day it runs. A month running a fifth over the $25 estimate reaches $30 only near its end, so in production, also alert on a costly day. Create quota.js:

Language: JavaScript Filename: quota.js
import { latestReports, RESCUE_LINE } from "./model/fallback.js";
import { callCost, PRICES } from "./model/prices.js";

export const DAILY_TOKENS = 8_000;
export const RESERVE = 1_000;
export const MONTHLY_BUDGET = 50;
export const ALERT_SHARE = 0.6;
export const QUOTA_REACHED =
  "You've asked a lot today. Ask again tomorrow.";

const days = new Map();
let month = new Date().toISOString().slice(0, 7);
let spent = Number(process.env.MONTH_SPENT ?? 0);
let unknown = 0;
let alerted = false;

Set MONTH_SPENT from the provider’s usage page. The Map holds each day’s counts per hiker in memory, so a restart forgets them.

Give Each Hiker a Daily Quota

To stop a script, you need a quota, a daily allowance per hiker that your server checks before any model call. It counts tokens, since a question about every place on the trail costs ten times as much as one about the Valbrune ford.

Hikers share hut Wi-Fi, so the page keeps an anonymous hiker ID, not an IP address:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.