Husk talks to eleven model providers through one interface. ModelRouter in
@husk-ai/models answers four questions and nothing else:
- What is reachable right now? —
detect() - Which model does this alias mean? —
resolve() - Can we afford it? — the budget check
- What do we do when the provider says no? — the fallback chain
A provider is only listed once it is reachable and reports at least one model. Providers has the environment variable and the sign-up path for each one.
Aliases
Nine aliases resolve to a fixed model id. Three resolve to a strategy, because their honest answer depends on what is running on this machine right now.
| Alias | Resolves to |
|---|---|
opus | anthropic/claude-opus-5 |
sonnet | anthropic/claude-sonnet-5 |
haiku | anthropic/claude-haiku-4-5-20251001 |
gpt | openai/gpt-4.1 |
gemini | google/gemini-2.5-pro |
flash | google/gemini-2.5-flash |
gemma | ollama/gemma3 |
llama | ollama/llama3.2 |
qwen | ollama/qwen2.5-coder |
local | strategy: the best Ollama or LM Studio model that is running |
free | strategy: best free model that is actually reachable |
auto | strategy: best available model, by tool support and then quality |
resolveAlias tries five things, in this order, and stops at the first that answers:
- A user override from
modelAliasesin~/.husk/config.json. - A dynamic alias —
local,free,auto. - A canonical alias from the table above.
- An explicit
provider/modelid. Split at the first slash, sotogether/meta-llama/Llama-3.3-70B-Instruct-Turbois one model, not two. - A bare model name, but only when exactly one provider in the catalog offers it.
Anything else throws E_MODEL_UNAVAILABLE and lists the aliases it does know.
Pinning your own
{
"modelAliases": {
"fast": "groq/llama-3.3-70b-versatile",
"sonnet": "anthropic/claude-sonnet-5"
}
}"model": "free" in the same file is shorthand for an auto override: it is what auto
means on this machine, unless modelAliases has an auto entry of its own.
An override may point at another alias. The resolver follows up to eight hops and refuses a cycle rather than hanging:
error Model alias "a" loops back on itself
hint: Fix the modelAliases entry for "a" in ~/.husk/config.json.What auto, free and local actually pick
The router pools every reachable model, drops those the prompt would price over the ceiling, then sorts:
| Strategy | Pool | Sort |
|---|---|---|
auto | every reachable model | tool support, then quality, then size, then context window |
free | every reachable model | free models first, then input price, then as auto |
local | only ollama and lmstudio | free first, then input price, then as auto |
"Quality" is a maintainer's judgement number in the catalog, 0–100. It is not a benchmark
score. A model nobody has catalogued — a fresh ollama pull — scores 40 if it is free
and 50 if it is not. Size settles a tie: a model whose parameter count is known comes
first, 7B or more beats a smaller one, and within that tier the smaller one wins.
Provider priority plays no part, and nor does price for auto.
husk run picks its model before the run starts, so its header can name it, and it
resolves the three its own way, walking the providers by
priority, highest first:
autois the best model of the first reachable provider that lists one. WithANTHROPIC_API_KEYset, that isanthropic/claude-opus-5, whatever else is reachable.freeis the first free model of the first provider that has one, so Gemini Flash wins over a local Ollama whenGOOGLE_API_KEYis set.localtries LM Studio before Ollama.
Under a ceiling of $0, each of the three considers only models priced at zero, as the router does.
Detection
detect() probes every registered provider in parallel and caches the answer for
30 seconds. Each probe is capped at 3 seconds; a provider that hangs is reported as
unavailable with the reason rather than stalling the report, and so is one that answers
but lists no model. Nothing here throws. husk doctor does not call
it: doctor asks each provider itself and shows that provider's own reason and fix.
Providers with a key requirement answer instantly from the environment. Keyless local servers — Ollama, LM Studio — are probed over the network with their own 2-second timeout.
Fallback
RouterRequest.fallbacks and a husk's fallbackModels build an ordered candidate list:
the requested model first, then each declared fallback, then whatever the strategy
ordering turns up. Each candidate is tried in turn.
Two rules shape the behaviour:
- A downgrade is never silent. The caller gets a
warningevent naming what failed and what replaced it. A run that quietly finished on an 8B local model when it asked for Opus is worse than a run that failed. - A 400 is never retried, anywhere, and nor is a 422. The request is malformed; shopping a malformed request around six providers wastes six round trips.
Within one candidate, the router makes up to 3 attempts. The wait before a retry is random, up to 400 ms before the second attempt and up to 800 ms before the third. When a candidate has failed for good, the router moves on to the next, unless the failure was an abort, a 400 or a 422. A provider's status becomes an error code:
| Status | Code | Retried |
|---|---|---|
| 401, 403 | E_NO_CREDENTIALS | no |
| 404 | E_MODEL_UNAVAILABLE | no |
| 400, 422 | E_MODEL_ERROR | no, and no fallback |
| 429 | E_QUOTA | yes |
| 408, 409, 425, 5xx | E_MODEL_ERROR | yes |
| any other | E_MODEL_ERROR | no |
A network failure is E_MODEL_ERROR and is retried. An abort is E_ABORTED, and
E_BUDGET_EXCEEDED is not retried either.
On a stream, a candidate can only be abandoned before it has produced content. Once
a token has reached the caller there is nothing honest to do with a mid-stream failure
except report it, so that case ends in an error event rather than a silent restart on
a different model.
Both husk run and POST /v1/husks/:name/run honour fallbackModels. husk run first
finds the first reachable model of [model, ...fallbackModels], so its header names what
will run, then calls a ModelRouter with the list on every request. A run over the API
hands the router the same list.
For that first step the CLI keeps its own alias table, resolveModel() in
packages/cli/src/lib/models.ts, which resolves auto, free and local as
above. After each fixed alias's own id it
lists older ones: anthropic/claude-3-opus-20240229 for opus,
anthropic/claude-3-7-sonnet-20250219 and anthropic/claude-3-5-sonnet-20241022 for
sonnet, anthropic/claude-3-5-haiku-20241022 for haiku, and openai/gpt-4o for
gpt. Anthropic's provider lists only the catalog, which has no Claude 3 model, and
openai/gpt-4.1 is tried first and is listed whenever OpenAI is, so those never change
what is picked. It also matches an Ollama model without its :latest, so llama finds
llama3.2:latest.
Cost
Every response comes back with a costUsd, worked out from the catalog price and the
reported token counts; no provider's own figure is read. A model the catalog does not
price therefore comes to $0. A local model is genuinely $0.00, not a rounded-down
estimate.
Cost and budgets covers the estimate, the maxCostUsd ceiling, and which
prices in the catalog are published figures rather than conservative guesses.
Where to go next
- Providers — every provider, its environment variable, and how to get a key. Four have a real free tier.
- Local models — Ollama and LM Studio end to end, and an honest account of what a 7B model can and cannot do as an agent.
- Cost and budgets — estimation, the ceiling, and why local is zero.