A FastAPI-based API server that provides an interface to run Aider commands via HTTP requests. This server allows you to send files and instructions to Aider and receive structured responses.
- Structured JSON responses with stdout/stderr separation
- Send multiple files in a single request
- Configure Aider options (auto-commits, dirty-commits, dry-run)
- Temporary file handling for safety
- Docker support
- API documentation with Swagger UI
The API server is also available as a TypeScript implementation that provides the same functionality as the Python version.
-
First follow the Python steps as we need the venv for the latest Aider
-
Install Node.js dependencies:
npm install
- Build the TypeScript code:
npm run build
- Run the server:
npm start
The TypeScript version supports the same command line arguments and API functionality as the Python version.
- Clone the repository:
git clone https://github.com/yourusername/aider-api
cd aider-api
- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows, use: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Make sure we have the latest aider
venv/bin/python -m pip install --upgrade aider-chat
- Run the server
python3 aider_api.py [--host HOST] [--port PORT]
The server can be configured with the following command line arguments:
--host
: Host to listen on (default: 127.0.0.1)--port
: Port to listen on (default: 8000)
- Build and run using Docker:
docker build -t aider-api .
docker run -p 8000:8000 aider-api
- Or use Docker Compose:
docker-compose up
The repository includes a chat.py script that provides an interactive command-line interface to the API:
python3 chat.py [--port PORT] [files ...]
Options:
--port
: Port number where the API server is running (default: 8000)files
: Optional list of files to edit in the chat session
The chat script allows you to:
- Interactively send messages to the API
- Edit multiple files in a session
- See stdout/stderr output clearly separated
- Get error messages in a user-friendly format
The server runs on http://localhost:8000
by default.
Send a POST request with JSON payload containing:
message
: The instruction for Aiderfiles
: Dictionary of filename to file contentauto_commits
: (optional) Enable/disable auto commits (default: true)dirty_commits
: (optional) Enable/disable dirty commits (default: true)dry_run
: (optional) Enable/disable dry run mode (default: false)
- Using curl:
curl -X POST http://localhost:8000/run-aider \
-H "Content-Type: application/json" \
-d '{
"message": "add a docstring to this function",
"files": {
"example.py": "def hello():\n print(\"Hello, World!\")"
}
}'
curl -X POST http://localhost:8000/run-aider \
-H "Content-Type: application/json" \
-d '{
"message": "/help"
}'
- Using Python requests:
import requests
response = requests.post(
"http://localhost:8000/run-aider",
json={
"message": "add a docstring to this function",
"files": {
"example.py": "def hello():\n print(\"Hello, World!\")"
}
},
)
# The response is now a JSON object with the following structure:
response_json = response.json()
print("STDOUT:", response_json["raw-stdout"])
print("STDERR:", response_json["raw-stderr"])
if "error" in response_json:
print("ERROR:", response_json["error"])
- Using JavaScript fetch:
fetch("http://localhost:8000/run-aider", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
message: "add a docstring to this function",
files: {
"example.py": 'def hello():\n print("Hello, World!")',
},
}),
})
.then((response) => response.json())
.then((data) => {
console.log("STDOUT:", data["raw-stdout"]);
console.log("STDERR:", data["raw-stderr"]);
if (data.error) {
console.log("ERROR:", data.error);
}
});
pytest tests/
The API documentation is available at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
The server is configured through command line arguments when starting:
python3 aider_api.py [--host HOST] [--port PORT]
Arguments:
--host
: Host to listen on (default: 127.0.0.1)--port
: Port to listen on (default: 8000)
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
MIT License