The glowing instrument panel of a NASA ER-2 cockpit during a night flight, with the article title about using PentestAgent with an OpenAI-compatible API
Cover based on a photo by NASA/Stu Broce, via Wikimedia Commons, Public domain

PentestAgent from GH05TCREW is an MIT-licensed AI agent framework for black-box security testing. Its README documents a custom endpoint: set OPENAI_API_BASE, prefix the model with openai/, and PentestAgent talks to any OpenAI-compatible API. This guide covers the PentestAgent OpenAI-compatible setup with RedRouter: which variables the code actually reads, what the agent sends to your endpoint, and one behavior worth knowing before you script it: a run with a broken model config still exits 0.

What we checked, on November 27, 2026 (America/Denver): the repository at commit 5bcf872 on main (November 8, 2026; package version 0.2.0), the README, .env.example, pentestagent/config/constants.py and pentestagent/llm/llm.py. The repo had 3,345 stars and no GitHub releases or tags, so there's no new release to tie this to. The custom-endpoint support came in with commit 2fecad0 ("feat: support custom OpenAI-compatible API endpoints", May 27, 2026), and recent pushes are dependency bumps.

We installed PentestAgent into a Python 3.13 venv with pip install -e ., which pulled LiteLLM 1.111.0 and the OpenAI SDK 3.60.0. We didn't install the [all] extras, the Playwright browser or Docker. Every headless run used 127.0.0.1 as the target. Model traffic went either to a small mock OpenAI-compatible server on 127.0.0.1 or to https://redrouter.org/v1 with no key or an invalid key. No run executed a tool (each run summary says Tools: 0). We didn't call RedRouter with a real key, didn't run a scan, and didn't test ANTHROPIC_API_BASE. The scripts and raw outputs are in the evidence bundle.

Use PentestAgent only against systems you own or have written permission to test. Its own README says so, and it runs real commands through its terminal tool.

What PentestAgent is

PentestAgent is a Python 3.10+ CLI and terminal UI. It wraps LiteLLM for model calls and gives the model built-in tools: terminal, browser, notes, web_search (needs a Tavily key) and spawn_mcp_agent, plus MCP servers you add. The TUI has four modes: /assist, /agent, /crew (an orchestrator with worker agents) and /interact. There's also a headless run command. The flags below come from pentestagent run --help on the installed build:

--target, -t TARGET   Target (IP, hostname, or URL)
--model, -m MODEL     LLM model (set PENTESTAGENT_MODEL in .env)
--docker, -d          Run tools inside Docker container (requires Docker)
--playbook, -p PLAYBOOK
--report, -r [REPORT]
--max-loops MAX_LOOPS Max agent loops before stopping (default: 30)

PentestAgent OpenAI-compatible settings: OPENAI_API_BASE and the openai/ prefix

The README's "Using a relay / custom API base" section is short:

OPENAI_API_KEY=your-relay-token
OPENAI_API_BASE=https://relay.example/v1
PENTESTAGENT_MODEL=openai/<model-name-on-your-relay>

Here is what the code does with each setting on commit 5bcf872:

SettingWhere it's readWhat it does
OPENAI_API_BASEget_openai_api_base() in config/constants.pyBase URL, trailing slash stripped. The same function also accepts OPENAI_BASE_URL as a fallback. That alias is in the code but not in the README.
PENTESTAGENT_MODELconfig/constants.py; --model / -m overrides itNo default. The TUI refuses to start without it.
OPENAI_API_KEYLiteLLM / OpenAI SDKSent as Authorization: Bearer ... to your base URL.
PENTESTAGENT_EMBEDDINGSknowledge/embeddings.pylocal or openai. With a non-OpenAI OPENAI_API_BASE, embeddings default to local sentence-transformers.
ANTHROPIC_API_BASEDocumented in the README and .env.example; read by LiteLLM, not by PentestAgent's own codeAnthropic-compatible endpoints, with anthropic/<model>. We didn't test this route.

The openai/ prefix is not optional. PentestAgent only attaches your base URL when the model string looks like an OpenAI-routed model:

