StackPractices
intermediate By Mathias Paulenko

AI Model Selection Matrix

Compare LLM models by cost, latency, context window, accuracy, and use case. Includes decision criteria, benchmark results, pricing comparison, and recommendations for classification, extraction, summarization, code, and agent tasks.

Topics: ai

Overview

“Which model should we use” is the question every LLM project opens with and nobody wants to answer rigorously. This matrix answers it: model side by side on cost, latency, context window, accuracy, and task fit — the five axes that actually matter — plus the decision framework to pick and the fallback strategy for when the pick goes wrong.

Use it to shortlist two or three candidates, run your own evals on the shortlisted set, and keep the pricing and benchmark rows current as new models land — the matrix is the framework, the numbers are yours to update.

The Decision at a Glance

Decision tree for picking an LLM tier by task type, batch versus real-time, context size, and accuracy needs.

Companion files: the ai-model-selection-matrix companion repo has everything on this page as standalone files — the pricing comparison CSV, the cost-per-1000-queries worksheet, the weighted scorecard template, and the pre-commit checklist.

1. Model Comparison Table

The five axes from the overview, side by side. Prices move fast — treat these rows as a snapshot and re-check them before you commit.

Model               | Input $/1K | Output $/1K | Context | Multimodal
--------------------+------------+-------------+---------+-----------
GPT-5               | $0.00125   | $0.01000    | 400K    | Yes
GPT-5-mini          | $0.00025   | $0.00200    | 400K    | Yes
GPT-5-nano          | $0.00005   | $0.00040    | 400K    | Yes
Claude Sonnet 4.5   | $0.00300   | $0.01500    | 200K    | Yes
Claude Haiku 4.5    | $0.00100   | $0.00500    | 200K    | Yes
Gemini 2.5 Pro      | $0.00125   | $0.01000    | 1M      | Yes
Gemini 2.5 Flash    | $0.00030   | $0.00250    | 1M      | Yes
Llama 4 Maverick    | $0.00020   | $0.00060    | 1M      | Yes
Mistral Medium 3    | $0.00040   | $0.00200    | 128K    | No

2. Cost per 1000 Queries

One workload priced across all nine rows — this is where the tier gaps stop being abstract.

Assumptions: 1500 input tokens, 500 output tokens per query
Costs computed from the Section 1 pricing — verify against providers.

Model              | Cost per query | Cost per 1K queries | Monthly (10K q/day)
───────────────────┼────────────────┼─────────────────────┼────────────────────
GPT-5              | $0.00688       | $6.88               | $2,062.50
GPT-5-mini         | $0.00138       | $1.38               | $412.50
GPT-5-nano         | $0.00028       | $0.28               | $82.50
Claude Sonnet 4.5  | $0.01200       | $12.00              | $3,600.00
Claude Haiku 4.5   | $0.00400       | $4.00               | $1,200.00
Gemini 2.5 Pro     | $0.00688       | $6.88               | $2,062.50
Gemini 2.5 Flash   | $0.00170       | $1.70               | $510.00
Llama 4 Maverick   | $0.00060       | $0.60               | $180.00
Mistral Medium 3   | $0.00160       | $1.60               | $480.00

3. Task-Based Recommendations

3.1 Classification

Task: Assign input to one of N categories
Requirements: Consistency, low cost, low latency

Recommended models (in order):
1. GPT-5-nano      — Cheapest closed option, plenty for simple categories
2. Gemini 2.5 Flash — Good cost/accuracy ratio, huge context
3. GPT-5-mini      — A step up when nano misses edge cases
4. Llama 4 Maverick — Self-hosted option, lowest marginal cost

Not recommended:
- GPT-5           — Overkill for classification, ~25x nano's price
- Claude Sonnet 4.5 — Same story, ~40x nano's price

3.2 Information Extraction

Task: Extract structured data (entities, relationships, fields) from text
Requirements: Accuracy, structured output, schema adherence

