Sub topic 13
Measuring effort settings on your own task
This chapter assumes you can call an LLM API from Python and know what tokens and max output tokens are. It also assumes you have read the earlier chapters on effort levels, thinking budgets and cost. Here you will build a small experiment that picks an effort setting from measurements instead of habit.
Why measure instead of guess
Published benchmarks tell you that higher effort helps on hard problems. They do not tell you whether it helps on your prompts, with your output format, at your latency limit. Three things vary by task:
- Gain. A classification task may score the same at low and high effort. A multi-step planning task may jump by 20 points.
- Cost. Reasoning tokens are billed as output tokens, so a setting that doubles reasoning can more than double the bill for short answers.
- Latency. Reasoning tokens are generated before the visible answer starts, so time to the first visible token grows with effort.
An experiment gives you one number for each of these per setting. You then compare the settings against your own requirements.
The shape of the experiment
The loop is simple. Take a fixed set of cases, run each case at each setting several times, grade every answer automatically, and summarize.
Keep everything except the effort setting fixed: the model, the prompt, the case set and the temperature or other sampling options where the API allows them. If two things change at once you cannot tell which one caused the difference.
Building the case set
Your cases should come from real traffic or realistic inputs. Some practical rules:
- Use at least 30 cases. With 10 cases, one flipped answer moves accuracy by 10 points, which is more than the effect you are trying to see.
- Include easy, medium and hard cases. If every case is easy, all settings tie and you learn nothing. If every case is hard, you may conclude that high effort is always needed when most of your traffic is easy.
- Use answers you can check by code. Exact values, labels, numbers, or a unit test that runs on generated code all work. Free-form text needs a rubric or a judge model, which adds its own noise.
- Keep a held-out slice. Tune your prompt on some cases and report the effort comparison on others.
The grader matters as much as the cases. The spine's sample loop checks whether the expected string appears anywhere in the answer. That is fragile. The expected string "no" also appears inside "not", "know" and "cannot". A safer pattern is to ask the model to end with a marker line and compare only that line.
A complete harness
The code below extends the basic loop from the plan. It repeats each case, grades only the final marker line, and records latency and output tokens for each trial. Output tokens include the hidden reasoning tokens on both OpenAI and Anthropic, so this count is the one that drives your bill.
import time
from dataclasses import dataclass
@dataclass
class Trial:
correct: bool
seconds: float
output_tokens: int
def extract_final(answer):
"""Return the text after the last 'ANSWER:' line, lowercased."""
for line in reversed(answer.strip().splitlines()):
if line.strip().upper().startswith("ANSWER:"):
return line.split(":", 1)[1].strip().lower()
return ""
def run_trials(ask, cases, effort, repeats=3):
"""ask(prompt, effort) -> (answer_text, output_tokens)."""
trials = []
for prompt, expected in cases:
for _ in range(repeats):
start = time.perf_counter()
answer, output_tokens = ask(prompt, effort)
seconds = time.perf_counter() - start
correct = extract_final(answer) == expected.strip().lower()
trials.append(Trial(correct, seconds, output_tokens))
return trials
def summarize(trials, price_per_million_output):
n = len(trials)
seconds = sorted(t.seconds for t in trials)
accuracy = sum(t.correct for t in trials) / n
avg_tokens = sum(t.output_tokens for t in trials) / n
cost_per_case = avg_tokens * price_per_million_output / 1_000_000
return {
"accuracy": accuracy,
"median_seconds": seconds[n // 2],
"p95_seconds": seconds[min(n - 1, int(0.95 * n))],
"avg_output_tokens": avg_tokens,
"cost_per_case": cost_per_case,
"cost_per_correct": cost_per_case / accuracy if accuracy else float("inf"),
}Two details are worth noting. The harness reports the 95th percentile of latency as well as the median, because a few very long reasoning runs hurt users more than the typical run helps them. It also reports cost per correct answer. A cheap setting that is wrong 40 percent of the time can cost more per useful result than a pricier one, once you count retries or human review.
Connecting a provider
The harness only needs an ask function. Here are two adapters, one for each API shown earlier in the tutorial. The effort labels map directly to reasoning.effort on OpenAI. Anthropic uses token budgets, so the adapter translates each label into a budget. The numbers in that table are my choices, not a standard, and you should adjust them.
import anthropic
from openai import OpenAI
openai_client = OpenAI()
anthropic_client = anthropic.Anthropic()
def ask_openai(prompt, effort):
response = openai_client.responses.create(
model="o4-mini",
reasoning={"effort": effort},
input=prompt,
)
return response.output_text, response.usage.output_tokens
BUDGETS = {"low": 1024, "medium": 4000, "high": 8000}
def ask_anthropic(prompt, effort):
budget = BUDGETS[effort]
response = anthropic_client.messages.create(
model="claude-sonnet-4-5",
max_tokens=budget + 2048, # must exceed budget_tokens, with room for the answer
thinking={"type": "enabled", "budget_tokens": budget},
messages=[{"role": "user", "content": prompt}],
)
text = "".join(b.text for b in response.content if b.type == "text")
return text, response.usage.output_tokensAnthropic's max_tokens is set to the budget plus 2048 so that the visible answer cannot be cut off by a long thinking phase. If max_tokens is too tight, high settings can fail on length and look worse than they are. That is a harness bug, not a model result.
Now run it on a tiny case set. This set is only to show the format. Use a real one of 30 or more cases.
cases = [
(
"A train leaves at 14:10 and arrives at 17:45. How long is the trip? "
"End your reply with a line 'ANSWER: H:MM'.",
"3:35",
),
(
"Is 3599 a prime number? End your reply with a line 'ANSWER: yes' or 'ANSWER: no'.",
"no",
),
]
PRICE_PER_MILLION_OUTPUT = 4.0 # replace with your model's current output price
for effort in ("low", "medium", "high"):
trials = run_trials(ask_openai, cases, effort, repeats=3)
stats = summarize(trials, PRICE_PER_MILLION_OUTPUT)
print(effort, {k: round(v, 4) for k, v in stats.items()})The second case is a useful trap. 3599 is 59 times 61, so it looks prime but is not. Quick answers tend to fail this kind of case, which makes it good for separating settings.
Handling noise
Model output varies from run to run, even at the same setting. That is why the harness uses repeats=3. Some guidance on reading noisy results:
- Compare the gap with the spread. If you repeat the whole experiment and accuracy at one setting moves by 5 points, a 3-point difference between settings is not a finding.
- Count flips per case. A case that is right 3 of 3 times at high effort and 1 of 3 at low effort is real signal. A case that flips randomly at every setting is probably ambiguous, or its expected answer is wrong. Fix or remove it.
- Watch for rate limits and retries. A retry inside
askinflates the measured latency. Record time for a single successful call, or log retries separately. - Run settings interleaved if load varies. If you run all low trials in the morning and all high trials during peak hours, network and server load will contaminate the latency comparison. Alternate settings per case if you can.
Reading the results
Suppose your run produced the following numbers. They are invented for illustration.
| Setting | Accuracy | Median seconds | P95 seconds | Avg output tokens | Cost per correct (relative) |
|---|---|---|---|---|---|
| low | 0.72 | 2.1 | 4.0 | 380 | 1.0 |
| medium | 0.91 | 6.5 | 14.0 | 1400 | 2.5 |
| high | 0.93 | 14.8 | 41.0 | 3600 | 6.3 |
Going from low to medium buys 19 points of accuracy for about three times the latency. Going from medium to high buys 2 points for more than twice the latency again and more than twice the cost. If your bar is 90 percent accuracy and users wait for responses, medium is the answer. If a wrong answer is expensive, such as an incorrect legal clause, the 2 extra points at high may be worth it.
This is the diminishing-returns curve described earlier in the tutorial. The experiment's job is to show you where the knee sits for your task.
Some further checks before you commit:
- Break results down by difficulty. If medium matches high on easy and medium cases but falls behind only on hard ones, you can route: classify the request first, then send hard ones to high effort.
- Look at the token distribution. If the average output tokens at high effort are far below the budget or max, the setting is not the limit and raising it will not help. If many trials hit the cap, you are truncating, and the results understate that setting.
- Check the failures by reading them. Open five wrong answers at your chosen setting. Wrong reasoning suggests a harder task or a better prompt is needed. A wrong format suggests a grader or prompt problem that no effort level fixes.
Common errors
- Changing the prompt between settings. Even small wording differences swamp effort differences.
- Grading by substring. It rewards verbose answers that mention the right word anywhere.
- Too few cases. A decision based on 8 cases is a coin toss.
- Treating labels as comparable across providers. "Medium" on one API and a 4000-token budget on another are different things. Compare by measured accuracy, tokens and latency, not by label.
- Ignoring the cap. A
max_tokensvalue that cuts off reasoning produces empty or partial answers that count as wrong. - Measuring once. Models and defaults change. Keep the harness and case set in your repository and rerun them when you change model versions.
Exercise
Exercise
You run 40 cases three times each at low, medium and high effort. Accuracy is 0.80, 0.88 and 0.89. Median latency is 3 s, 9 s and 25 s. A second identical run gives low 0.84, medium 0.85 and high 0.90. What should you conclude, and what would you do next?
Show answer
The medium result moved from 0.88 to 0.85 between identical runs, and low moved from 0.80 to 0.84, so run-to-run noise is about 3 to 4 points. The gap between medium and high (1 to 5 points) is within or close to that noise, while high costs far more latency. Medium and high are not clearly different on accuracy, so medium looks like the better choice unless the task needs the last few points. Next, add more cases or repeats to shrink the noise, break results down by difficulty to see whether only hard cases benefit from high, and read the failures to check that the grader is not producing flips.