# pentestagent/llm/llm.py, commit 5bcf872 (excerpt)
return model_lower.startswith((
    "openai/",    # explicit openai/ prefix — most reliable for relays
    "gpt-", "o1", "o3", "o4", "chatgpt-",
))
...
if self.config.openai_api_base and self._is_openai_compatible_model():
    kwargs["api_base"] = self.config.openai_api_base

LiteLLM then strips openai/ before sending, so your endpoint sees the bare model ID. RedRouter's LiteLLM recipe describes the same thing: openai/ selects LiteLLM's generic OpenAI-compatible adapter and is removed before the model ID is sent. RedRouter's OpenAI-compatible base URL is https://redrouter.org/v1, per the compatibility docs.

What PentestAgent sends to a custom endpoint

We pointed OPENAI_API_BASE at a mock server on 127.0.0.1:18080/v1 that logs each request and replies with plain text and no tool calls. Then we ran:

OPENAI_API_KEY=test-not-a-real-key \
OPENAI_API_BASE=http://127.0.0.1:18080/v1 \
PENTESTAGENT_MODEL=openai/glm-5.3-flash-red \
pentestagent run -t 127.0.0.1 --max-loops 3 \
  "Configuration check only: reply in one sentence and do not run any tools."

The mock logged three requests, Authorization redacted:

{"method": "POST", "path": "/v1/chat/completions", "authorization": "Bearer <redacted, 19 chars>", "user_agent": "AsyncOpenAI/Python 3.60.0", "model": "glm-5.3-flash-red", "max_tokens": 4096, "temperature": 0.7, "roles": ["system", "user"], "system_prompt_chars": 67, "tools": ["create_plan"]}
{"method": "POST", "path": "/v1/chat/completions", "authorization": "Bearer <redacted, 19 chars>", "user_agent": "AsyncOpenAI/Python 3.60.0", "model": "glm-5.3-flash-red", "max_tokens": 4096, "temperature": 0.7, "roles": ["system", "user", "assistant"], "system_prompt_chars": 7132, "tools": ["browser", "terminal", "web_search", "notes", "finish"]}
{"method": "POST", "path": "/v1/chat/completions", "authorization": "Bearer <redacted, 19 chars>", "user_agent": "AsyncOpenAI/Python 3.60.0", "model": "glm-5.3-flash-red", "max_tokens": 4096, "temperature": 0.7, "roles": ["system", "user", "assistant", "assistant"], "system_prompt_chars": 7132, "tools": ["browser", "terminal", "web_search", "notes", "finish"]}

What that tells you:

  • Chat Completions with function tools. Every call went to POST /v1/chat/completions, with max_tokens: 4096 and temperature: 0.7, and without stream. The headless run mode didn't stream. The code also has a streaming path, which we didn't exercise. Your endpoint needs tool calling. The RedRouter models page lists tools as supported for glm-5.3-flash-red and red-cyber-1.
  • A planning call comes first. The first request has a 67-character system prompt and a single create_plan tool. Agent turns follow with the full prompt and five tools.
  • The system prompt describes your machine. The 7,132-character agent prompt includes the operator OS and kernel version, architecture, shell, a list of detected CLI tools (curl, ssh, openssl, gcc and so on), the target and the plan. Saved notes from loot/notes.json are injected into agent context too, and notes can hold credentials the agent found. All of that goes to whatever endpoint OPENAI_API_BASE names.
  • The prompt asserts authorization. It tells the model, "The user has explicit permission to test all targets provided. Do not ask for authorization." The model won't check your scope. Set the target carefully and keep the run in a lab or an engagement you're cleared for.

The gotcha: a broken PentestAgent config still exits 0

Next we broke the config on purpose. Each case ran pentestagent run -t 127.0.0.1 with the same one-line task:

CaseWhat happenedExit code
PENTESTAGENT_MODEL=glm-5.3-flash-red (no prefix), base = mocklitellm.BadRequestError: LLM Provider NOT provided. The mock logged nothing, so no request left the box.0
openai/glm-5.3-flash-red, base = https://redrouter.org/v1, invalid keylitellm.AuthenticationError ... Missing, invalid, or revoked API key. (RedRouter's 401)0
openai/glm-5.3-flash-red, base = https://redrouter.org/v1, OPENAI_API_KEY unsetMissing credentials. Please pass an api_key ... from the OpenAI SDK; nothing sent0