Recommended models (in order):
1. GPT-5           — Best structured output, strict JSON mode
2. Claude Sonnet 4.5 — Handles extraction well, copes with messy schemas
3. GPT-5-mini      — Covers simple extraction at ~5x less
4. Gemini 2.5 Pro  — Best for long-document extraction (1M context)

Considerations:
- Use JSON mode / structured output when available
- Validate output schema in application code
- For long documents (>100K tokens), use Gemini 2.5 Pro or Claude Sonnet 4.5

3.3 Summarization

Task: Condense long text into a shorter summary
Requirements: Accuracy, coherence, context window for long inputs

Recommended models (in order):
1. Claude Sonnet 4.5 — Best summarization quality, 200K context
2. GPT-5             — close behind, 400K context
3. Gemini 2.5 Pro    — the pick when the document is huge (1M context)
4. Claude Haiku 4.5  — Good for short documents, lower cost

Considerations:
- For documents < 10K tokens: any model works well
- For documents 10K-100K tokens: GPT-5 or Claude Sonnet 4.5
- For documents > 100K tokens: Gemini 2.5 Pro (1M context)

3.4 Code Generation and Review

Task: Generate, review, or refactor code
Requirements: Code accuracy, language support, reasoning ability

Recommended models (in order):
1. Claude Sonnet 4.5 — Best code reasoning, strong at refactoring
2. GPT-5             — Excellent code generation, broad language support
3. GPT-5-mini        — Fine for simple code tasks at lower cost
4. Llama 4 Maverick  — Open-source option for self-hosting

Considerations:
- For complex refactoring: Claude Sonnet 4.5
- For boilerplate generation: GPT-5-mini
- For code review: GPT-5 (best at identifying subtle bugs)
- For self-hosting: Llama 4 Maverick with code-specific fine-tunes

3.5 RAG (Retrieval-Augmented Generation)

Task: Answer questions based on retrieved context
Requirements: Faithfulness, context utilization, citation accuracy

Recommended models (in order):
1. GPT-5             — Best faithfulness, follows context instructions well
2. Claude Sonnet 4.5 — Better at combining many retrieved chunks
3. Gemini 2.5 Pro    — Best for large context windows (many chunks)
4. GPT-5-mini        — Good for simple Q&A, lower cost

Considerations:
- Faithfulness is critical — use temperature 0
- For multi-chunk synthesis: Claude Sonnet 4.5 or GPT-5
- For large context (20+ chunks): Gemini 2.5 Pro
- For cost-sensitive RAG: GPT-5-mini with fewer chunks

3.6 Agent / Tool Use

Task: Multi-step reasoning with tool calls
Requirements: Tool selection accuracy, reasoning, instruction following

Recommended models (in order):
1. Claude Sonnet 4.5 — Top tool use and reasoning, solid function calling
2. GPT-5             — Excellent tool use, parallel function calling
3. GPT-5-mini        — Fine for small agents of 1-3 tools
4. Llama 4 Maverick  — Open-source option with function calling

Considerations:
- For complex agents (5+ tools): Claude Sonnet 4.5 or GPT-5
- For simple agents (1-3 tools): GPT-5-mini
- For self-hosted agents: Llama 4 Maverick
- Test tool selection accuracy before deploying

4. Decision Framework

Work the steps in order — each one narrows the shortlist a bit more.

Step 1: What is the task type?
  Classification → Start with GPT-5-nano
  Extraction → Start with GPT-5
  Summarization → Start with Claude Sonnet 4.5
  Code → Start with Claude Sonnet 4.5
  RAG → Start with GPT-5
  Agent → Start with Claude Sonnet 4.5

Step 2: What is the input size?
  < 10K tokens → Any model works
  10K-100K tokens → Any flagship tier
  100K-500K tokens → Claude Sonnet 4.5 (200K) or GPT-5 (400K)
  > 500K tokens → Gemini 2.5 Pro or Llama 4 Maverick (1M context)

