Connect Aider to Codex4Less: OpenAI-Compatible API Setup

Aider is a terminal-based AI pair programmer: it edits files in your local git repository from natural-language instructions, using an OpenAI-compatible API under the hood. This guide points Aider at Codex4Less and proves the setup with a real edit — the exact commands below were executed against the live API with aider 0.86.2.

Aider talks to OpenAI-compatible endpoints through the standard OPENAI_API_BASE / OPENAI_API_KEY environment variables and the openai/<model> prefix in --model. Codex4Less serves that same interface, so no special integration is needed.

Prerequisites

  • Python 3.10+ (Aider's official installer handles the environment for you).
  • git — Aider works best inside a git repository (it uses git to track its edits; commits are optional).
  • A Codex4Less account and API key: codex4less.com/register.
  • A terminal. The setup in this guide was tested on Linux; Windows commands are provided but were not executed during testing (marked below).

Step 1 — Create Your API Key

  1. Sign in and open API Keys: codex4less.com/dashboard/api-keys
  2. Click Create New API Key and copy the sk-... value — it is shown only once.
Security: keep the key in an environment variable (Step 3), never inside a file you commit. The examples below use sk-... as a placeholder — replace it with your real key only in your own terminal.

Step 2 — Install Aider

The official method:

bash
python -m pip install aider-install
aider-install

On systems where pip is unavailable or managed by the OS, uv works the same way (this is how the supporting tests for this guide were installed):

bash
uv tool install aider-chat
aider --version

At the time of writing this installs aider 0.86.2.

Step 3 — Configure Environment Variables

Aider reads the endpoint from OPENAI_API_BASE and the key from OPENAI_API_KEY.

macOS / Linux:

bash
export OPENAI_API_BASE="https://api.codex4less.com/v1"
export OPENAI_API_KEY="sk-..."

Add the same lines to ~/.bashrc or ~/.zshrc to make them permanent, then open a new terminal.

Windows (PowerShell):

powershell
$env:OPENAI_API_BASE = "https://api.codex4less.com/v1"
$env:OPENAI_API_KEY = "sk-..."

For persistence, add them to your PowerShell profile, or use setx OPENAI_API_BASE "https://api.codex4less.com/v1" and setx OPENAI_API_KEY "sk-..." followed by a new terminal. (The Windows steps follow standard PowerShell syntax but were not executed while preparing this guide.)

Step 4 — Start Aider with a Codex4Less Model

Change into your project and prefix the model name with openai/:

bash
cd /path/to/your/project
aider --model openai/gpt-6.1-sol

Inside the interactive session, describe the change you want. For scripted or quick checks you can send a single message instead:

bash
aider --model openai/gpt-6.1-sol --yes --message "Fix the bug in calc.py so add(a, b) returns a + b." calc.py

--yes skips confirmation prompts (useful for automation); drop it for normal interactive use.

Model choice: the authoritative list is at codex4less.com/pricing and via GET https://api.codex4less.com/v1/models. gpt-6.1-sol is the model verified in this guide; gpt-5.6-sol answered the same API tests. Aider prints a “model warnings” note for names it doesn't recognize — see the official warnings page; the run still proceeds.

Step 5 — Verify the First Request

This is the exact test performed for this guide, in a fresh git repository containing a buggy calc.py:

python
def add(a, b):
    return a - b  # BUG: should be +
bash
aider --model openai/gpt-6.1-sol --yes --no-auto-commits \
  --message "Fix the bug in calc.py so add(a,b) returns a + b. Only change that one line." calc.py

Observed result: Aider sent the request to Codex4Less, applied the fix and printed a summary:

text
Applied edit to calc.py
Tokens: 683 sent, 28 received. Cost: $0.0016 message, $0.0016 session.

The file now contains return a + b. To confirm the request went through Codex4Less (not another endpoint), open Dashboard → Usage: codex4less.com/dashboard/usage — the request appears with model, tokens and cost.

Note: in scripted runs Aider may print Warning: Input is not a terminal (fd=0). — this is harmless; it means Aider is running non-interactively.

Step 6 — Optional Configuration File

Instead of exporting variables every session, you can store them in a .env file in your project root (see Aider's .env docs):

text
OPENAI_API_BASE=https://api.codex4less.com/v1
OPENAI_API_KEY=sk-...

Make sure .env is in .gitignore. Default options (like your preferred model) can live in ~/.aider.conf.yml:

yaml
model: openai/gpt-6.1-sol

Keep the minimum working setup from Steps 3–4 as your baseline; add extras only after the basic flow works.

Troubleshooting

Authentication errors (401 / invalid API key)

  • OPENAI_API_KEY must contain the full sk-... key. Check with echo $OPENAI_API_KEY (avoid printing it in shared screens).
  • Environment variables are per-terminal; after setx on Windows, open a new terminal.

404 or endpoint errors

  • OPENAI_API_BASE must be exactly https://api.codex4less.com/v1. Aider appends /chat/completions itself — adding an endpoint path to the base produces 404s.
  • Verify the endpoint quickly: curl https://api.codex4less.com/v1/models -H "Authorization: Bearer $OPENAI_API_KEY".

Model warnings / “unknown model”

Aider warns about model names it doesn't know from its internal list. The request still runs via the OpenAI-compatible path. If you see repeated edit-format errors, try --edit-format whole (the format used in this guide's successful test) and keep the task small.

Git identity warning

If git lacks user.name/user.email, Aider prints a warning. Either configure git (git config user.name "...") or keep using --no-auto-commits, which was the mode tested here.

Edits not applied

  • Aider needs the target files in the chat: pass them on the command line (calc.py) or add them interactively.
  • If a model repeatedly fails its edit format, switch to gpt-6.1-sol and retry with a smaller instruction.

FAQ

Can I use a custom OpenAI-compatible endpoint with Aider? Yes — that is exactly what OPENAI_API_BASE is for. See the official OpenAI compatible APIs page.

Where should I store my API key? In OPENAI_API_KEY (shell environment or a git-ignored .env). Never commit it.

Which API format does Aider use against Codex4Less? The OpenAI chat completions interface: POST https://api.codex4less.com/v1/chat/completions. The verified flow in this guide used exactly that path. Codex4Less also documents the full API in its docs.

Does Aider use function calling / tools? No — Aider applies edits by having the model produce structured edit blocks (whole-file or diff formats), then parses and applies them locally. That flow was verified working end-to-end above.

What if my model ID stops working? Copy the current ID from codex4less.com/pricing or GET /v1/models and update the --model value.

Conclusion and CTA

Aider is one environment variable away from Codex4Less: set OPENAI_API_BASE to https://api.codex4less.com/v1, add your key, and use --model openai/gpt-6.1-sol. The edit-and-verify flow above was run live, so you can copy it as a starting point.

Ready to get started?

Create your Codex4Less account, generate an API key and run your first Aider edit against a Codex4Less model.

Create your account →

Related reading: Cline + Codex4Less setup · Using Codex CLI with Codex4Less · API documentation