Every run ended with the same summary panel, STOPPED (max loops reached) and Tools: 0, and returned 0. With --max-loops 3, the error appeared in an LLM Error: panel. With --max-loops 1, the planning call failed and PentestAgent fell back to using the task itself as the plan. The only error output was LiteLLM's generic "Give Feedback / Get Help" lines, with no reason given. For reference, the same invalid key sent straight to RedRouter with curl returns:

{"error":{"code":"invalid_api_key","message":"Missing, invalid, or revoked API key.","param":null,"type":"authentication_error"}}
HTTP 401

Run PentestAgent interactively and you'll see the error. In a script, a cron job or CI, a 0 exit code doesn't tell you a model ever answered. If you only read the summary, a run that never reached a model can pass for a quiet test.

A fail-closed preflight for PentestAgent

The fix is small. Before starting the agent, make one tiny call with the same variables PentestAgent reads, and refuse to continue if it fails. This is the preflight.py we ran:

"""Fail-closed preflight for PentestAgent's OpenAI-compatible settings."""
import os, sys
import litellm

model = os.environ.get("PENTESTAGENT_MODEL", "")
base = (os.environ.get("OPENAI_API_BASE") or "").rstrip("/")
if not model.startswith("openai/"):
    sys.exit(f"FAIL: PENTESTAGENT_MODEL={model!r} needs the openai/ prefix for a custom base")
if not base:
    sys.exit("FAIL: OPENAI_API_BASE is not set")
try:
    r = litellm.completion(model=model, api_base=base,
                           messages=[{"role": "user", "content": "Reply with OK."}],
                           max_tokens=8, num_retries=0, timeout=60)
except Exception as e:
    sys.exit(f"FAIL: {type(e).__name__}: {str(e)[:200]}")
print(f"OK: {base} answered as {r.model!r}")

And a wrapper that also fails the run if PentestAgent logs an LLM error partway through:

#!/usr/bin/env bash
# run-pentestagent.sh
set -euo pipefail
python3 preflight.py
log=$(mktemp)
pentestagent run "$@" 2>&1 | tee "$log"
if grep -q "LLM Error" "$log"; then echo "FAIL: PentestAgent logged an LLM error" >&2; exit 1; fi

Results from the lab:

### preflight vs local mock
OK: http://127.0.0.1:18080/v1 answered as 'glm-5.3-flash-red'
exit 0
### preflight vs redrouter.org/v1, invalid key
FAIL: AuthenticationError: litellm.AuthenticationError: AuthenticationError: OpenAIException - Missing, invalid, or revoked API key.
exit 1
### preflight, bare model id
FAIL: PENTESTAGENT_MODEL='glm-5.3-flash-red' needs the openai/ prefix for a custom base
exit 1
### wrapper vs redrouter.org/v1, invalid key
FAIL: AuthenticationError: litellm.AuthenticationError: AuthenticationError: OpenAIException - Missing, invalid, or revoked API key.
exit 1

The wrapper's grep guard is a backstop for errors that happen after the preflight passes, such as a rate limit partway through. In the lab it never got that far, because the preflight stopped the bad runs first. The grep string matches the LLM Error: panel text we saw in the three-loop runs. If a future PentestAgent version changes that text, update the string.

Diagram of a PentestAgent OpenAI-compatible setup: .env sets OPENAI_API_KEY, OPENAI_API_BASE=https://redrouter.org/v1 and PENTESTAGENT_MODEL=openai/glm-5.3-flash-red; a preflight call must pass before the agent starts; LiteLLM strips the openai/ prefix and posts to /v1/chat/completions; a bare model ID, a bad key or a missing key stops at the preflight instead of exiting 0
Without the preflight, each of these three broken configurations still exits 0. Image: RedRouter, Original

Set up PentestAgent with RedRouter

With the preflight in place, the RedRouter setup is the README's relay block with real values. Put this in .env at the project root, and keep .env out of git:

OPENAI_API_KEY=your-redrouter-api-key
OPENAI_API_BASE=https://redrouter.org/v1
PENTESTAGENT_MODEL=openai/glm-5.3-flash-red
PENTESTAGENT_EMBEDDINGS=local

