Point Aider at an OpenAI-compatible API base.

Updated 2026-07-16

Aider connects to OpenAI-compatible endpoints with two environment variables and a model prefix. Set OPENAI_API_BASE to https://api.apisrouter.com/v1, run aider --model openai/<model-id>, and pair programming sessions route through one key with every catalog model addressable.

Quick answer: two env vars and a model prefix.

Aider's documented OpenAI-compatible path is exactly this: export OPENAI_API_BASE with your endpoint, export OPENAI_API_KEY with the key for it, and prefix the model name with openai/ so Aider speaks the chat-completions protocol to that base. The string after the prefix is passed through to the endpoint, so any id the gateway serves is fair game, Claude and DeepSeek ids included. That is the whole connection. On Mac and Linux use export; on Windows use setx and open a new shell, since setx does not affect the current session. The same values can live in Aider's config file or a .env file if you prefer per-project configuration over shell state.

export OPENAI_API_BASE=https://api.apisrouter.com/v1
export OPENAI_API_KEY=sk-APIsRouter-...

aider --model openai/claude-sonnet-4-6

How Aider resolves models and providers.

Aider (Aider-AI on GitHub, roughly 47K stars) is the original terminal pair programmer: it maps your git repo, takes change requests in chat, edits files directly, and commits the result. Under the hood it routes model calls through litellm, which is why the openai/ prefix matters: litellm reads the prefix to choose a provider protocol, and openai/ means "chat-completions against whatever OPENAI_API_BASE says." A prefixless model name gets provider-inferred from its spelling instead, which routes a Claude id toward Anthropic's native API and your ANTHROPIC_API_KEY rather than your gateway. There is one behavior specific to Aider worth knowing before your first session: it keeps its own registry of model capabilities, and a model it does not recognize triggers the warning "Unknown context window size and costs, using sane defaults", after which Aider assumes an unlimited context window and zero cost. The session still works, but two useful subsystems degrade: token budgeting cannot warn you before you blow past the real context limit, and the in-session cost display reads zero. The fix is a small metadata file, covered below, and it is worth the two minutes. Aider also runs more than one model per session. The main model does the coding; a weak model handles commit messages and chat summarization; and in architect mode, a separate editor model applies the plan. Each accepts the same openai/ prefix, so all three can route through the gateway on one key.

Full setup: connection plus model metadata.

The connection is the two variables above. The polish is registering metadata so Aider treats gateway models as known quantities. Create .aider.model.metadata.json in your home directory, the git repo root, or the working directory (or pass --model-metadata-file), keyed by the fully qualified name including the openai/ prefix; the litellm_provider field should match that prefix. With max_input_tokens registered, Aider's context budgeting works against the model's real window instead of assuming it is infinite. A second optional file, .aider.model.settings.yml, tunes behavior per model: edit_format controls how Aider asks for code changes (diff variants for models that handle them, whole-file for models that do not), and use_repo_map controls repo-context inclusion. Aider cannot infer the best edit format for a model it does not recognize, so declaring it is the difference between a model looking mediocre and performing at its level.

{
  "openai/claude-sonnet-4-6": {
    "max_input_tokens": 200000,
    "max_output_tokens": 64000,
    "litellm_provider": "openai",
    "mode": "chat"
  },
  "openai/deepseek-v4-pro": {
    "max_input_tokens": 128000,
    "max_output_tokens": 16000,
    "litellm_provider": "openai",
    "mode": "chat"
  }
}

Choosing main, weak, and editor models.

Aider sessions are long and iterative, which makes model comparison unusually honest here: run the same feature branch with two main models on different days and the difference shows up in how often you type /undo. One endpoint makes each candidate a flag change, and per-key usage prices each experiment.

  • The main model carries every edit. It reads the repo map, reasons over your files, and produces diffs, so this is where claude-sonnet-4-6 or gpt-5.5 belongs; a model that fumbles diff syntax costs you review time on every change.
  • The weak model (--weak-model) writes commit messages and summarizes chat history. It fires constantly and never touches code, so route it to a fast, low-priced id through the same gateway rather than letting it default elsewhere.
  • Architect mode splits planning from editing: the main model plans, the editor model (--editor-model) applies. A strong reasoner planning with a coding-tuned id like kimi-k2.7-code applying is a pairing single-vendor keys cannot express.
  • deepseek-v4-pro and gpt-5.4 are worth benchmarking as daily-driver main models on refactor-heavy work, where per-session token volume makes the price difference compound.

Pay-as-you-go · transparent per-model pricing

Selected models are priced below official list prices. Exact input, output, cache, and per-request prices are shown for each model.

