Environment:Norrrrrrr lyn WAInjectBench OpenAI API Credentials
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Security, LLMs |
| Last Updated | 2026-02-14 16:00 GMT |
Overview
OpenAI API credentials required for the PromptArmor text detector and GPT-4o image detector.
Description
Two detectors in WAInjectBench rely on the OpenAI API: the PromptArmor text detector (`detector_text/promptarmor.py`) and the GPT-4o image detector (`detector_image/gpt-4o-prompt.py`). Both instantiate an `OpenAI` client using the `OPENAI_API_KEY` environment variable. The detectors call the `gpt-4o-2024-08-06` model with `max_tokens=10` for binary classification (0/1). A retry mechanism with configurable `max_retries` (default 3) and `wait_time` (default 2s) handles transient API errors.
Usage
Use this environment when running the PromptArmor or GPT-4o-Prompt detectors. It is not required for other detectors (KAD, PromptGuard, embedding-based, JailGuard, LLaVA).
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| Network | Internet access | Required to reach the OpenAI API endpoint |
| Account | OpenAI API account | Must have access to the `gpt-4o-2024-08-06` model |
Dependencies
Python Packages
- `openai` >= 1.0.0 (installed version: 1.108.0)
Credentials
The following environment variables must be set:
- `OPENAI_API_KEY`: OpenAI API key with access to GPT-4o. Required for PromptArmor and GPT-4o-Prompt detectors.
- `OPENAI_BASE_URL`: (Optional, commented out in source) Custom API base URL for proxy or alternative endpoints.
Quick Install
# Set your API key
export OPENAI_API_KEY="your-api-key-here"
# Install the OpenAI Python client
pip install openai>=1.0.0
Code Evidence
OpenAI client initialization from `detector_text/promptarmor.py:17-20`:
client = OpenAI(
# base_url=os.getenv("OPENAI_BASE_URL"),
api_key=os.getenv("OPENAI_API_KEY")
)
Same pattern in `detector_image/gpt-4o-prompt.py:17-20`:
client = OpenAI(
# base_url=os.getenv("OPENAI_BASE_URL"),
api_key=os.getenv("OPENAI_API_KEY")
)
Retry mechanism from `detector_text/promptarmor.py:22-49`:
def detect_text(text: str, max_retries: int = 3, wait_time: int = 2) -> int:
for attempt in range(1, max_retries + 1):
try:
response = client.chat.completions.create(
model="gpt-4o-2024-08-06",
...
)
except Exception as e:
if attempt < max_retries:
time.sleep(wait_time)
else:
return -1
README documentation confirming requirement:
PromptArmor → requires OPENAI_API_KEY as environment variable.
GPT-4o-Prompt → requires OPENAI_API_KEY as environment variable.
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `openai.AuthenticationError` | Missing or invalid `OPENAI_API_KEY` | Set `export OPENAI_API_KEY="sk-..."` in your shell |
| `openai.RateLimitError` | API rate limit exceeded | Reduce concurrent requests or increase `wait_time` parameter |
| Returns `-1` for all items | API errors on every attempt | Check network connectivity and API key validity |
Compatibility Notes
- Cost: GPT-4o API calls are billed per token. Running detection on large datasets can be expensive.
- Latency: Each sample requires a separate API call with up to 3 retries. Text detection is sequential per file.
- Model version: Both detectors hardcode `gpt-4o-2024-08-06`. If this model version is deprecated, update the model string in the detector files.