New: Cookbooks and AI ExplanationsStep-by-Step recipes to solve problems connected to Roadmaps and Cheat Sheets. Need more details? Use AI buttons for structured and simple explanations with concrete examples throughout the whole platform.Take a look
Someone pasted a huge wall of text into my chat box. My next bill did not look like the others.
What you'll have at the end
The wrapper rejects an oversized input and caps output tokens and request time, verified by a test that triggers the rejection.
You need
A function in your own code that already sends a prompt to a live LLM API from somewhere a stranger's input can reach it, such as a chat box, a support form, or a public endpoint.
Not covered
Slowing down a flood of many separate requests: this only stops one prompt from being too big or too slow, it never limits how many requests a caller can send.
Leans on
Log the token count and dollar cost behind every API call you make
go there to total up what every accepted call actually cost after it finished, instead of only refusing the ones that were too big before they started
Test your API wrapper without spending real tokens
go there once you also want to test the accepted path, mocking a real reply instead of only testing that an oversized one gets refused
Give a runaway agent a spending cap
go there once you are capping a whole multi-step agent loop instead of the one prompt this recipe guards
Checked 15 Aug 2026
Part of the LLM APIs and Integration cookbook