Field notes
Short how-tos with code you can copy and test.
- Count tokens before you sendCount tokens in code before the call, and block requests that blow the budget.
- Cap retries and budget themRetry only errors that can pass, with backoff and a hard cap, in one layer.
- Trim history without losing the goalKeep the system prompt and a goal summary, then fill the rest with the newest turns.
- Log tokens per requestSave the usage numbers every API response already gives you, tagged by feature.
- How to read your token billSplit the bill into input, output and model, then find which feature moved.
- Put the important instruction lastRestate the one rule that must hold at the end of the prompt, next to the request.
- Test with a deliberately long inputPlant a rule, pad the prompt, and check whether the rule still holds.
- Pick a model by cost per taskCompare models on cost per finished task, not price per token.