OPENAI_API_BASE and OPENAI_API_KEY: other programs on your computer will use them too

Coding with AIAider·· 6 views· 3 min read

Aider reads the address and the key from OPENAI_API_BASE and OPENAI_API_KEY. These are the names OpenAI uses, and they do not belong to Aider alone. Any program on the computer that reads them starts talking to the MozOut API, with your key.

What can happen

1 Another program that uses these names sends its requests to our API and spends your AI credits or your Coding Plan points.
2 If that program asks for a model that is not in the catalogue, it gets 404 model_not_found and looks broken.
3 Windows setx and export replace whatever value was there. If you had another service's key under these names, it is gone.

Names that belong to Aider

Aider has its own names for the same two things: AIDER_OPENAI_API_BASE and AIDER_OPENAI_API_KEY. They match the --openai-api-base and --openai-api-key options, as the Aider options list shows. On Linux and macOS:

export AIDER_OPENAI_API_BASE=https://api.mozout.co.mz/v1
export AIDER_OPENAI_API_KEY="prod_..."

On Windows:

setx AIDER_OPENAI_API_BASE https://api.mozout.co.mz/v1
setx AIDER_OPENAI_API_KEY "prod_..."

Close the terminal and open a new one. Nothing else changes: aider --model openai/moonshotai/kimi-k2.7-code.

Or in the config file

The address is not a secret and can go in the .aider.conf.yml in your home folder:

openai-api-base: https://api.mozout.co.mz/v1

The Aider documentation also accepts openai-api-key: in that file, but then the key is written in a file. If you do it, only use the one in your home folder, never the one at the repository root, which can end up in Git.

Removing the old variables

On Linux and macOS, delete the two lines from ~/.bashrc or ~/.zshrc and, in the open terminal:

unset OPENAI_API_BASE OPENAI_API_KEY

In Windows PowerShell:

[Environment]::SetEnvironmentVariable("OPENAI_API_BASE", $null, "User")
[Environment]::SetEnvironmentVariable("OPENAI_API_KEY", $null, "User")

Then close the terminal and open a new one.

If the key ended up in a file that went into Git, or somewhere other people can see, revoke it and create another: what to do, in the right order.

Want our models in Aider without touching your other programs? Visit the Coding with AI page.

See Coding with AI

SEE ALSO

Installing Aider and opening it in your project with an All in One AI model

Where Aider looks for .aider.model.metadata.json: home folder, repository and start folder

Aider with All in One AI: the two variables, the openai/ prefix and the context window

An API key or token has leaked: what to do

Coding with AI in All in One AI

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from $6.60/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.