Aider with an OpenAI-compatible endpoint
Aider is terminal pair programming: it reads your repo, writes edits, and commits them. It reaches models through LiteLLM, which means any OpenAI-compatible endpoint works — as long as you set the base URL and prefix the model ID correctly. This page covers both, the double-prefix trap that catches people moving between gateways, and what a real Aider session costs given how it spends tokens.
The two values Aider needs
Everything reduces to a base URL and a model ID. Aider reads the base URL from OPENAI_API_BASE, from --openai-api-base, or from openai-api-base in a config file. The model ID carries an openai/ prefix because Aider routes OpenAI-compatible traffic through LiteLLM, and the prefix is how LiteLLM picks the request format.
# Aider reads these on startup. The base URL must end in /v1.
export OPENAI_API_BASE="https://aicomp.ai/v1"
export OPENAI_API_KEY="sk-your-key"
# The openai/ prefix is not decoration — Aider routes OpenAI-compatible
# models through LiteLLM, and the prefix is how it picks the wire format.
aider --model openai/deepseek-v4-pro
Three things go wrong here more often than anything else. The first is a missing /v1. The second is a doubled one — people write …/v1/v1 because a gateway's own docs show a full path somewhere else. The third is the prefix: without openai/, Aider assumes you mean a provider it has built-in support for, and the failure looks like a model problem rather than a routing problem.
Persist it in the repo, not in your shell
Environment variables are fine for a one-off, but they are invisible to the next person and to your future self on another machine. A .aider.conf.yml in the project root is read automatically on every launch, which makes the endpoint part of the repository instead of part of your shell history.
# .aider.conf.yml — committed with the repo, so every contributor
# gets the same endpoint without setting environment variables.
openai-api-base: https://aicomp.ai/v1
model: openai/deepseek-v4-pro
# Optional: separate the cheap model that writes edits from the strong
# one you talk to. This is where most of the savings actually come from.
# editor-model: openai/deepseek-v4-flash
# Aider re-reads the repo map on every request. Narrowing the scope is
# the cheapest change you can make to the bill.
# map-tokens: 2048
Two settings in that file are worth knowing about even if you do not use them immediately. editor-model separates the model that writes edits from the model you converse with — a cheap editor model plus a strong chat model is usually better value than one expensive model doing both. map-tokens caps the size of the repository map Aider rebuilds and re-sends, which matters because of how Aider spends tokens.
Why Aider's bill looks different from a chatbot's
Aider is input-heavy in a way chat applications are not. Every request carries a map of your repository — file paths, class and function signatures, dependency structure — plus the files currently in scope. On a mid-sized project that map alone runs to five figures of tokens, and it is re-sent on every turn whether or not you changed anything.
That inverts the usual advice. Most model comparisons rank by output price, and for a chat workload that is right. For Aider, the input rate carries much more of the bill, so the model that looks expensive by output rate can be the cheaper one here. The table below uses a realistic shape: a 200k-token request — roughly 120k of repo map and context, 8k of output — repeated twelve times a day across a twenty-day month.
| Model | Vendor | Rate in / out per 1M | Per request | Per month |
|---|---|---|---|---|
| gpt-5.6-luna | OpenAI | $0.1 / $0.6 | $0.025 | $6 |
| MiniMax-M3 | MiniMax | $0.15 / $0.6 | $0.035 | $8 |
| deepseek-v4-flash | DeepSeek | $0.22 / $0.66 | $0.049 | $12 |
| gemini-3.7-flash | $0.375 / $1.875 | $0.090 | $22 | |
| claude-haiku-4-5-20251001 | Anthropic | $0.5 / $2.5 | $0.120 | $29 |
| deepseek-v4-pro | DeepSeek | $0.66 / $1.98 | $0.148 | $35 |
| glm-5.3 | Zhipu | $0.7 / $2.2 | $0.158 | $38 |
| qwen3.8-max | Alibaba | $1 / $3 | $0.224 | $54 |
| claude-sonnet-5 | Anthropic | $1 / $5 | $0.240 | $58 |
| gpt-5.6-terra | OpenAI | $1 / $6 | $0.248 | $60 |
| kimi-k3 | Moonshot | $1.5 / $7.5 | $0.360 | $86 |
| claude-opus-5 | Anthropic | $2.5 / $12.5 | $0.600 | $144 |
Verify before you trust a long session
Aider will happily run for twenty minutes before surfacing a configuration error, and by then you have burned tokens finding out. One cheap request tells you whether the endpoint, key and model ID are all correct.
# Before trusting a long session, prove the wiring with one request.
curl "$OPENAI_API_BASE/chat/completions" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"deepseek-v4-flash","messages":[{"role":"user","content":"Reply with the word ok."}],"max_tokens":5}'
# 200 + JSON -> endpoint, key and model ID are all correct.
# 401 -> the key is not being read.
# 404 -> the base URL is missing /v1, or has it twice.
# model error -> the ID is not in the current /v1/models response.
The status code is diagnostic. A 401 means the key is not being read — usually a shell that never picked up the export. A 404 at this layer is almost always the base URL, not the model. A model error with a 400 means the ID you typed is not in the current /v1/models response, which is worth checking directly rather than guessing at naming conventions.
How this fails in practice
| What you see | What it usually is | Fix |
|---|---|---|
| 404 on every request | Base URL missing /v1, or /v1 written twice | Check the exact string; the endpoint is …/v1, and Aider appends /chat/completions itself |
| Unknown provider or model | Model ID missing the <code>openai/</code> prefix | Prefix it: openai/deepseek-v4-pro |
| Double prefix error | Gateway model IDs already contain a provider segment | Some gateways return IDs like openai/gpt-…; prefixing again gives openai/openai/…. Use the ID as /v1/models returns it, plus one prefix |
| 401 with a key that works elsewhere | Shell did not inherit the export, or the config file is not in the working directory | Re-export in the current shell, or move the values into .aider.conf.yml |
| Empty or truncated responses | Model does not stream, or a repo map that exceeds the context window | Test with a small --map-tokens and a longer-context model |
| Bill far higher than expected | Repo map re-sent every turn; large or generated files in scope | Narrow the file scope; check what /tokens reports per request |
https://aicomp.ai/v1).
Create one free →
FAQ
Does Aider work with any OpenAI-compatible endpoint?
Yes, for chat completions. Aider routes through LiteLLM, so anything speaking the OpenAI chat format works once you set the base URL and prefix the model ID. Feature support beyond chat — such as certain reasoning controls — depends on what the endpoint exposes.
Why does the model need an openai/ prefix if I am not using OpenAI?
The prefix tells LiteLLM which request format to build, not which company to bill. Every OpenAI-compatible endpoint uses that same format, so the prefix stays even when the traffic goes to a gateway or a local server.
Can I use one model for chat and a different one for edits?
Yes. Set model for the conversation and editor-model for the code changes. This is usually where the money is: a cheap fast editor model plus a strong reasoning model for the parts that need one.
Where should I put the API key so it is not committed?
Leave openai-api-key out of the committed config and keep it in the environment, or point the config at a variable. The base URL and model ID are safe to commit — they tell the next contributor which endpoint the project expects.
Why is Aider more expensive per session than a chat interface?
Because every request carries a map of your repository on top of the conversation. That is input volume a chat app never sends, so the input rate matters more here than in most comparisons.
How do I stop Aider sending my whole repository?
Add only the files that matter with /add, drop the rest with /drop, and cap the map with map-tokens. Scope is the single biggest cost control available in Aider.