Ai Code Review
- Source
- openrouter.ai
- Author
- OpenRouter editorial sitemap
- Date

Context
OpenRouter has published a tutorial for an AI code reviewer that tries to prove each bug by running code before it reports it. AI reviewers that read only the diff, the lines a change adds or removes, have to guess what the rest of the file looks like and whether a suspected bug actually fails. OpenRouter's 233-line Python script instead uploads the full changed files, any test files you name, and the diff into a hosted Linux through OpenRouter's API, which sends them on to the chosen model's provider. The model rebuilds the repository there, writes short checks and runs them. Each finding comes back marked confirmed, with the command and output that showed the failure, or unconfirmed when a quick script cannot demonstrate the problem, as with a database connection that is no longer closed.
The script also works as a gate. The model proposes fixes as patches, which the script tries on a temporary copy of your files and copies into your working tree only when you pass its apply flag. Those patches are not applied inside the sandbox, so the model's checks ran against the original code, and the guide tells readers to run their own tests after applying a fix. When any finding reaches a chosen severity, high by default, the script exits with an error code. Installed as a Git pre-push in OpenRouter's test, that stopped a push containing planted bugs, and the remote branch stayed at its previous commit.
The evidence comes from one small test. OpenRouter planted five bugs in a short Python file whose existing tests still passed, then ran three reviews per model. Every model confirmed the SQL injection, the pagination error, an identity comparison that counted refunded orders as revenue, and a retry helper that silently swallowed its final error, in every review it completed. Anthropic's Claude Sonnet 5.5 found all five planted bugs in each of its three runs, and its patches fixed all five every time, at an average of $0.0447 and 60 seconds per review. Claude Haiku 5.5 was the cheapest at $0.0153, but its patches fixed all five bugs in only one of three runs, and two of them rewrote a function in a way that would break callers passing the data shape it expected. GPT-6 Luna found 12 of the 15 across its three runs, and one DeepSeek V4.1 Flash review spent all eight of its turns resending patches without finishing.
Running code costs more than reading it. Sandbox time is billed at $0.0001 per second from the first shell command until the response completes, so a slow model pays for its thinking time even when its are cheap. OpenRouter puts a diff-only reviewer on Haiku 5.5 at about $0.001 per review and the sandboxed version at 10 to 40 times that. What the extra cost buys is a reproduced failure for each confirmed finding. The guide itself says models can still miss bugs, overstate severity or write broken patches, and the uploaded code goes to the model provider. A five-bug sample shows the method catching planted bugs; it does not show how often it catches bugs in real changes.
- OpenRouter's reviewer uploads the full changed files and the diff to a hosted Linux sandbox, so the model can run quick checks and mark each finding confirmed, with the command and output as evidence, or unconfirmed when it cannot reproduce the bug.
- In OpenRouter's three-run test on a five-bug change, Claude Sonnet 5.5 found all five planted bugs and its patches fixed them in every run, at $0.0447 and 60 s per review. Haiku 5.5 was cheapest at $0.0153 but fully fixed the change in only 1 of 3 runs.
- Sandbox time is billed at $0.0001 per second from the first shell command until the response ends, including model thinking time, so slower models pay more: it was $0.0074 to $0.0159 of each Haiku review versus $0.0047 to $0.0068 for Sonnet.
- OpenRouter puts a diff-only Chat Completions reviewer at about $0.001 per review on Haiku 5.5, so running code in the sandbox costs 10 to 40 times more, in exchange for reproducer evidence and tested patches.
- Patches still need a human read: two of Haiku's three patches rewrote total_revenue to index tuples instead of fixing the "is not" comparison, breaking dict callers. The sandbox checks also ran against the original code, not the patched copy.
- sandbox — An isolated environment where AI-generated code or agent actions run without being able to touch anything real.
- agent hook — A script the harness runs automatically at a fixed point in an agent's loop — before a tool call, after an edit, on session start.
- token — The chunk of text a model reads and writes in — roughly three-quarters of a word — and the unit AI usage is billed in.
Checking sign-in…
Loading comments…






