In this lesson, you read a simulated July week of traffic for misuse, in the two places your server records it, and decided what the server should do about each pattern you found.
Key Points
- A simulated week. The traffic simulator’s script option adds a scripted user who sends a fresh hiker ID and a long page about hut 4 to translate with every question. Over 13 to 19 July, requests climbed from about two hundred a day to 677, and the bill climbed with them. The simulator knows who sent what. Your server doesn’t.
- The first place: the traces and the server log. Neither holds a hiker ID, and a trace keeps a question’s fields, never its words. The trace writer keeps every error and every failed check, and one in ten of the rest.
- Counting a sample. A small program,
scripts/misuse-week.js, counts the week: a trace kept for an error or a failed check counts once, and a sampled one stands for ten. So the counts are estimates. The simulator’s 195 answers on the first day read as 168 model calls. The costs cover the answer model’s calls only, simulated, so moderation isn’t in them. - What the traces showed. The first three days looked ordinary: about 170 model calls, forty cents, and no long inputs. From the sixteenth, long inputs of over two thousand tokens jumped to hundreds a day, and 1,210 of the week’s 1,221 shared the same fields: hut 4, beds and dogs.
- A lead, not proof. The same fields don’t prove one paste. Only the simulator knows they were copies of one translation request. The cost reached $4.15 a day, ten times the first days, and none of your guards reacted. The quota refused one hiker a day at most, off-topic questions stayed at a handful, and the log held seven moderation flags.
- The second place: today’s quota counters. Only the quota’s
Mapholds tokens per hiker ID, andsweepQuota()deletes every earlier day, so you can read only today.tokensToday()returns today’s numbers without the IDs. - Reading the counters safely. Save the result of
tokensToday()from inside the running server, because another process that importsquota.jsgets an emptyMap. On a real server, keep it to staff, as a local snapshot or an admin-only route, never for signed-in hikers. - What the counters showed. The counters hold quota tokens, where a cached token counts its price share, a twentieth at this answer model. On 19 July, 531 IDs asked. 452 sat between two and three and a half thousand quota tokens, about one long paste’s worth each, and together used 94 percent of the day’s quota tokens.
- Tokens, not questions. Whether each ID asked once is a guess, and the next lesson adds a question count. The largest was one ID a little past the quota, like a group sharing a phone. The 452 stayed far under 8,000, so the quota never stopped them.
- Pattern one: a scripted user. A free translator on hundreds of IDs. Its pastes name hut 4, so the scope check lets them through, as does the length check from Place Guardrails Around the Stream and the Cache. A line in the prompt can’t stop it: by the time the model reads it, you’ve paid for the paste.
- Respond in your server. Tighten that length limit, and limit how fast new IDs arrive, above your busiest real minute so it doesn’t turn away real hikers. The next lesson measures where. This scripted user is a clear-cut one. A real script varies its text and timing, so it won’t stand out this clearly.
- Pattern two: using the assistant for something else. The scope check refused off-topic questions, such as homework, before the answer call. Jailbreaks are harder to see. One answer was blocked for a go/no-go verdict, which an ordinary hiker can trip as well as a role-play.
- A floor, not a count. The simulator sent five role-plays, and the ones whose answers passed left no mark, so a blocked count is a floor, not a count of attempts. Review each blocked one in the wardens’ desk queue, and keep counting.
- The gap. You can’t look back, because the sweep deleted the counters for the sixteenth to the eighteenth. You’d need a daily record, written before the sweep, with no IDs.
- The rule: look for misuse where your server records it: patterns without IDs in the traces, scaled up for the sample, and patterns per hiker in today’s quota counters, before the sweep. Then decide what your server does about each.
Final Code
In quota.js, below sweepQuota():