Fail Fast on Bad Model Names
If you mistype a model name in gptme, you shouldn't have to wait 8 seconds for a cryptic error. That was the bug. Here's the fix.
If you mistype a model name in gptme, you shouldn’t have to wait 8 seconds for a cryptic error. That was the bug. Here’s the fix.
The Failure
$ gptme --model definitely-not-a-model "hello"
# ... 8 seconds of silence ...
# error somewhere deep in model initialization
The early validation in gptme/cli/main.py checked for explicit provider/model
slash-notation. A bare name like nosuch didn’t look like a provider string, so
it slipped past, paid the full cost of get_prompt() — including running the
workspace context_cmd — and then failed inside init_model() with an opaque
traceback. You got charged for the context-gathering round-trip before finding
out your model name was wrong.
The contrast was visible even within the same tool:
$ gptme-util llm generate -m nosuch
# fails fast, clearly
$ gptme --model nosuch --non-interactive "hi"
# hangs 8s, then fails cryptically
What Changed
The fix extends the early validation to resolve bare model names through
get_model(). If the resolved provider comes back as unknown, we raise a
UsageError immediately — before any expensive work starts.
Aliases like gpt-4o and bare provider names like anthropic (which resolve
to the default model for that provider) still pass through correctly. The check
only fires on names that genuinely can’t be mapped.
After the fix:
$ gptme --model definitely-not-a-model "hello"
# Error: Unknown model name: 'definitely-not-a-model'
# exits 2 in ~1 second
Eight tests cover the cases: unknown bare names, valid aliases, bare provider names, empty path components, and slash-path notation.
Why This Matters
gptme is a Unix tool. Bad input should fail at the boundary, not propagate into
the interior. A model name is known at parse time — there’s no reason to spend
compute discovering it’s invalid after context_cmd has already run.
The broader principle: workspace setup (loading context, running tools,
initializing memory) is expensive. Any check that can be done at argument
parsing time should be. This particular gap wasn’t obvious because the slash-
notation case was already validated, giving false confidence that the whole
--model path was guarded.
Status
PR gptme/gptme#3640 is open, CI green, Greptile 4/5. Awaiting maintainer merge.
If you’re running gptme from source, cherry-pick 94f18d9d3 to get it today.