Aider Model Not Found Fix 2026: Every Cause of the Error and How to Clear It

aiderollamalitellmtroubleshootingai

TL;DR: Aider almost never fails because a model is truly “missing” — it fails because the name you passed can’t be routed to a provider. Add the provider prefix (openai/, anthropic/, openrouter/, ollama_chat/), confirm the exact string with aider --list-models <partial>, and make sure the matching API key is exported. That clears the large majority of cases.

What you’ll be able to fix after this guide:

  • The hard litellm.BadRequestError: LLM Provider NOT provided crash that stops Aider before it starts.
  • The softer Unknown context window size and costs, using sane defaults warning — what it actually means and when to ignore it.
  • Local-model failures with Ollama and LM Studio, where the model exists but Aider still can’t reach it.

Honest take: If you’re stuck, run aider --list-models <part-of-the-name> first. Nine times out of ten the fix is staring at you in that output — you had a typo or a missing prefix, not a broken install.

First, know which error you actually have

“Model not found” is a catch-all people type into search. Aider produces several distinct messages, and they have different fixes. Match yours to this table before you change anything.

What you seeWhat it meansThe fix
litellm.BadRequestError: LLM Provider NOT providedThe name can’t be mapped to any providerAdd a provider prefix
Model <x>: Unknown context window size and costs, using sane defaultsAider doesn’t have metadata for this model — not fatalIgnore, or add model settings
... Did you mean one of these? - <y>Likely a typoCopy the suggested exact name
Model <x>: Missing these environment variables: - <KEY>Known model, but its API key isn’t setExport the listed variable
Model <x>: Unknown which environment variables are requiredModel too new/obscure for Aider to know its keysSet the key manually, check litellm docs
Local model hangs or 404sOllama/LM Studio prefix or base URL wrongUse ollama_chat/, set OLLAMA_API_BASE

The 30-second diagnostic: --list-models

Before touching config files or reinstalling anything, ask Aider what it knows. Run:

aider --list-models sonnet

Pass any fragment of the model name. Aider searches its full catalog (it uses litellm under the hood, which supports hundreds of models) and prints every match. Per the official docs, aider --list-models turbo returns matches like gpt-4-turbo, gpt-4-turbo-2024-04-09, and so on.

You can also list an entire provider’s catalog by passing just the prefix:

aider --list-models openai/
aider --list-models openrouter/anthropic/

Whatever exact string appears in that output is the string you paste after --model. If your intended model isn’t in the list at all, you’ve found your answer: the name is wrong, or it needs a prefix that tells litellm which provider owns it.

Cause 1 — the missing provider prefix (the real “model not found”)

This is the one that hard-crashes. You run something like:

aider --model claude-sonnet-4

and get:

litellm.BadRequestError: LLM Provider NOT provided. Pass in the LLM provider you are trying to call.

litellm can’t guess which company hosts a bare model name, so it refuses. The fix is to prefix the name with the provider:

aider --model anthropic/claude-sonnet-4-20250514
# or via OpenRouter
aider --model openrouter/anthropic/claude-sonnet-4

The prefixes you’ll use most in 2026:

  • openai/ — GPT models on OpenAI’s own API
  • anthropic/ — Claude models direct from Anthropic
  • gemini/ — Google Gemini
  • openrouter/<vendor>/<model> — anything routed through OpenRouter
  • ollama_chat/ — local models via Ollama (more on this below)
  • azure/ — models served through Azure OpenAI

Aider ships short aliases too — sonnet, opus, gemini, flash, o3-mini — and those resolve without a prefix because Aider maps them internally. The trouble starts when you type a specific dated model string without its provider. When in doubt, prefix it.

Cause 2 — a typo, and Aider already knows it

If your string is close to a real model, Aider is helpful about it:

Model gpt-5o: Unknown context window size and costs, using sane defaults.
Did you mean one of these?
- gpt-4o

Don’t fight this. Copy the suggested name verbatim. The most common self-inflicted versions are transposed digits (gpt-4o vs gpt-5o), a dropped date suffix, or claude-3.7 where the catalog wants claude-3-7. --list-models is the tie-breaker whenever the “Did you mean” list has more than one candidate.

Cause 3 — the model is found, but the key isn’t

Sometimes the model resolves fine and Aider tells you exactly what’s missing:

Model azure/gpt-4-turbo: Missing these environment variables:
- AZURE_API_BASE
- AZURE_API_VERSION
- AZURE_API_KEY

This is not a “not found” error even though it feels like one — the model is known, its credentials aren’t set. Export the variables it names:

export ANTHROPIC_API_KEY=sk-ant-...
export OPENAI_API_KEY=sk-...

litellm reads keys lazily, so a missing key only blows up when you actually call that provider — which is why the same install can work with one model and fail with another. On Windows, if you set a variable with setx, the official docs note you’ll need to restart the terminal before it takes effect. That single detail accounts for a surprising number of “I set the key and it still fails” reports.

A cleaner long-term option: put keys in ~/.aider.conf.yml or a .env file in your project root, so you’re not re-exporting them every shell session.