Step 3: What is your budget per 1000 queries?
  < $1 → GPT-5-nano, Gemini 2.5 Flash, Llama 4 Maverick
  $1-5 → GPT-5-mini, Mistral Medium 3, Claude Haiku 4.5
  $5-15 → GPT-5, Gemini 2.5 Pro, Claude Sonnet 4.5
  > $15 → Any model (cost is not the constraint)

Step 4: Do you need to self-host?
  Yes → Llama 4 Maverick
  No → Any cloud model

Step 5: Do you need multimodal (image input)?
  Yes → GPT-5, Claude Sonnet 4.5, Gemini 2.5 Pro
  No → Any model (Mistral Medium 3 is text-only)

5. Benchmark Results

Fill this section in during your evals — the whole point of the matrix is that your numbers replace the placeholders.

Record your own eval results here — public benchmark scores age fast.
Pull live numbers from LMArena / provider model cards when you adopt the matrix.

Benchmark: [Your eval — e.g., extraction accuracy on 100 test cases]
Model              | Score | Cost per 1K queries | p95 latency
───────────────────┼───────┼─────────────────────┼────────────
[candidate 1]      |       |                     |
[candidate 2]      |       |                     |
[candidate 3]      |       |                     |

Benchmark: [Second eval — e.g., code review pass rate]
Model              | Score | Cost per 1K queries | p95 latency
───────────────────┼───────┼─────────────────────┼────────────
[candidate 1]      |       |                     |
[candidate 2]      |       |                     |
[candidate 3]      |       |                     |

6. Fallback Strategy

When the primary model times out or rate-limits, fall through to the next tier — and pick a different provider for the backup, not just a smaller sibling that shares the same outage.

# Multi-model fallback chain — call_llm and the exception types are stubs;
# implement them against whichever SDK or gateway you use.
FALLBACK_CHAIN = [
    {"model": "gpt-5", "timeout": 30, "retry": 2},
    {"model": "claude-sonnet-4-5", "timeout": 30, "retry": 1},
    {"model": "gpt-5-mini", "timeout": 15, "retry": 1},
]

async def call_with_fallback(prompt: str, **kwargs):
    for config in FALLBACK_CHAIN:
        try:
            response = await call_llm(
                model=config["model"],
                prompt=prompt,
                timeout=config["timeout"],
                retry_count=config["retry"],
                **kwargs,
            )
            return response
        except (TimeoutError, RateLimitError, ServiceUnavailableError):
            continue  # Try next model
    
    raise Exception("All models in fallback chain failed")

7. Weighted Scorecard

When two models look equivalent on paper, force the decision through a weighted scorecard. Assign each criterion a weight that reflects your actual traffic — latency doesn’t matter for a nightly batch job, and cost doesn’t matter for a page that runs twice a day.

Criterion        | Weight | GPT-5 | Claude Sonnet 4.5 | Llama 4 Maverick | Weighted best
─────────────────┼────────┼───────┼───────────────────┼──────────────────┼──────────────
Accuracy         |  30%   |  9/10 |       9/10        |       7/10       | tie
Cost per query   |  25%   |  6/10 |       5/10        |       9/10       | Llama
Latency          |  20%   |  7/10 |       6/10        |       5/10       | GPT-5
Context window   |  10%   |  7/10 |       6/10        |      10/10       | Llama
Tool reliability |  10%   |  8/10 |       9/10        |       6/10       | Claude
Data control     |   5%   |  3/10 |       3/10        |      10/10       | Llama

Score each cell 1-10, multiply by the weight, and sum per column. In this example Llama 4 Maverick edges the total (7.45 vs 7.25 vs 6.80) — cost and data control carry it despite the weaker accuracy and latency rows. It won’t make the call for you, but it lays the trade-offs bare — and when a stakeholder asks “why this model?”, this is the page you hand them.

8. Total Cost of Ownership