ModelOfficial PriceOur Price
Claude Sonnet 4.6$3.00 / $15.00 per M$2.40 / $12.00 per M
GPT-5.5$5.00 / $30.00 per M$4.00 / $24.00 per M
GPT-5.4$2.50 / $15.00 per M$2.00 / $12.00 per M
DeepSeek V4 Pro$0.43 / $0.87 per M$0.39 / $0.78 per M
Kimi K2.7 Code$0.95 / $4.00 per M$0.85 / $3.60 per M

The failure modes specific to Aider.

Trusting the "sane defaults." The unknown-model fallback assumes unlimited context and zero cost. Practically, that means Aider will happily let a long session grow past the model's real window until the gateway rejects the request or the model quietly loses the early context, and the cost tracker shows nothing the whole time. Register metadata; both problems disappear. Dropping the openai/ prefix. Without it, litellm infers the provider from the model name. Claude ids route toward Anthropic's API and fail on a missing ANTHROPIC_API_KEY, which reads like a key problem when it is a prefix problem. Metadata that does not match. Entries in .aider.model.metadata.json are keyed by the fully qualified name, prefix included, and litellm_provider should agree with that prefix. A bare-id key or a mismatched provider field silently fails to apply, and you are back on defaults without an error saying so. Windows shell state. setx writes the variable for future shells only. Running aider in the same terminal where you just ran setx uses the old environment, and the resulting 401 is a shell-lifecycle issue, not a credentials issue. The wrong edit format. An unregistered model gets a default edit format that may not be what it handles best. If a strong model keeps producing edits Aider rejects, set edit_format explicitly in .aider.model.settings.yml before concluding the model cannot code.

Who routes Aider through a gateway.

  • Daily Aider users who want Claude, GPT, and DeepSeek switchable per session with --model, without maintaining a vendor account per model family.
  • Developers pairing a frontier main model with a fast weak model for commit messages, both billed to one key with per-session visibility.
  • Architect-mode users mixing a planning model and an editing model from different vendors in the same session.
  • Teams onboarding engineers with one secret instead of a vendor-key checklist, with per-key usage as the spend report.
  • Developers without access to a given vendor's billing. Top-up based access with no card requirement removes the per-provider sign-up dependency.

Verify the endpoint and debug the first session.

List the gateway's models before starting; the id after openai/ must match a served id exactly, version suffixes included. First-session failures sort quickly. A 401 means OPENAI_API_KEY is not visible to the shell that launched aider (new shells only on Windows after setx; check echo in the same terminal). A model-not-found error from the gateway is an id typo. An error mentioning a different vendor's key means a prefixless model name routed natively. And the unknown-model warning at startup is not an error, but it is your cue to add the metadata file before a long session, not after one hits the real context limit. In session, Aider's own token and cost readout becomes accurate once metadata is registered, and the APIsRouter console shows the same sessions from the endpoint side: per-request model, token counts, and spend. For an all-day pair programmer, that per-key view is the honest answer to what a week of Aider actually costs.

curl -s https://api.apisrouter.com/v1/models \
  -H "Authorization: Bearer $OPENAI_API_KEY" | head -50

FAQ

How do I connect Aider to an OpenAI-compatible endpoint?

Export OPENAI_API_BASE with the endpoint URL and OPENAI_API_KEY with its key, then run aider --model openai/<model-id>. This is Aider's documented openai-compat path; the openai/ prefix tells its litellm layer to speak chat-completions to your base URL.

Can Aider run Claude or DeepSeek models through this setup?

Yes. The id after openai/ is passed through to the endpoint as a plain string, so any model the gateway serves works: aider --model openai/claude-sonnet-4-6 or openai/deepseek-v4-pro. Keep the prefix, or the id gets provider-inferred and routed away from your base.

What does the "Unknown context window size and costs" warning mean?

Aider does not recognize the model, so it assumes an unlimited context window and zero cost. Sessions work, but context budgeting and the cost display are wrong. Register the model in .aider.model.metadata.json, keyed by its fully qualified openai/ name, and the warning and both problems go away.

Do the weak model and editor model route through the gateway too?

Yes, if you point them there: --weak-model openai/<fast-id> for commit messages and summarization, and --editor-model openai/<id> in architect mode. All three slots accept the prefix, so one key can cover a cross-vendor main/weak/editor mix.

Why is Aider still asking for an Anthropic key?

A model name went in without the openai/ prefix. litellm inferred the vendor from the name and tried the native Anthropic route, which wants ANTHROPIC_API_KEY. Add the prefix and the request goes to OPENAI_API_BASE with your gateway key instead.

Should I set edit_format for gateway models?

For models Aider does not recognize, yes. edit_format in .aider.model.settings.yml controls how Aider requests code changes, and frontier models generally do their best work with a diff format. Leaving an unknown model on defaults can make a strong model look worse than it is.