Skip to content

Simple API on top of Aider with some basic tooling

Notifications You must be signed in to change notification settings

tluyben/aider-api

Repository files navigation

Aider API Server

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.

Features

  • 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

Installation

TypeScript Version

The API server is also available as a TypeScript implementation that provides the same functionality as the Python version.

TypeScript Setup

  1. First follow the Python steps as we need the venv for the latest Aider

  2. Install Node.js dependencies:

npm install
  1. Build the TypeScript code:
npm run build
  1. Run the server:
npm start

The TypeScript version supports the same command line arguments and API functionality as the Python version.

Python Version Setup with venv

  1. Clone the repository:
git clone https://github.com/yourusername/aider-api
cd aider-api
  1. Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows, use: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Make sure we have the latest aider
venv/bin/python -m pip install --upgrade aider-chat
  1. 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)

Docker Setup

  1. Build and run using Docker:
docker build -t aider-api .
docker run -p 8000:8000 aider-api
  1. Or use Docker Compose:
docker-compose up

Usage

Interactive Chat Demo

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

API Usage

The server runs on http://localhost:8000 by default.

API Endpoints

POST /run-aider

Send a POST request with JSON payload containing:

  • message: The instruction for Aider
  • files: Dictionary of filename to file content
  • auto_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)

Example Usage

  1. 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"
  }'
  1. 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"])
  1. 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);
    }
  });

Development

Running Tests

pytest tests/

API Documentation

The API documentation is available at:

Configuration

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)

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

MIT License

About

Simple API on top of Aider with some basic tooling

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published