The sticker price per query is what providers advertise — it’s not what you’ll actually pay. Before committing to a model, cost out the full pipeline: the calls that retry on timeout, the tokens spent on system prompts repeated on every request, the calls that produce unusable output and have to run again, and the latency tax — a model 2x slower that costs half as much is still a loss if users bounce. Rule of thumb: multiply the sticker price by 1.3 for retry waste and failed outputs, then add the engineering time spent working around the model’s weaknesses. Self-hosting adds a different line: a GPU node that sits 40% idle still bills at 100%. Don’t forget the line nobody writes down: switching costs. Every model you adopt trains your team on its quirks — the refusals, the format drift, the retry behavior — and that knowledge doesn’t transfer for free. If your team has to fight the model every week, the savings evaporate.

9. Running Your Own Benchmark

Vendor benchmarks tell you how a model performs on their test set, not on your workload. Instead, put together a small one: pull 50-100 real inputs from production traffic, spell out what counts as a good answer (valid JSON, correct result, a hard token cap), and run every candidate against that set. Cheap loop: run the set weekly on your top two candidates, log accuracy and cost per call, and keep the data for the next re-evaluation. A model that wins MMLU but mangles your Spanish invoices is the wrong model for you — your benchmark is the only number that counts.

10. Migrating Between Models

Model swaps are rarely drop-in. Prompts tuned for one provider drift on another: system prompt placement, tool-call formats, refusal thresholds, and output verbosity all change. When migrating, keep the old model serving while you run the new one in shadow mode for a week — same inputs, no user-visible outputs — and compare results on your regression set before cutting over. Budget for a prompt-tuning pass: expect 20-30% of prompts to need adjustments, mostly around output formatting and refusals. Teams that skip the shadow week usually find out about the drift in production — one support ticket at a time.

11. Open-Source vs Proprietary

Running an open-weight model yourself turns the pricing model inside out: per-token billing becomes fixed infrastructure plus ops work. It wins when volume is high and steady (a GPU pays for itself past a few million tokens a day), when data can’t leave your perimeter, or when you need fine-tuning that providers won’t give you. Hosted APIs still win on quality headroom, zero ops, and price while volume stays low or medium. The mature setup is usually both: proprietary for the tasks that need the flagship, self-hosted for high-volume commodity work.

12. Common Selection Mistakes

  • Choosing on benchmarks alone: leaderboards measure generic tasks, not your prompts — always run your own set.
  • One model for everything: a flagship on every call is how teams end up with a $9k/month classification pipeline.
  • Ignoring failure modes: pick for how the model fails (refusals, format drift) as much as how it succeeds.
  • No re-evaluation cadence: models get updated silently — re-run your benchmark quarterly or when the provider ships a new version.

All four share the same root: a decision made once and never revisited. The matrix only pays off if picking a model stays a recurring exercise.

13. Latency Budgeting

Latency is a product requirement before it’s a metric. Decide the budget first — an autocomplete needs p50 under 300ms, a chat answer tolerates 1-3s, a nightly report doesn’t care — and only then look at which models fit. Measure the full round trip: time-to-first-token, tokens-per-second, and the p95 tail, because the average hides the retries that make a fast model feel slow. Streaming also skews perception — a model feels instant while tokens trickle in and slow when you wait for the whole thing. Whatever you choose, add 30% headroom for provider degradation days — every API has them.

14. A Worked Cost Example

Workload: 40,000 queries/day, 1200 input + 300 output tokens each

Model              | $/1K in | $/1K out | Daily cost | Monthly | Latency p50
───────────────────┼─────────┼──────────┼────────────┼─────────┼────────────
GPT-5              | .00125  | .01000   | $180.00    | $5,400  | 900ms
Claude Sonnet 4.5  | .00300  | .01500   | $324.00    | $9,720  | 1.2s
GPT-5-mini         | .00025  | .00200   | $36.00     | $1,080  | 500ms
Llama 4 Maverick   | .00020  | .00060   | $16.80     | $504    | 700ms

The gap is still brutal: ~19x between the priciest flagship and the open-weight tier, and 5x between the two GPT-5 tiers — for a task that might not need the flagship at all. Run your benchmark (section 9) on the two cheapest candidates first — if the mini tier passes your quality bar, the flagship column is noise.

