⚡ ApiPatch
Autonomous AI Agent for API Breaking Changes & Self-Maintaining Codebases
🛑 The Problem
Over 30% of cloud outages and broken builds are caused by silent, third-party API breaking changes. When vendors release major SDK updates (OpenAI v1.0+, Pydantic v2, Stripe SCA/PaymentIntents, LangChain LCEL, React hooks, Next.js App Router…), engineering teams spend days hunting broken calls and rewriting legacy code.
Tools like Dependabot and Renovate only bump version numbers in requirements.txt or package.json—they do not fix actual code logic.
[ Traditional Dependency Bumper ]
requirements.txt: openai==0.28.0 ──► openai==1.50.0 ──❌ (Code breaks at runtime!)
[ ApiPatch Autonomous Agent ]
1. Detects breaking API calls across ANY library — Python, JS, TS, JSX, TSX…
2. Refactors code via LLM reasoning (Gemini, Claude, GPT-4o)
3. Validates safety before accepting any change
4. Generates ready-to-merge Pull Requests ───────────────────────✅ (Build passes!)
🚀 Key Features
- 🤖 Autonomous GitHub PR Pipeline (
apipatch pr): Scans an entire remote repository, auto-forks/branches, commits refactorings, and opens live Pull Requests with rich Markdown summaries. - ⚡ GitHub App & Webhook Daemon (
apipatch webhook): Listens for repositorypushevents, verifies HMAC signatures, and autonomously runs the audit & PR pipeline in the background. - 🔑 Smart Token Discovery: Automatically resolves GitHub tokens from CLI flags,
GITHUB_TOKEN/GH_TOKENenv,github_token.txtfile, or.env. - 🧠 Universal LLM Engine: Audits ANY third-party library in any language dynamically — no hardcoded rules required.
- 🌐 Multi-Language Support: Full support for
.py,.js,.ts,.jsx,.tsx,.mjs,.cjsfiles. - 🛡️ AST & Safety Guard: Validates every refactored Python file through AST syntax parsing. JS/TS files checked for truncation and brace/bracket balance.
- 🔁 Automatic Retry: Exponential backoff retry (3 attempts) on transient LLM/network errors — no silent failures.
- 📦 Flexible CLI: Rich terminal interface with
scan,fix --write,detect,hunt,pr,webhook, and--output report.json. - 🔄 Safe In-Place Refactoring: Automatically generates
.bakbackups before modifying any files. - 🔌 Multi-Provider: Works with Google Gemini (free tier), OpenAI GPT-4o, and Anthropic Claude — auto-detected from environment variables.
- 📊 JSON Report Output: Save scan results with
--output report.jsonfor CI/CD integration.
🌍 Universal Coverage — Any Library, Any Language
ApiPatch is not limited to a fixed list of rules. The LLM engine can detect and fix breaking changes in any third-party library it has been trained on, including (but not limited to):
| Language | Libraries / Frameworks |
|---|---|
| Python | OpenAI, Pydantic, Stripe, LangChain, Supabase, SQLAlchemy, FastAPI, Boto3/AWS, Celery, HuggingFace, Twilio, and more |
| JavaScript / TypeScript | React (class → hooks), Next.js (Pages → App Router), Axios, Stripe.js, Supabase JS, OpenAI Node SDK, Express, and more |
| Any Language | If the LLM knows about a library's breaking change, ApiPatch can fix it |
⚡ Quickstart
1. Installation
pip install apipatch
Or install from Git (latest dev version):
pip install git+https://github.com/MoradMoqbel/apipatch.git
🔑 Setting Up AI & GitHub Tokens
AI Provider Keys
# Google Gemini (Fast & Free Tier Available)
export GEMINI_API_KEY="your-gemini-api-key-here"
# OpenAI
export OPENAI_API_KEY="sk-..."
# Anthropic Claude
export ANTHROPIC_API_KEY="sk-ant-..."
GitHub Token Setup
ApiPatch automatically resolves your GitHub token in this priority:
--token <ghp_...>CLI optionGITHUB_TOKENorGH_TOKENenvironment variablegithub_token.txtin your working directory or project root.envfile
💻 CLI Commands & Usage
1. 🚀 Autonomous Live GitHub Pull Request
Audits an entire GitHub repository, forks if needed, commits modernized files, and opens a real live PR:
# Open live PR on repository
apipatch pr owner/repo
# Dry run / preview changes without opening PR
apipatch pr owner/repo --dry-run
# Specify custom base branch
apipatch pr owner/repo --branch main
2. ⚡ GitHub App Webhook Daemon
Runs the continuous webhook server to trigger autonomous PRs on every repository push:
apipatch webhook --port 8080 --secret "my_webhook_secret"
3. 🔍 Scan a Codebase Locally (Dry Run)
Audits files recursively (.py, .js, .ts, .jsx, .tsx, .mjs, .cjs),
detects deprecated calls, and outputs colorized diff previews without modifying files:
apipatch scan /path/to/project
apipatch scan /path/to/project --provider gemini
4. ⚡ Refactor and Apply Fixes In-Place
Automatically updates the code and generates .bak safety backups:
apipatch fix /path/to/project --write
apipatch fix /path/to/single/file.py --write --provider openai
(Add --no-backup to skip automatic .bak backup creation.)
5. 📦 Discover All Project Dependencies
Inspects requirements.txt, package.json, pyproject.toml, and all source file
imports (Python AST + JS/TS regex) to list every third-party library in use:
apipatch detect /path/to/project
6. 🎯 Hunt for Deprecated Code on GitHub & Submit PRs
Searches GitHub for legacy patterns and prepares/submits ready-to-merge Pull Requests:
apipatch hunt "openai.ChatCompletion.create language:python" --submit
apipatch hunt "stripe.Charge.create language:javascript"
🧪 Testing
pytest
All 76 tests are offline-safe and mocked (no external network or live LLM required for the test suite).
🗺️ Roadmap
- Universal LLM engine — no hardcoded rules, ANY library supported
- Multi-language support: Python, JavaScript, TypeScript, JSX, TSX
- AST Syntax & Safety Validator
- Multi-LLM Provider (Gemini, OpenAI, Claude) with auto-discovery
- In-place refactoring with automatic backup (
--write) - Autonomous dependency discovery (requirements.txt / package.json / AST scan)
- Automated test suite (76/76 tests passing)
- v0.5.0: Autonomous GitHub PR Engine (
apipatch pr) - v0.5.0: GitHub App Webhook Daemon (
apipatch webhook) - v0.5.0: Automatic token discovery (
github_token.txt/ env) - v0.5.0: Multi-file atomic Git tree commits & auto-forking
- PyPI Release (
pip install apipatch)
📄 License
MIT License. Built by Morad Moqbel.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file apipatch-0.5.0.tar.gz.
File metadata
- Download URL: apipatch-0.5.0.tar.gz
- Upload date:
- Size: 57.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c411ceb490186ce9319c8287be96e40718ed277702c571dd44fbcc9888ca6a03
|
|
| MD5 |
942a5eed44d074b6a03b93b01dde11d8
|
|
| BLAKE2b-256 |
b6d7bad6e44ab4de6d5d9fe280824b98c727cab989ac28b5bd4db0052ddc0a66
|
File details
Details for the file apipatch-0.5.0-py3-none-any.whl.
File metadata
- Download URL: apipatch-0.5.0-py3-none-any.whl
- Upload date:
- Size: 52.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15649194659117c3818054975c86c159c95ae451245f3e602545ce0b3340227c
|
|
| MD5 |
a8e0d61626bfa9df274ab37aefb1f0e1
|
|
| BLAKE2b-256 |
3c22dcb0eefd80f5aa6b4cbefcabaa5f5f173c747e8442901ef998d280386acf
|