58API Help Center58API Help Center
User GuideAI ApplicationsAPI DocumentationHelp & Support

Aider - Terminal AI Pair Programming Assistant

Use Aider's OpenAI compatible configuration to connect to 58API and complete code understanding and modification in the terminal.

Scope of application

Aider is an open source AI pair programming tool that runs in the terminal and can read code repositories, modify files, and integrate changes with Git workflows. This tutorial is available for Windows, macOS, and Linux.

Preparation before use

  1. Log in 58API, create an API Key, and confirm that the account has available balance.
  2. Install Python 3.
  3. Prepare a Git code repository. Aider can run without relying on Git, but it is easier to view and undo changes in a Git repository.
  4. Confirm the model IDs currently available to the account. The following is gpt-6.1-sol For example.

Install Aider

Aider officially recommends installing a standalone installer first, and then letting the installer create the Aider environment:

python -m pip install aider-install
aider-install

Check the version after installation is complete:

aider --version

If the terminal prompts that it cannot be found aider, close and reopen the terminal to make the PATH added by the installer take effect. If it is still not found, follow the path prompts last output by the installer. Do not install repeatedly in different Python environments.

Configure 58API

Aider will read the user's home directory, Git warehouse root directory, current directory and --env-file designated .env, files read later have higher priority. In order to allow multiple projects to share 58API and avoid putting the key in the code repository, it is recommended to edit the user's home directory. .env:

systemRecommended documents
Windows%USERPROFILE%\.env
macOS / Linux~/.env

If the file already exists, please keep the original content and append the following three lines. Do not overwrite other configurations:

AIDER_MODEL=openai/gpt-6.1-sol
AIDER_OPENAI_API_BASE=https://api.58api.net/v1
AIDER_OPENAI_API_KEY=your_58API_api_key

Configure 58API in .env and start Aider

The screenshot is for illustration, Aider will not actually output API base OK.

①~③ in the picture are .env There are three variables that must be checked, ④ is the startup command executed after saving. The API Key is represented by a mask only; the actual file should be populated with the key created from the 58API console.

The role of three variables:

variableillustrate
AIDER_MODELAider main model; required for OpenAI compatible models openai/ prefix
AIDER_OPENAI_API_BASEOpenAI compatible base address for 58API
AIDER_OPENAI_API_KEY58API API Key, only readable by Aider’s OpenAI provider

The model prefix cannot be omitted

Aider officially requires a custom OpenAI compatible model to be written openai/<model-name>. Therefore should be filled in openai/gpt-6.1-sol, you can’t just write gpt-6.1-sol。

If you only want to use different configurations for a certain project, you can create it in the project root directory .env. The project file will overwrite the variable with the same name in the user's home directory, so add it .gitignore, avoid submitting API Key.

first start

Open the terminal, enter the code repository and start Aider:

cd /path/to/your/project
git status
aider

Windows PowerShell example:

Set-Location 'C:\path\to\your\project'
git status
aider

The model should be shown in the startup information openai/gpt-6.1-sol(Aider may also prompt that the context length or cost is unknown for models without built-in metadata, which is normal. See the FAQ below). First perform a read-only test:

只分析当前仓库的目录结构和主要语言,不要修改文件。

After receiving the reply, open the 58API console usage log and confirm that the corresponding request occurs.

Let Aider modify the code

Can be used first /add Add the target file to the chat and describe the modification:

/add hello.py
把 hello.py 的输出从 hello 改为 goodbye,并说明修改内容。

Aider creates Git commits by default for code modifications produced by the model. Can be used before and after submission git diff、git log or Aider's /diff View changes. If you do not want automatic submission during the first trial, you can start it like this:

aider --no-auto-commits

Temporarily switch models

Command line parameters can be overridden .env Main model in:

aider --model openai/另一个可用模型ID

still want to keep openai/ prefix. The model ID must come from the account's actual available list and cannot be guessed based on the display name.

FAQ

Prompt that API Key cannot be found

Make sure the variable name is AIDER_OPENAI_API_KEY,.env File was not saved as .env.txt. If the project root directory or current directory also has .env, check whether the home directory configuration is overwritten with a null value.

Return 401

Copy the 58API API Key again and make sure there are no spaces on either side of the equal sign and that the value does not have quotes or extra newlines. Revise .env Then exit the current Aider session and restart.

Returns 404 or interface path exception

The base address should be https://api.58api.net/v1, do not add any more /chat/completions. Aider will splice OpenAI compatible interface paths by itself.

If it already exists in the system environment variables OPENAI_BASE_URL(It may be set by other tools or OpenAI SDK tutorials), LiteLLM used by Aider will use it first, ignoring AIDER_OPENAI_API_BASE, the request and key will be sent to another address. Please delete this system variable or change it in the same .env Add another line:

OPENAI_BASE_URL=https://api.58api.net/v1

Prompt model does not exist

confirm AIDER_MODEL Satisfy two points at the same time: with openai/ The beginning and the second half are exactly the same as the actual model ID of 58API.

Unknown model, context length, or cost warnings appear

Aider maintains metadata for familiar models. Custom aliases may be called fine but are missing context length and price information, hence the warning. First confirm that the request is indeed successful; when precise context and cost estimates are required, then supplement the model metadata according to the official Model Metadata document, and do not fill in random values.

Text is returned, but code modifications are not applied correctly

Code modifications rely on the ability of the model to follow the Aider editing format. First use a simple single file modification verification; if it still fails, switch to a model that has stronger programming capabilities and is known to be suitable for Aider. Just being able to chat does not mean that the model can stably generate applicable editing blocks.

The configuration has been changed but the old value is still used

Aider press "Home Directory → Git Root Directory → Current Directory → --env-file"Sequential reading .env, the later value will overwrite the previous value. Check if a variable with the same name exists in the project and restart Aider. Also check whether the system environment variables are set OPENAI_BASE_URL, which has a higher priority than AIDER_OPENAI_API_BASE。

official basis