Cause 4 — local models (Ollama / LM Studio): found on disk, unreachable in Aider

Here the model genuinely exists — ollama list shows it — but Aider can’t talk to it. Three things trip people up, in order of frequency.

Use the ollama_chat/ prefix, not ollama/. The Ollama docs for Aider explicitly recommend ollama_chat/ over the older ollama/ prefix, because it uses the chat completion endpoint that Aider’s editing flow expects:

export OLLAMA_API_BASE=http://127.0.0.1:11434
aider --model ollama_chat/qwen2.5-coder:32b

Point Aider at the right base URL. OLLAMA_API_BASE defaults to http://127.0.0.1:11434. If Ollama runs on another host, in Docker, or on a non-default port, set it explicitly or every request 404s.

Match the tag exactly. The string after the prefix must match what ollama list prints, tag included. ollama_chat/qwen2.5-coder and ollama_chat/qwen2.5-coder:32b are different names to litellm; if you only pulled the tagged version, the bare name won’t resolve.

For LM Studio the shape is the same idea with a different prefix and base URL — start LM Studio’s local server, then point Aider at it. We walk through that end to end in the Aider + LM Studio setup guide, and the full Ollama path lives in Aider with Local LLM via Ollama.

The silent context-window trap that looks like a bad model

Even after Aider connects, Ollama can make a working model look broken. Ollama defaults to a 2k token context window and silently discards anything past it — so on a real codebase Aider sends the file, Ollama drops most of it, and the model returns confused or truncated edits. It reads like “the model is wrong” when the real problem is dropped context.

Aider tries to size the window to your request plus about 8k tokens for the reply, but the reliable fix is to pin it. Create .aider.model.settings.yml in your project or home directory:

- name: ollama_chat/qwen2.5-coder:32b
  extra_params:
    num_ctx: 65536

Pick a num_ctx your VRAM can actually hold — a bigger window costs memory. If you’re not sure what your hardware supports, our sister site runaihome.com has the numbers by card in best local AI models by VRAM.

Cause 5 — “Unknown context window size and costs” is a warning, not a failure

This message panics people because it appears right where a fatal error would:

Model foobar: Unknown context window size and costs, using sane defaults.

It is not an error. Aider is telling you it doesn’t have metadata for this model, so it’s assuming an unlimited context window and no token cost, then continuing normally. For a self-hosted or brand-new model, that’s usually fine.

Two reasons to act on it anyway:

  1. You want accurate cost tracking. With no pricing data, Aider’s /tokens spend estimate is blank.
  2. The model has a real context limit you need Aider to respect, so it doesn’t overflow the window.

Both are solved by supplying the metadata yourself, which is Cause 6.

Cause 6 — a model so new litellm hasn’t shipped metadata for it

In a fast-moving year, you’ll hit models Aider recognizes enough to run but not enough to describe — you’ll also see Unknown which environment variables are required for the truly obscure ones. Give Aider the facts in a metadata file. Create .aider.model.metadata.json:

{
  "openrouter/some-vendor/new-model-2026": {
    "max_input_tokens": 200000,
    "max_output_tokens": 8192,
    "input_cost_per_token": 0.000003,
    "output_cost_per_token": 0.000015,
    "litellm_provider": "openrouter"
  }
}

Now the warning disappears, cost tracking works, and Aider enforces the real context limit. For provider-specific keys you can’t find, the litellm providers page lists the required environment variables per model.

Verify the fix

Don’t declare victory off a clean launch screen. Confirm the model is live:

aider --model anthropic/claude-sonnet-4-20250514
# inside the session:
/model

/model echoes the exact model Aider resolved. If it matches what you intended and a trivial request (add a docstring to this function) returns a real edit, the routing is correct. If the launch banner still shows the “sane defaults” line but everything works, that’s expected — see Cause 5.

FAQ

Is “model not found” the same as “LLM Provider NOT provided”? Functionally, for your purposes, yes — both mean Aider couldn’t route your model string. The provider error is the specific hard crash; add a prefix to clear it.

Why does the same model name work for a teammate but not me? Almost always a missing API key on your machine (litellm fails lazily, only when that provider is called) or a different Aider/litellm version with a different catalog. Compare aider --version and check your exported keys.

Do I need to reinstall Aider to get a new model? Sometimes. Model catalogs ship with litellm, so a brand-new model may need pip install --upgrade aider-chat. But if the model already exists in your version, a metadata file (Cause 6) gets you there without upgrading.

My Ollama model runs in the terminal but gives garbage in Aider. Bug? Usually the 2k context trap (Cause 4), not a bug. Pin num_ctx in .aider.model.settings.yml and it typically clears up.

Can I just use OpenRouter to avoid all this? Largely, yes. If you set no keys, Aider offers to connect you to OpenRouter, which fronts most popular models behind one key and one openrouter/ prefix — fewer provider variables to manage. It’s the lowest-friction path if you’re tired of chasing prefixes.

Sources

Last verified: Jul 12 2026. Pricing and model names change frequently — re-check the official pages before relying on any specific string.

Was this article helpful?