We are going to build a specialized code-review language model that reads git diffs and returns structured, actionable feedback. This tool is useful for teams who want consistent automated PR reviews without maintaining their own inference infrastructure. Because Oxlo.ai offers flat per-request pricing, you can pass large diffs without worrying about ballooning token costs.
What you'll need
- Python 3.10 or newer
- An Oxlo.ai API key from https://portal.oxlo.ai
- The OpenAI SDK:
pip install openai
Step 1: Instantiate the Oxlo.ai client
Create a single client instance that points to Oxlo.ai's OpenAI-compatible endpoint. I keep the API key in an environment variable.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.oxlo.ai/v1",
api_key=os.environ.get("OXLO_API_KEY")
)
Step 2: Define the system prompt
This prompt constrains the general foundation model into a staff-engineer reviewer that emits structured JSON.
SYSTEM_PROMPT = """You are a senior staff engineer performing code review.
Given a git diff, emit a JSON object with a single key "issues" containing a list.
Each issue must have:
- severity: one of "info", "warning", or "critical"
- file: the affected file path
- line: the starting line number as an integer
- comment: a one-sentence explanation of the problem
- fix: a one-sentence concrete fix recommendation
If no issues are found, return an empty list. Be concise and factual."""
Step 3: Prepare the diff
Read the diff from disk and wrap it in a predictable user message so the model knows where the patch starts and ends.
def load_diff(path: str) -> str:
with open(path, "r") as f:
content = f.read()
return f"Review the following git diff:\n\n
```diff\n{content}\n```
"
Step 4: Call the model
Send the system prompt and formatted diff to Oxlo.ai. I use Llama 3.3 70B for reliable general-purpose reasoning.
from openai import OpenAI
client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")
user_message = load_diff("changes.diff")
response = client.chat.completions.create(
model="llama-3.3-70b",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": user_message},
],
)
raw_output = response.choices[0].message.content
print(raw_output)
Step 5: Lock output with JSON mode
To guarantee valid JSON, enable JSON mode and switch to DeepSeek V3.2, which handles structured coding tasks well on Oxlo.ai.
import json
response = client.chat.completions.create(
model="deepseek-v3.2",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": user_message},
],
response_format={"type": "json_object"},
)
review = json.loads(response.choices[0].message.content)
print(json.dumps(review, indent=2))
Step 6: Wrap it in a script
Combine everything into a single file that accepts a diff path as an argument and prints formatted results.
import argparse
import json
import os
from openai import OpenAI
SYSTEM_PROMPT = """You are a senior staff engineer performing code review.
Given a git diff, emit a JSON object with a single key "issues" containing a list.
Each issue must have:
- severity: one of "info", "warning", or "critical"
- file: the affected file path
- line: the starting line number as an integer
- comment: a one-sentence explanation of the problem
- fix: a one-sentence concrete fix recommendation
If no issues are found, return an empty list. Be concise and factual."""
def load_diff(path: str) -> str:
with open(path, "r") as f:
content = f.read()
return f"Review the following git diff:\n\n
```diff\n{content}\n```
"
def main():
parser = argparse.ArgumentParser(description="Code review language model")
parser.add_argument("diff", help="Path to the .diff file")
args = parser.parse_args()
client = OpenAI(
base_url="https://api.oxlo.ai/v1",
api_key=os.environ.get("OXLO_API_KEY")
)
user_message = load_diff(args.diff)
response = client.chat.completions.create(
model="llama-3.3-70b",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": user_message},
],
response_format={"type": "json_object"},
)
review = json.loads(response.choices[0].message.content)
for issue in review.get("issues", []):
print(f"[{issue['severity'].upper()}] {issue['file']}:{issue['line']}")
print(f" {issue['comment']}")
print(f" Fix: {issue['fix']}\n")
if __name__ == "__main__":
main()
Run it
Save a sample diff as changes.diff and invoke the script.
python reviewer.py changes.diff
Example output:
[WARNING] src/auth.py:42
Hardcoded timeout value detected.
Fix: Move the timeout to a configuration constant or environment variable.
[INFO] src/auth.py:58
Consider adding type hints to the helper function.
Fix: Add -> bool return annotation and parameter types.
From here, you can wire this script into a GitHub Action so it comments on every pull request automatically. You can also swap the model to qwen-3-32b if your team works across multilingual codebases, or to kimi-k2.6 for deeper reasoning on complex refactors. Oxlo.ai's request-based pricing stays flat regardless of diff size, so long-context reviews cost the same as short ones. See https://oxlo.ai/pricing for plan details.
Top comments (0)