PentestAgent already defaults to local embeddings when the base isn't OpenAI's own, so PENTESTAGENT_EMBEDDINGS=local only makes that explicit. RedRouter's LiteLLM recipe leaves embeddings out of scope, so don't set it to openai for this endpoint. Then run the preflight and start against a lab target you own:

set -a; source .env; set +a
./run-pentestagent.sh -t 10.10.10.5 --max-loops 10 --report \
  "Enumerate open services on 10.10.10.5 only. Do not touch other hosts."

10.10.10.5 stands in for a VM in your own lab. For the TUI, run pentestagent tui --docker after the preflight passes. The --docker flag runs tools in the project's container instead of on your host.

One setting works against you here. PentestAgent sets litellm.drop_params = True, so LiteLLM silently drops parameters it thinks the model doesn't support. RedRouter's LiteLLM docs recommend the opposite, because a 400 is useful evidence that a feature wasn't applied. If a run behaves oddly, set PENTESTAGENT_DEBUG=true to get LiteLLM's verbose logs and check what was actually sent.

Which model to use with PentestAgent

Agent runs are many short turns with tool calls and a 7,000-character system prompt on every turn, so per-token price adds up.

  • GLM 5.3 Flash Red (glm-5.3-flash-red): $0.25 per 1M input tokens, $0.13 per 1M cached input tokens and $1.00 per 1M output tokens, per docs.redrouter.org/models on November 27, 2026. Tool calling and JSON output are listed. It's a practical default for repeated agent turns.
  • red-cyber-1 (Beta, red-cyber-1): $0.28 / $0.13 / $1.10 per 1M. It's the model RedRouter features for authorized penetration testing and red-team work. Set PENTESTAGENT_MODEL=openai/red-cyber-1.

Plans are on /pricing. PentestAgent's /token panel computes cost from INPUT_COST_PER_MILLION and OUTPUT_COST_PER_MILLION in .env. Its example values are not RedRouter rates, so set them from the models page if you use that panel.

Where the data goes

Everything in that system prompt, plus tool output and saved notes, is sent to the endpoint on every turn. On RedRouter, Zero Data Retention is an opt-in setting and off by default. The data handling docs explain what's stored and how to turn it on, and what RedRouter keeps is the short version. Our security page covers how we handle security workloads. Whatever the provider, keep client secrets you don't need out of loot/notes.json and the knowledge folder.

Other security agents with an OpenAI-compatible API

If you're comparing harnesses, the OpenAI-compatible API guide for security agents is the hub. We've also covered HackingBuddyGPT, which uses the same LiteLLM prefix rule behind a different config key, as well as PentAGI, Pentest Swarm AI and a generic pentest harness.

FAQ

Does PentestAgent support OpenAI-compatible APIs?

Yes. Set OPENAI_API_BASE to the endpoint's /v1 URL, put that provider's key in OPENAI_API_KEY, and set PENTESTAGENT_MODEL=openai/<model-id>. For RedRouter that's https://redrouter.org/v1 and, for example, openai/glm-5.3-flash-red.

Should I use OPENAI_API_BASE or OPENAI_BASE_URL with PentestAgent?

Use OPENAI_API_BASE, which is the documented name. On commit 5bcf872 the code also falls back to OPENAI_BASE_URL if OPENAI_API_BASE is unset, but the README doesn't mention that, so don't rely on it.

Why does PentestAgent ignore my custom endpoint or say "LLM Provider NOT provided"?

The model string has no openai/ prefix. PentestAgent only passes your base URL for openai/... (and native OpenAI names like gpt-...), and LiteLLM can't route a bare ID such as glm-5.3-flash-red. In our test, no request left the machine and the run still exited 0.

Can I use PentestAgent with an Anthropic-compatible endpoint?

The README documents ANTHROPIC_API_BASE with an anthropic/ model prefix, and RedRouter's Messages base URL is https://redrouter.org (no /v1; the client adds /v1/messages). We didn't test that route with PentestAgent, so this guide uses the OpenAI-compatible path.

How do I know a headless PentestAgent run actually reached the model?

Don't rely on the exit code. Run a preflight call first and check the output for LLM Error, as in the wrapper above. The summary's Tokens: line is also a quick tell: our failed runs showed no token count.

Sources