Installing and Configuring aider with a Large Model API on Ubuntu 24.04
This guide walks through installing aider on Ubuntu 24.04 LTS using pipx, connecting it to an OpenAI-compatible large model API, verifying connectivity with curl, troubleshooting common HTTP errors, and managing API keys securely. It is aimed at developers with basic Linux command-line experience who want to call third-party large models from a server or cloud host.
1. Scope and Prerequisites
This article is for developers with basic Linux command-line experience who need to use large models on an Ubuntu 24.04 LTS server or cloud host. After reading it, you will be able to call a third-party large model with aider in your projects and troubleshoot common API errors on your own.
This guide only covers OpenAI-compatible APIs. If your provider uses a different protocol, such as the native Anthropic API, the environment variables and curl commands here will not apply.
Before starting, confirm the following:
| Item | Requirement | Check Command |
|---|---|---|
| System | Ubuntu 24.04 LTS with sudo access | lsb_release -a |
| Python | 3.10 or later (the system default is 3.12) | python3 --version |
| Model service | An OpenAI-compatible API from a third-party platform, with an API key already obtained | Confirm in the platform console |
| Network | The server can reach the model service on port 443 | See Section 5 |
The https://llm.example.com/v1 used in this article is a placeholder. Replace it with the Base URL given in your provider’s documentation. A Base URL usually ends with /v1 and should not include endpoint paths such as /chat/completions.
This article proceeds in the order: environment setup, installation, API integration, verification, troubleshooting, and key management.
2. Prepare the System Environment
Ubuntu 24.04 enforces the PEP 668 restriction. Installing packages directly into the system Python with pip will produce an externally-managed-environment error. The recommended approach is to install command-line tools with pipx, which creates an isolated virtual environment for each tool without touching the system Python.
Update the package index and install the basic tools:
sudo apt update && sudo apt upgrade -ysudo apt install -y curl git pipxpipx ensurepath
After running pipx ensurepath, reopen your terminal or run source ~/.bashrc so that ~/.local/bin is added to PATH. Verify with:
echo $PATH | grep -q "$HOME/.local/bin" && echo "PATH includes ~/.local/bin" || echo "PATH is missing ~/.local/bin, reopen your terminal"
If your project requires a Python version different from the system one, install that version with pyenv first, then specify it with pipx install --python <interpreter path>.
3. Install aider
pipx install aider-chataider --version
A version number in the output confirms the executable is in ~/.local/bin and can be found by your shell. To upgrade or uninstall later:
pipx upgrade aider-chatpipx uninstall aider-chat
Common failures and fixes:
command not found: run the PATH check above and confirm the output says the path is included. If not, reopen your terminal.aider --versionfails or produces no output: runpipx listto check the installation status of aider-chat, then reinstall withpipx reinstall aider-chat.
4. Connect to the Large Model API
aider has no graphical or interactive setup wizard. It reads API details from environment variables and command-line arguments, so you need to set three things: the Base URL, the API key, and the model name.
- Set the Base URL:
export OPENAI_API_BASE="https://llm.example.com/v1"
- Set the API key. Use
read -sso the key is not echoed to the screen or written to shell history:
read -rsp "Enter API key: " OPENAI_API_KEY && echoexport OPENAI_API_KEY
- Confirm the model name. Use the name shown in the provider’s console or documentation. In aider, model names must be prefixed with
openai/. For example, if the provider’s model name isyour-model-name, useopenai/your-model-namein aider.
If you want to persist the configuration, store the variables in a separate file and restrict its permissions:
mkdir -p ~/.config/aidernano ~/.config/aider/llm.envchmod 600 ~/.config/aider/llm.env
Example file contents (replace the placeholders with real values):
export OPENAI_API_BASE="https://llm.example.com/v1"export OPENAI_API_KEY="paste your key here"
Load it when needed with source ~/.config/aider/llm.env. This file contains the key in plain text, so do not commit it to a repository or leave it on shared machines long-term.
5. Verify Connectivity
5.1 Check Port 443
curl -sS -o /dev/null -w "%{http_code}\n" --connect-timeout 10 "$OPENAI_API_BASE/models"
How to interpret the result:
000: no connection could be established. Check the server’s outbound firewall and security group rules, and verify the domain in the Base URL.401: the network is fine; the request simply lacked a key. This is an expected result.
5.2 List Models with curl
curl -i --connect-timeout 10 "$OPENAI_API_BASE/models" \-H "Authorization: Bearer $OPENAI_API_KEY"
A response of HTTP/2 200 together with a model list confirms that both the Base URL and the key are correct.
Some platforms do not expose a /models endpoint and will return 404 directly. In that case, verify with the chat endpoint instead:
curl -sS "$OPENAI_API_BASE/chat/completions" \-H "Authorization: Bearer $OPENAI_API_KEY" \-H "Content-Type: application/json" \-d '{"model":"your-model-name","messages":[{"role":"user","content":"ping"}],"max_tokens":5}'
If the returned JSON contains a choices field, the call succeeded. Replace your-model-name with the actual model name.
5.3 Verify with aider
cd ~/your-projectaider --model openai/your-model-name --no-auto-commits
By default, aider automatically creates git commits for the files it modifies. With --no-auto-commits, changes stay in the working tree and you decide whether to commit them.
Once in the interactive session, ask a simple question, such as “Describe this project in one sentence.” Receiving a reply means the integration is complete. Type /exit to quit.
6. Error Troubleshooting Reference
| Status Code | Common Causes | Troubleshooting Steps |
|---|---|---|
| 401 | Key is wrong or revoked; leading/trailing spaces or line breaks in the key; malformed Authorization header | Confirm the header format is Bearer plus one space plus the key; re-copy the key from the console; run echo ${#OPENAI_API_KEY} and compare the length with the key shown in the console |
| 404 | Incorrect Base URL path, such as a missing /v1 or an extra /chat/completions; nonexistent model name; platform does not provide /models |
Fix the Base URL against the provider’s documentation; use /models to list available model names and ensure the name after openai/ in aider matches exactly |
| 429 | Rate limit exceeded, or quota exhausted | Check usage and balance in the console; reduce concurrency; retry after waiting; add fewer files per aider request |
For other status codes (such as 400, 403, or 500), rely on the error message returned by the provider. The message field in the error response usually states the cause directly.
7. API Key Permissions and Revocation
An API key is equivalent to a credential for your account. If it leaks, someone else could consume your quota or gain access to your data on the platform.
Permission recommendations:
- Create a separate key for each server or project. If something goes wrong, you only need to revoke that one key.
- If the platform supports it, restrict which models the key can call and enable only the endpoints required for this setup.
- Set a monthly spending or quota cap to avoid large charges if a program misbehaves.
- If the platform supports an IP allowlist, restrict access to your server’s outbound IP.
Storage rules:
- Never put the key in source code, scripts, Dockerfiles, or configuration templates.
- Never paste the key into chat tools, tickets, or documents.
- Protect files containing the key with
chmod 600and add them to.gitignore. - If the key was ever entered in plain text into your command history, remove the corresponding lines from
~/.bash_history.
Revocation steps:
- Log in to the provider’s console and delete or disable the key.
- Run
unset OPENAI_API_KEYon the server to clear the variable from the current terminal. - Remove the key line from
~/.config/aider/llm.env, or delete the whole file. - If the key was accidentally committed to a git repository, revoke it in the console first, then clean up the repository history. Deleting only the latest commit does not remove the risk, because the key remains in the history.
8. Deployment Checklist
-
lsb_release -ashows Ubuntu 24.04 LTS -
aider --versionprints a version number -
echo $OPENAI_API_BASEshows the Base URL provided by your provider - The curl check in Section 5.1 returns
401or200, not000 - The request in Section 5.2 returns
200, or the chat endpoint returns JSON containingchoices - aider starts and receives replies from the model
- The key has restricted permissions and a spending cap, and any file containing the key has 600 permissions
