Agents · October 24, 2026 · 3 min read
Building an AI code-review bot for your repos
Learn how to build a serverless AI code-review bot using Python and Podstack’s on-demand GPUs to automate pull request feedback with per-second billing.
In the era of rapid software development, the bottleneck is often the code review process. While linters and static analysis catch syntax errors, they lack the "semantic intuition" to spot logic flaws or architectural inconsistencies. Large Language Models (LLMs) have bridged this gap, but running high-performance inference at scale usually requires managing complex infrastructure.
In this guide, we’ll build a custom AI code-review bot that analyzes GitHub pull requests using a fine-tuned or open-source LLM (like Llama 3) hosted on Podstack. By using Podstack’s serverless GPU functions, we can trigger an inference job only when a new PR is opened, ensuring we only pay for the seconds the GPU is actually active.
The Architecture
Our bot consists of three main components:
- The Trigger: A GitHub Action that fires on
pull_requestevents. - The Logic: A Python script that fetches the code diff and prepares the prompt.
- The Inference Engine: A Podstack GPU endpoint running our model of choice.
The beauty of this setup is that you don't need a persistent server. Podstack handles the cold starts and scaling, providing a dedicated GPU environment for the duration of the review.
Step 1: Setting Up the Inference Function
First, we define our inference function. We want a model that can handle context-heavy diffs. We’ll use the Podstack Python SDK to define a function that loads our model and generates suggestions.
# review_bot.py
import podstack
from transformers import AutoModelForCausalLM, AutoTokenizer
@podstack.gpu_function(gpu="A100", memory="40GB")
def analyze_diff(diff_text: str):
model_id = "meta-llama/Meta-Llama-3-8B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
prompt = f"Review the following git diff and identify logic errors or security risks:\n\n{diff_text}"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=512)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
By decorating the function with @podstack.gpu_function, you tell the platform to provision an A100 only when this function is called.
Step 2: Deploying to Podstack
To make this function accessible to our GitHub Action, we deploy it using the Podstack API. Ensure you have your PODSTACK_API_KEY exported in your local environment.
Podstack does not ship a command-line interface. Use the console, the Python package `podstack-sdk`, or the API at https://podstack.ai/api/v1 with a `ps_live_` key.
Once deployed, Podstack provides a unique URL for your function. This endpoint is billed per second, meaning if the review takes 15 seconds, you only pay for those 15 seconds of A100 usage.
Step 3: Integrating with GitHub Actions
Now, we create a workflow in .github/workflows/ai-review.yml. This script will extract the PR diff and send it to our Podstack endpoint.
name: AI Code Review
on: [pull_request]
jobs:
review:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get Diff
run: git diff origin/${{ github.base_ref }} > pr_diff.txt
- name: Call Podstack Reviewer
env:
PODSTACK_API_KEY: ${{ secrets.PODSTACK_API_KEY }}
run: |
python -c "
import podstack
client = podstack.Client()
with open('pr_diff.txt', 'r') as f:
res = client.call('code-reviewer', diff_text=f.read())
print(res)
" > review_feedback.txt
- name: Post Comment
uses: mshick/add-pr-comment@v2
with:
message-path: review_feedback.txt
Practical Tips for AI Reviews
- Prompt Engineering: Don't just ask the AI to "review the code." Give it specific personas. For example: "You are a Senior Security Engineer. Focus on SQL injection, XSS, and broken access control in this diff."
- Context Management: LLMs have token limits. If a PR is massive, split the diff by file or use a summarization step before the final review.
- Cost Efficiency: Use smaller models (like Llama 3 8B) for general stylistic reviews and reserve larger models (70B+) for mission-critical architectural reviews. On Podstack, you can swap the
gpuparameter in your decorator to match the model size instantly.
Scaling with Podstack
Building this on Podstack removes the "GPU tax" of idle instances. Traditional VPS or container services force you to pay for the GPU as long as the server is up, even if no PRs are being submitted. With Podstack’s per-second billing and serverless inference, your code-review bot costs pennies per day, scaling automatically during high-activity periods like "Merge Wednesdays."
By moving the heavy lifting to Podstack, you keep your CI/CD pipeline fast and your developers focused on shipping features rather than managing Kubernetes clusters. Whether you are running a single-repo bot or a fleet of reviewers for an entire organization, the workflow remains the same: write Python, deploy via the API, and let the GPUs handle the rest.