Topic 7
Every token costs, and wrap-up
Every token of a prompt is paid for on every call: in input price, and in prefill time before the first token. AI Engineering (Ch. 5, "Provide examples") advises choosing example formats that use fewer tokens, if they perform equally well.
Predict first
Same examples, fewer tokens
cl100k_base (GPT-4's tokenizer) · deterministic
Loading the tokenizer…
Default texts: our transcription of AI Engineering, Ch. 5, Table 5-2 ("Provide examples"). The book counts 38 and 27 tokens with GPT-4; our transcription counts 37 and 26, likely a whitespace difference. Fewer tokens only help if the shorter format works as well: test both.
The template costs tokens too: 15 of the 25 in the two-message chat on the chat-templates page. You can't remove those, but you can make the rest cheaper to repeat. A prompt cache reuses only an identical prefix, so put the system prompt and examples first and the per-request part last: the prefix must match exactly.
What to keep
- A prompt is task description, examples and the task, all in one sequence.
- Roles are markers in that sequence, built by the model's own chat template. Use it exactly, and check token IDs, not just the printed string.
- System beats user beats tool output only because models are trained that way; misaligned lower-level instructions should be ignored.
- Be specific: scale, format, markers, persona.
- Count tokens, and order the prompt static-first.
Quick check