Sub topic 17
A checklist for making and revisiting the choice
This chapter pulls the earlier material into one repeatable process. It assumes you can call an HTTP API or SDK, read basic Python, and already know the terms prompt, token, and context. It also assumes you have seen the ideas covered earlier in the tutorial: hosted APIs, open-weight models, parameter counts, context windows, token pricing, quantization, and evaluation sets.
The goal is simple. Pick the smallest option that meets your requirements, write down why, and set up the conditions under which you will look again.
Why a process beats a favorite model
Teams often choose a model because it topped a public leaderboard or because a colleague used it last month. Both reasons fail in the same way. Neither one starts from your task. A leaderboard measures someone else's questions, and a colleague's choice reflects someone else's constraints.
A written process gives you three things:
- A decision you can explain to a reviewer, a security team, or your future self.
- A way to compare candidates on the same footing.
- A clear trigger for when to change your mind.
Models, prices, and licenses change often. A choice that was right six months ago may be wasteful today. So the process has two halves: making the choice, and revisiting it.
The decision flow
The diagram shows the order of the steps. Each step produces something you can write down. The loop at the end is the part people skip.
Step 1: Define the task and requirements
Write the requirements as numbers and yes/no facts, not as adjectives. "Fast and accurate" cannot be tested. The following can:
- Task type: extraction, classification, summarization, question answering, code generation, or open-ended chat.
- Input size: the typical and worst-case number of tokens per request.
- Output size: the typical number of output tokens.
- Latency target: for example, the first token within 1 second, or a full answer within 5 seconds.
- Volume: requests per day, and how spiky the traffic is.
- Quality bar: for example, at least 95 percent of test cases pass.
- Data rules: whether the inputs contain personal or regulated data.
The worst-case input size matters more than the average. If one request in a hundred carries a 90,000-token document, a model with a smaller context window fails that request outright.
Step 2: Filter by hard constraints
Hard constraints are pass/fail. Apply them before you spend time on evaluation, because they remove candidates cheaply.
| Constraint | Question to ask | Effect on the candidate list |
|---|---|---|
| Context window | Does the model fit the worst-case input plus the output? | Removes models with a smaller window |
| Data privacy | May the data leave your network or region? | May rule out hosted APIs, or require a specific provider agreement |
| License | Does the license allow your use, user count, and field of use? | Removes open-weight models whose terms you cannot meet |
| Hardware | Do the weights fit in the memory you can get? | Removes models that are too large to self-host |
| Budget | Does projected spend fit? | Removes options that cost too much at your volume |
Check the license text itself. An open-weight model lets you download the weights, but that does not make it open source. Some licenses limit commercial use above a user threshold, forbid certain uses, or require attribution.
Step 3: Build an evaluation set
Collect real or realistic examples with a known good answer, or a clear pass check. Aim for at least 30 to 50 cases to start, and include the awkward ones: long inputs, typos, empty fields, and inputs that should produce a refusal or a "not found" answer.
Keep the set under version control and treat it like test code. Add a case every time the application fails in production.
Step 4: Test candidates, smallest first
Run the same cases against each candidate. Start with the smallest plausible model. If it passes, you are done searching upward. If it fails, move one size up and repeat.
This order saves money and time. It also guards against a common bias: trying the largest model first, seeing that it works, and never checking whether a cheaper one would have worked too.
The helper below runs one set of cases against several models behind an OpenAI-compatible endpoint and prints a pass rate for each. It reads the endpoint and key from environment variables, so the same script can test a hosted API or a local server.
import os
from openai import OpenAI
client = OpenAI(
base_url=os.environ["LLM_BASE_URL"],
api_key=os.environ.get("LLM_API_KEY", "not-needed-for-local"),
)
CASES = [
{"prompt": "Extract the invoice number: 'Invoice INV-2041, due May 3'", "expected": "INV-2041"},
{"prompt": "Extract the invoice number: 'Ref: INV-17, total $90'", "expected": "INV-17"},
{"prompt": "Extract the invoice number: 'No invoice here'", "expected": "none"},
]
def ask(model: str, prompt: str) -> str:
response = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": prompt}],
temperature=0,
)
return response.choices[0].message.content or ""
def pass_rate(model: str) -> float:
passed = sum(
1 for c in CASES
if c["expected"].lower() in ask(model, c["prompt"]).lower()
)
return passed / len(CASES)
if __name__ == "__main__":
# Candidate names come from the environment, smallest first.
for model in os.environ["LLM_CANDIDATES"].split(","):
print(f"{model.strip()}: {pass_rate(model.strip()):.0%}")Set LLM_CANDIDATES to a comma-separated list such as small-model,medium-model,large-model, using names your provider or local server recognizes.
A pass rate on three cases tells you little. The point of the code is the shape of the loop. Replace the cases with your own, and grow the set.
Step 5: Estimate cost and hardware
Once a model passes quality, check that it passes the budget. For a hosted API, multiply token counts by price. For a self-hosted model, estimate memory and add the cost of the machine.
def request_cost(input_tokens: int, output_tokens: int,
price_in_per_million: float, price_out_per_million: float) -> float:
return (input_tokens / 1_000_000) * price_in_per_million + \
(output_tokens / 1_000_000) * price_out_per_million
def weight_memory_gb(params_billion: float, bits_per_weight: int) -> float:
return params_billion * bits_per_weight / 8
# Placeholder prices, not real quotes.
per_request = request_cost(2_000, 300, 1.00, 4.00)
print(f"hosted: ${per_request * 50_000:.2f} per month")
print(f"7B at 4-bit weights: {weight_memory_gb(7, 4):.1f} GB before KV cache and overhead")Two cautions apply. First, weight memory is a floor. The KV cache (the stored attention state for the tokens in flight) and runtime overhead add more, and they grow with context length and concurrent requests. Second, a self-hosted machine costs money whether or not it is busy. Compare the monthly cost of the machine, plus the engineering time to run it, against the hosted bill at your real volume.
Step 6: Pick the smallest model that passes
Choose the smallest model that clears your quality bar with some margin. Margin matters because your evaluation set is a sample, and real traffic is messier. If a model passes at exactly the threshold, expect it to fail sometimes in production.
If two models pass, prefer the one that is cheaper, faster, and easier to operate. If you cannot separate them, choose the one with fewer lock-in risks, such as a standard API shape and a permissive license.
Consider routing as an option, not a default. If most requests are easy and a few are hard, a small model can handle the easy ones and a larger model can take the rest. Routing adds a classifier or a fallback rule to build and maintain, so use it only when the savings are clear.
Step 7: Keep the model swappable
Your choice will change. Make that cheap:
- Keep the endpoint, key, and model name in configuration, as in the code above.
- Put model calls behind one function, so prompts and parsing live in one place.
- Avoid features that only one provider supports unless you need them, and note them when you do.
- Keep the evaluation set runnable with one command, so you can test a replacement in minutes.
Prompts are not fully portable. A prompt tuned for one model can score lower on another, so re-run the evaluation after every swap and adjust prompts if needed.
Step 8: Record the decision and set review triggers
Write a short decision record. It should hold the requirements, the candidates tested, their scores, the cost estimate, the choice, and the date. A half page is enough.
Then list the events that should make you reopen the decision:
- A provider announces a price change, a deprecation date, or a new model.
- A new open-weight model of a similar size posts clearly better results on your evaluation set.
- Your volume grows by a factor of several, which can flip the hosted-versus-self-hosted comparison.
- Quality complaints rise, or the evaluation pass rate drops after a provider updates a model behind the same name.
- Your data rules change, for example a new customer contract that restricts where data may go.
- Your license terms or user counts cross a threshold stated in a model license.
Also pick a calendar date, such as every quarter, to rerun the evaluation even if nothing fires.
The checklist
Copy this list into your decision record.
- Requirements are written as numbers: task, token sizes, latency, volume, quality bar, data rules.
- Hard constraints were applied: context window, privacy, license, hardware, budget.
- An evaluation set exists with at least 30 cases, including edge cases.
- Candidates were tested smallest first, with the same prompts and settings.
- Cost and memory were estimated with worst-case token counts and a margin.
- The chosen model is the smallest one that passes with margin.
- Model name, endpoint, and key come from configuration, behind one call function.
- A dated decision record and a list of review triggers exist.
Common errors
- Choosing on a public benchmark and skipping the evaluation on your own data.
- Sizing the context window on the average input instead of the worst case.
- Counting only weight memory and forgetting the KV cache.
- Comparing hosted and self-hosted cost without engineering and idle-machine time.
- Treating "open-weight" as "free to use for anything" without reading the license.
- Swapping a model without re-running the evaluation.
- Never revisiting a choice made when the options were different.
Exercise
Your app summarizes support tickets. Typical input is 1,500 tokens, the worst case is 40,000 tokens, and the output is about 200 tokens. You are choosing between a small and a large hosted model. The small model has a 32,000-token context window and passes 92 percent of your cases, and the large model has a 128,000-token window and passes 97 percent. Your quality bar is 95 percent. Which model do you pick, and what would you do before accepting that answer?
Show answer
The small model fails twice over. Its 32,000-token window cannot hold the 40,000-token worst case, and its 92 percent pass rate is below the 95 percent bar. The large model meets both. Before accepting it, check how often the 40,000-token case actually occurs, because a rare long case could be handled by truncating or chunking the ticket, which might let the small model qualify after a fresh evaluation. Also estimate cost for both at your real volume, and confirm that 97 percent leaves enough margin over 95 percent on a larger evaluation set.
Exercise
Name three events that should make you reopen a model decision, and say which step of the checklist you would repeat for each.
Show answer
Any three of these work. A provider price change means repeating Step 5, cost and hardware estimation. A new open-weight model means repeating Step 4, testing candidates on your evaluation set. A new customer contract restricting data location means repeating Step 2, the hard-constraint filter, and then the steps after it. A drop in the evaluation pass rate after a provider update means repeating Step 4 and possibly adjusting prompts. A large volume increase means repeating Step 5 and the hosted-versus-self-hosted comparison.