AI secure code review
Triage SAST findings with a model
Feed Semgrep JSON or a CodeQL SARIF file to auto/security at https://api.pentestllm.ai/v1 and every finding comes back with a verdict, a plain note on whether it is exploitable, and a suggested fix. A reviewer still confirms each true positive, and what shrinks is the pile of noise they read first.
from openai import OpenAI client = OpenAI(base_url="https://api.pentestllm.ai/v1", api_key="sk-ptl-live-…") reply = client.chat.completions.create( model="auto/security", messages=[{"role": "user", "content": "Explain this advisory and list what to check on an affected host."}],)print(reply.model) # the build that answeredprint(reply.choices[0].message.content)Where this sits in a review
When a scanner runs in your pipeline, CI security report review keeps the optional reading job separate from the release gate.
A secure code review usually starts with a scanner pass that produces hundreds of findings, most of them unreachable or already handled. Sorting them is slow, repetitive reading: open the file, find the source of the tainted value, check for a sanitiser, decide. That reading is what you hand to the model. The decision stays with the reviewer, and the repository stays inside the scope the client signed.
Before any client code leaves your machine, settle what the contract allows. The privacy page lists what PentestLLM keeps, and the files-and-redaction feature covers the header that strips keys and tokens from snippets before the request is forwarded.
Get findings a script can read
Semgrep prints its own JSON format with --json, and -o writes it to a file. For CodeQL, pin the SARIF version, because the manual warns that sarif-latest can change between releases and break automation, so use sarifv2.1.0. One catch with Semgrep: since version 1.98.0 some fields, including the matched lines, need a logged-in session, so the script below reads the code from disk instead and works either way.
semgrep scan --config p/default --json -o semgrep.jsoncodeql database analyze app-db codeql/python-queries \ --format=sarifv2.1.0 --output=codeql.sarifThe triage script
This reads semgrep.json, adds about fifteen lines of context on each side of every finding, and asks the model for a JSON verdict. It targets auto/security, because the router sends a structured-output request to a balanced security build; with the gateway’s redaction setting on (secrets), API keys, tokens and private keys in the snippet become placeholders before the request is forwarded. The redaction page has the header. Run it from the repository root; for CodeQL, keep the loop and swap the field lookups for the SARIF paths, falling back to the start line when a result omits the end line. Asking for a json_object has a billing note worth knowing: on a non-streamed request, an answer that does not parse is retried once and the missed answer is free; the response headers record the miss and the refund, and per-token rates are on pricing.
import json, sys, osfrom openai import OpenAIclient = OpenAI(base_url="https://api.pentestllm.ai/v1", api_key=os.environ["PTL_KEY"])SYSTEM = ("You triage static analysis findings for an authorized secure code review. " "Answer in JSON: verdict (true_positive, false_positive or needs_review), reason, " "exploitability (which input reaches the sink and what an attacker would gain; no exploit " "code, no payloads), fix (the smallest code change), confidence (low, medium or high).")def snippet(path, start, end, pad=15): lines = open(path, encoding="utf-8", errors="replace").read().splitlines() lo, hi = max(start - pad, 1), min(end + pad, len(lines)) return "\n".join(f"{n}: {lines[n-1]}" for n in range(lo, hi + 1))for f in json.load(open(sys.argv[1]))["results"]: s, e = f["start"]["line"], f["end"]["line"] prompt = f"Rule: {f['check_id']}\nFile: {f['path']}, lines {s}-{e}\n\n" + snippet(f["path"], s, e) reply = client.chat.completions.create(model="auto/security", response_format={"type": "json_object"}, extra_headers={"x-redact": "secrets"}, messages=[{"role": "system", "content": SYSTEM}, {"role": "user", "content": prompt}]) print(reply.choices[0].message.content)Read the verdicts like a reviewer
Sort by verdict and confidence. A high-confidence false positive usually points at a sanitiser or framework guard the rule does not know about, which is a rule-tuning note for the client; spot-check a sample. A needs_review means the model saw only the snippet, so taint that crosses files, middleware or configuration is invisible and you widen the context or read it yourself. A true positive you confirm for reachability inside scope, score with the CVSS calculator, and move to the triage and report writing steps. Never let the script close a finding on its own; a verdict file is a reading order, not an audit trail.
Keep the run reproducible
Store the scanner version, the rule set, the model id and the system prompt next to the verdict file. When the client asks months later why a finding was marked as noise, you can show the exact input and the reason the model gave, with the reviewer’s own note beside it. Changing the prompt between runs makes verdicts incomparable, so version it like code. The exploitability field asks for words, not code: which input reaches the sink and what an attacker would gain is what a client needs to prioritise a fix, while proofs of concept, where the rules of engagement call for them, are the tester’s job on the authorised target.
Where each field sits in the two formats
- Rule
- Semgrep: results[].check_id; CodeQL: runs[].results[].ruleId.
- Message
- Semgrep: extra.message; CodeQL: message.text.
- File
- Semgrep: path; CodeQL: locations[0].physicalLocation.artifactLocation.uri.
- Line
- Semgrep: start.line and end.line; CodeQL: physicalLocation.region.startLine.
16 security builds, priced per token
USD per million tokens, live on 2026-11-27; auto/security bills at the build that answers.
Detected refusals and invalid non-streamed JSON qualify for automatic refunds within the daily cap. Verify your receipt.
| Wire formats | |||||
|---|---|---|---|---|---|
| Qwen3.8 27B Cybersecurity | Security | $0.40 | $2.40 | 262K | |
| Uncensored Qwen3.8 27b Cybersecurity | Security | $0.40 | $2.40 | 262K | |
| Gemma 4 26B A4B Cybersecurity | Security | $0.4224 | $1.3376 | 262K | |
| Gemma 4 26B A4B Cybersecurity (Uncensored) | Security | $0.48 | $1.52 | 262K | |
| GLM-5.3 Flash Cybersecurity | Security | $0.4935 | $1.645 | 1049K | |
| GLM-5.3 Flash Cybersecurity (Uncensored) | Security | $0.5093 | $1.6975 | 1049K | |
| Red Team (Flash) | Security | $0.90 | $3.00 | 1000K | |
| Red Team (Pro) | Security | $1.50 | $6.00 | – | |
| OrcaCyber MiniMax M3.1 Flash | Security | $2.00 | $4.00 | 262K | |
| OrcaCyber MiniMax M3.1 Flash (Uncensored) | Security | $2.00 | $4.00 | 262K | |
| OrcaCyber Qwen3.8 Flash Next (Uncensored) | Security | $2.00 | $4.00 | 262K | |
| OrcaCyber Qwen3.8 Flash Next | Security | $2.00 | $4.00 | 262K | |
| Uncensored Qwen3.8 Flash Next Cybersecurity | Security | $2.00 | $4.00 | 262K | |
| Cyber Frontier | Security | $5.25 | $15.75 | 1049K | |
| OrcaCyber Zero 1.5 | Security | $7.50 | $18.75 | 999K | |
| OrcaCyber Zero 1.5 (Uncensored) | Security | $7.50 | $18.75 | 999K |
Questions
Can a model replace a person in SAST triage?
No. It removes the first pass of reading: obvious false positives, duplicates across rules, findings in test fixtures. A reviewer signs off every true positive and samples the false positives the model dismissed.
Does the model see the whole repository?
Only what the script sends: the rule, the file path and about thirty lines around each finding. That limit is why cross-file data flow lands in needs_review. Send more context for those findings rather than trusting a guess.
Which build fits SAST triage?
Send auto/security, as in the script: the router answers each request with a security build and sends a structured-output request to the balanced tier. There is no public benchmark of these builds on SAST triage yet, so compare a few hundred verdicts against your own decisions before you rely on one.
Does redaction keep secrets out of the snippet?
Yes for credentials: with redaction set to secrets, the gateway swaps API keys, tokens and private keys for placeholders before the request is forwarded. Hostnames, internal IPs and client names are not in that class, so scrub those yourself before the request goes out.