Short answer
To use Aider with APIVAI, set two environment variables, OPENAI_API_BASE=https://api.apivai.com/v1 and OPENAI_API_KEY set to your APIVAI key, then start Aider with the model ID prefixed by openai/, for example aider --model openai/claude-sonnet-4-6. This OpenAI-compatible route works for both Claude and GPT models with one key. For Claude only, you can instead use the Anthropic route: ANTHROPIC_API_BASE=https://api.apivai.com (without /v1), ANTHROPIC_API_KEY set to the same key, and --model anthropic/claude-sonnet-4-6. As of 2026-10-07, Claude Sonnet 4.6 costs $1.04 / $5.22 per million input / output tokens through APIVAI, against $3.00 / $15.00 at the official list price.
What is Aider?
Aider is an open-source AI pair-programming tool that runs in your terminal. You start it inside a git repository, add files to the chat and describe the change you want; Aider edits the files and commits the result to git. Aider talks to models through the LiteLLM library, so it can use any OpenAI-compatible API, including APIVAI. You pay per token from a prepaid balance, with no subscription.
Which provider setting should you use in Aider?
Aider picks the API format from the prefix of the model name:
| Route | Model name | Base URL variable | Key variable | Models |
|---|---|---|---|---|
| OpenAI-compatible (recommended) | openai/<model-id> | OPENAI_API_BASE=https://api.apivai.com/v1 | OPENAI_API_KEY | Claude and GPT |
| Anthropic | anthropic/<model-id> | ANTHROPIC_API_BASE=https://api.apivai.com | ANTHROPIC_API_KEY | Claude only |
Choose the OpenAI-compatible route if you want one setup for every model and want to switch between Claude and GPT freely. Choose the Anthropic route if you work mostly with Claude and want Aider's --cache-prompts option, which uses Claude prompt caching so that repeated context (the repo map and the files in the chat) is billed at the cheaper cache-read price. Both routes use the same APIVAI key.
Watch the /v1: the OpenAI base URL ends with /v1, the Anthropic base URL does not, because LiteLLM adds /v1/messages to it by itself. ANTHROPIC_API_BASE is a LiteLLM environment variable rather than an option in Aider's own reference, but Aider passes it through because all model calls go through LiteLLM. The general details of both formats are on the OpenAI-compatible API page and in the docs.
How do you set up Aider with APIVAI step by step?
Step 1: Get an APIVAI key
- Sign up at apivai.com
- Top up your balance from $10 by card, crypto, Alipay or WeChat Pay
- Create a key in the Dashboard (you can give it its own budget limit) and copy it
Step 2: Install Aider
Aider's docs recommend this installer:
python -m pip install aider-install aider-install
Step 3: Set the base URL and key
On macOS or Linux:
export OPENAI_API_BASE=https://api.apivai.com/v1 export OPENAI_API_KEY=your-apivai-key
On Windows:
setx OPENAI_API_BASE https://api.apivai.com/v1 setx OPENAI_API_KEY your-apivai-key
After setx, open a new terminal window: the window you ran it in does not see the new values.
Step 4: Start Aider in your project
cd /path/to/your/project aider --model openai/claude-sonnet-4-6 --edit-format diff
Type the model ID exactly after the openai/ prefix. To use GPT instead, start with --model openai/gpt-5.5, or switch inside a running session with /model openai/gpt-6-sol.
Why --edit-format diff: Aider chooses an edit format from the model name. For names it does not recognize, it falls back to whole, where the model rewrites every edited file in full, which costs far more output tokens. diff sends only the changed blocks and suits current Claude and GPT models.
Step 5 (optional): Save the settings in a .env file
Aider reads a .env file from your home directory, the root of your git repo and the current directory. With this file you can start it with a plain aider:
OPENAI_API_KEY=your-apivai-key AIDER_OPENAI_API_BASE=https://api.apivai.com/v1 AIDER_MODEL=openai/claude-sonnet-4-6 AIDER_WEAK_MODEL=openai/claude-haiku-4-5 AIDER_EDIT_FORMAT=diff
The weak model writes commit messages and summarizes chat history, so a cheap model there saves money without hurting code quality. Keep the key out of git: put the file in your home directory, or add .env to .gitignore.
Alternative: the Anthropic route for Claude
export ANTHROPIC_API_KEY=your-apivai-key export ANTHROPIC_API_BASE=https://api.apivai.com aider --model anthropic/claude-sonnet-4-6 --cache-prompts
On Windows, use setx as in step 3. Always pass --model: without it, Aider picks its own default model, which may not be the one you want.
Settings at a glance
| Field | Value |
|---|---|
OPENAI_API_BASE (or AIDER_OPENAI_API_BASE) | https://api.apivai.com/v1 |
OPENAI_API_KEY | your APIVAI key |
--model | openai/claude-sonnet-4-6 |
--weak-model | openai/claude-haiku-4-5 |
--edit-format | diff |
ANTHROPIC_API_BASE (Anthropic route) | https://api.apivai.com |
ANTHROPIC_API_KEY (Anthropic route) | your APIVAI key |
Which model should you choose for Aider?
Prices per 1M input / output tokens as of 2026-10-07. The model list changes over time, so take IDs from GET https://api.apivai.com/v1/models or the pricing page rather than copying old names.
| Model | Aider --model | Input | Output | Best for |
|---|---|---|---|---|
| Claude Sonnet 4.6 | openai/claude-sonnet-4-6 | $1.04 | $5.22 | Everyday coding, best value |
| Claude Sonnet 5.5 | openai/claude-sonnet-5-5 | $0.69 | $3.47 | Everyday coding, newer Sonnet |
| Claude Opus 5.5 | openai/claude-opus-5-5 | $1.39 | $6.96 | Hard bugs, large refactors |
| Claude Haiku 4.5 | openai/claude-haiku-4-5 | $0.35 | $1.74 | Weak model, small edits |
| GPT-5.5 | openai/gpt-5.5 | $0.77 | $4.56 | GPT alternative |
| GPT-6 Luna | openai/gpt-6-luna | $0.0144 | $0.0768 | Very cheap tasks |
A sensible default is Claude Sonnet 4.6 as the main model and Claude Haiku 4.5 as the weak model. For a difficult task, Aider's architect mode lets a strong model plan and a cheaper one write the edits, for example aider --architect --model openai/claude-opus-5-5 --editor-model openai/claude-sonnet-4-6.
What does Aider cost with APIVAI?
Each Aider request sends the repo map, the files you added to the chat and the conversation so far. Assume a typical request of about 15,000 input tokens and 1,500 output tokens (thinking tokens count as output) with Claude Sonnet 4.6:
- One request: $0.0234 ($0.0675 at the official price).
- A workday of 60 requests: $1.41 ($4.05 at the official price).
- A month of 22 such workdays (1,320 requests): $30.93 ($89.10 at the official price).
The same month on Claude Haiku 4.5 would be $10.38, and on GPT-6 Luna $0.437. To spend less, /drop files you no longer need, /clear long histories, and use --cache-prompts on the Anthropic route. The Dashboard lists every request with its tokens and cost; the Claude API pricing comparison shows all models next to official prices.
How do you fix common Aider errors?
- 401 / AuthenticationError: the key is wrong, deleted, or out of budget, or the variable is not set in this terminal. After
setxon Windows, open a new window. - 404 / NotFoundError: the base URL is wrong.
OPENAI_API_BASEmust end with/v1exactly once (not/v1/v1, not missing).ANTHROPIC_API_BASEmust not contain/v1. - "LLM Provider NOT provided": the model name has no prefix. Write
openai/claude-sonnet-4-6, notclaude-sonnet-4-6. - Model not found: the ID after the prefix must match an ID from
GET /v1/modelsexactly, not a display name. - Empty or cut-off replies: thinking is on by default and thinking tokens use up the output limit. Raise the limit for all models in
.aider.model.settings.yml(home directory or repo root):
- name: aider/extra_params
extra_params:
max_tokens: 8192- 429: the default limit is 60 requests per minute per key. Wait a moment, or ask support for a higher limit.
- "Unknown context window size and costs, using sane defaults": harmless for models Aider does not know. Hide it with
--no-show-model-warnings. Because of it, Aider's own cost display may show $0.00; the Dashboard has the real numbers.
FAQ
Can I use Claude and GPT in the same Aider session?
Yes. With the OpenAI-compatible route, one key and one base URL cover both; switch with /model openai/gpt-5.5 or /model openai/claude-sonnet-4-6.
Do I need an Anthropic or OpenAI account?
No. You only need an APIVAI key and a prepaid balance. There is no subscription and you pay only for the tokens you use.
Is the Anthropic route better for Claude?
It lets you use --cache-prompts, which makes the repeated repo map and files cheaper. If you also want GPT models, the OpenAI-compatible route is simpler.
Does APIVAI store my code?
No. Request and response content is not logged; only usage data such as model, tokens and cost is kept for billing.
What else can I use the same key with?
Any tool that accepts an OpenAI-compatible or Anthropic endpoint, for example Continue in VS Code and JetBrains, or Claude Code (see the Claude Code setup guide).
Create an account, top up from $10 and paste your key into Aider.