Prompt engineering notes
Fifteen practical notes on tokens, structure, and cost. Start with the optimizer if you want a number before you read.
How to reduce OpenAI API costs with token optimization
A practical way to lower an OpenAI bill: count the repeated prompt, cut what every call pays for, and keep the line the model actually needs.
Zero-shot vs few-shot prompting
When a plain instruction beats an example, and when one worked pair is worth the tokens it adds on every call.
Structuring prompts for Claude vs GPT-4
Markdown headings suit GPT-4-class models. Tagged blocks have long been Claude's documented preference. The task inside should be the same.
What cl100k_base actually counts
cl100k_base is not a word count. Spaces, line starts, digits, and rare words change the token integer GPT-4-class models bill.
Filler words that waste tokens
Please, kindly, and I would like are real tokens. They are rarely the bulk of the bill. Here is when they are worth deleting.
Delimiters models actually follow
Fences, headings, and tags work when they separate the assignment from the evidence. A delimiter around everything separates nothing.
Prompts that return JSON
Ask for the keys, forbid a preamble, and show one valid object. Most JSON failures are prose around an object, not the object.
System prompt vs user prompt
Put stable rules in the system text and the ticket in the user turn. Two copies of the same rule will drift the first week.
When chain-of-thought helps, and when it only adds tokens
Step-by-step reasoning helps some judgments and taxes every call. Ask for the steps only when you have seen the answer fail without them.
Shorten a prompt without losing the task
Cut copies, souvenirs, and tone paragraphs. Keep the verb, the limit that prevented an incident, and one example that still earns its tokens.
Count tokens before a batch job
A batch multiplies one prompt by every row. Count the template, the longest row, and the output cap before you launch thousands of calls.
Messy prompt failures that structure fixes
The model answers the sample, follows the customer, or emits two formats. These failures are layout problems more often than model problems.
Temperature does not fix a vague prompt
Sampling settings change how often you see an answer. They do not supply the task, the enum, or the ban on invented dates.
Role prompts that stay in scope
A role is one sentence about the job. It is not a persona, a license, or a substitute for the constraint you are hoping the persona implies.
A worked example: from a rambling support request to a brief
A full pass on a shipping-delay prompt: the messy draft, the structured brief, what the token estimate did, and what a person still has to check.
No notes match that search.
Nothing here calls an API. A token count in a note is the same cl100k estimate as the tool. Treat it as a planning figure, not an invoice.