15. When to Re-Evaluate

Re-run the scorecard quarterly at minimum, and immediately when any of these fire: a provider ships a new flagship, a price cut lands on your volume tier, your monthly spend crosses a round-number threshold ($1k, $5k), or an open-weight release enters the top tier on real benchmarks. Model economics move faster than most infra decisions — the right model in January can be the wrong model in June — and the bill is usually the first place you notice the drift.

16. Decision Checklist

Before locking a model:
  [ ] Workload measured — real tokens, real requests/day, real task mix
  [ ] Own benchmark run — 50+ production inputs on the top 2 candidates
  [ ] Scorecard filled — weights reflect this feature, not generic averages
  [ ] TCO calculated — retries, system prompt tokens, failed outputs
  [ ] Latency budget confirmed — p50 and p95 against the product requirement
  [ ] Fallback defined — secondary model + routing rule from section 6
  [ ] Re-evaluation scheduled — quarterly, plus triggers from section 15

Keep the filled checklist next to the scorecard — six months from now it’s the fastest way to explain why the incumbent still earns its place.

See Also

Pricing and benchmark sources worth revisiting when you update the numbers:

Frequently Asked Questions

How often does a model pick need re-checking?

Quarterly is a good cadence — providers ship new versions and reprice constantly. Each time a new model lands, point your test set at it and weigh the cost, latency, and quality against your incumbent. Switch when something beats your current pick on quality per dollar, or when yours gets deprecated.

Is one model enough for every task?

No — task requirements differ too much. Cheap models (GPT-5-nano, Claude Haiku) handle classification and sentiment fine; flagships (GPT-5, Claude Sonnet) earn their price on code, extraction, and agent reasoning. Routing simple work to small models typically cuts the bill 50-80% versus running everything on the flagship.

How do I benchmark models on my own workload?

Build the set from real traffic — a hundred-plus inputs, each with the output you would accept written next to it. Run every candidate at temperature 0, then score with whatever fits the task — exact match or F1 where it's mechanical, an LLM judge for subjective quality, human review on a sample. Put quality next to cost per 1K queries and p95 latency, and pick the cheapest model that clears your quality bar.

When does self-hosting beat a cloud API?

Self-host when privacy rules force it, when volume makes API costs exceed GPU costs (usually 100K+ queries/day territory), or when you need sub-100ms latency or fine-grained control. Stay on cloud APIs for low-to-medium volume, when you need the best available model, when you'd rather not run infrastructure, or when you need multimodal capabilities open models lack.

What actually changes between GPT-5 and GPT-5-mini?

GPT-5 is the full-capability model — best reasoning, code, and complex-task performance. GPT-5-mini keeps most of that capability at roughly a fifth of the cost, and nano goes cheaper still. For classification, simple extraction, and short summaries, the small tiers produce near-identical output. Reserve the flagship for complex reasoning and high-stakes generation where quality matters more than cost.

Which cost mistake do most teams keep making?

They budget the sticker price per query and forget the rest. The real number adds retry waste (calls that time out and run again), the system prompt tokens you pay for on every request, and the outputs you throw away because they failed validation. A workload that looks like $200/month on the pricing page is usually closer to $300 once you meter it — and the gap only shows up on the invoice.

Is upgrading on every new release a good idea?

No — upgrade when the benchmark says so, not the release notes. New flagships land with new failure modes, and prompts tuned for the old model can regress even when quality improves on average. Shadow-test the new model against your regression set, promote it only when it beats the incumbent on your tasks, and keep the old version pinned until the cutover is proven. Chasing every release is how you end up re-tuning prompts forever.

Can several models share one feature?

They can, and most teams do it through a router — the easy requests (classification, extraction, short replies) go to the cheap model and only what fails a confidence check escalates to the flagship. A cascade where 80% of traffic lands on the mini tier usually cuts the bill by two-thirds without touching quality on the hard cases. The matrix applies at the router: give each tier its own row and measure the mix monthly.