Back to blog

Tools & integrationsGuide

Aider config file for your own API key: .aider.conf.yml and Windows setx

Keep your own API key and base URL in .aider.conf.yml, get the load order right and avoid the Windows setx trap, with a session cost estimate.

By CheapTokens TeamPublished 3 min read

Terminal with the commands that connect Aider to an OpenAI-compatible API
On this page
  1. Windows: setx and a new terminal
  2. Which model for which edits
  3. Run a first edit
  4. Stop retyping: .aider.conf.yml
  5. What a session costs
  6. If it does not work

Two variables, OPENAI_API_BASE and OPENAI_API_KEY, and a model argument like openai/<model id> are enough to point Aider at CheapTokens. The step-by-step basics (install, first request, 401/404/400/402) are in How to connect Aider to CheapTokens; this page covers what that guide leaves out: Windows setx, the config file and its load order, and a session cost estimate.

Source: Aider's docs for OpenAI-compatible APIs (page checked 26 October 2026; the docs show no date or version, and the latest aider-chat on PyPI that day was 0.86.2).

Windows: setx and a new terminal#

On Mac and Linux you export the two variables. On Windows (PowerShell or cmd) use setx:

bat
setx OPENAI_API_BASE https://api.cheaptokens.dev/v1
setx OPENAI_API_KEY <your CheapTokens key>

On Windows there is a catch. setx writes the variables for future sessions, not the one you are typing in, so close the terminal and open a new one before you start Aider. If you set the variables and Aider still asks for a key, this is the usual reason.

Which model for which edits#

The model argument is openai/ plus the full id, so for CheapTokens it has two slashes:

bash
cd your-git-repo
aider --model openai/MiniMaxAI/MiniMax-M2.7

MiniMax-M2.7 has a 180K context and answers up to 8,192 tokens, a fit for small and medium edits where answers stay short. If your edits come back as long diffs, the other model worth trying is DeepSeek-V4-Flash: up to 32,768 tokens per answer, a 380K context and one price at any time of day.

bash
aider --model openai/deepseek-ai/DeepSeek-V4-Flash-0731

Copy the full id from the CheapTokens docs or the model list on pricing.

Run a first edit#

Aider works inside a git repo, so start in one. Add a file and ask for something small:

text
> /add app.py
> Add a --verbose flag that prints each file before it is processed

When Aider answers with an edit to the file, the key, the base URL and the model id are all right.

The wrong model id next to the full id that works, then the first edit
Wrong id versus full id, and the first request

Stop retyping: .aider.conf.yml#

Aider reads .aider.conf.yml from your home directory, then the git repo root, then the current directory, and later files win. So a global file can hold the key and base, and a repo file can pick the model. If you want one specific file and nothing else, aider --config <file> loads only that one.

A home-directory file (example, put your own key in):

yaml
openai-api-base: https://api.cheaptokens.dev/v1
openai-api-key: <your CheapTokens key>
model: openai/MiniMaxAI/MiniMax-M2.7

Now aider alone starts with the right endpoint and model. If you commit the file to a repo, leave the key out and keep it in the environment variable or in a .env file; the key lines are for your own home directory.

For a model that Aider does not know, the docs describe a model-settings-file (.aider.model.settings.yml) where you can specify its settings.

What a session costs#

Aider re-sends the files you added and the chat history with every message, so input tokens grow faster than output. Say a working session of about 20 messages sends 400,000 input tokens and gets 40,000 output tokens back (an assumption for the example; plug in your own numbers). On MiniMax-M2.7 that is $0.026, and cheaper than OpenRouter in total, with input and output counted together. The table below runs the same session across our models:

Model Cost OpenRouter
GLM-5.3-Flash $0.0096 $0.0196
DeepSeek-V4-Flash $0.01 $0.0253
MiniMax-M2.7 $0.026 $0.168

400,000 input and 40,000 output tokens in total. Prices per 1M tokens are current and change together with our tariffs; the OpenRouter column shows reference prices for the same workload.

How to keep the input side small (read-only files, /drop, repo map size) is covered in How much does Aider cost. Current prices are always on the pricing page.

If it does not work#

  • Aider asks for an API key or talks to the wrong service. The variables are not visible to the process. On Windows, restart the terminal after setx; on Mac and Linux, run echo $OPENAI_API_BASE in the same shell.
  • Your config seems ignored. Remember the order: home, repo root, current directory. A file closer to you overrides the global one.
  • Model not found, 404 or an authentication error. These are covered in How to connect Aider to CheapTokens.

The same OpenAI-compatible address works in other tools; if you also use an editor agent, see connecting OpenCode or the overview of where to plug in your own API key.