antiscamai
AI-powered request inspection middleware for Python.
Add one line to your FastAPI, Django, or Flask app and every incoming request is automatically screened by a trained AI model for scams, phishing, social engineering, and fraudulent content.
Install
# FastAPI / Starlette
pip install antiscamai[fastapi]
# Django
pip install antiscamai[django]
# Flask
pip install antiscamai[flask]
# All frameworks
pip install antiscamai[all]
Quick Start
FastAPI (Middleware)
from fastapi import FastAPI
from antiscamai.middleware.fastapi import AntiScamFastAPIMiddleware
import os
app = FastAPI()
app.add_middleware(
AntiScamFastAPIMiddleware,
api_key=os.environ["ANTISCAM_API_KEY"],
mode="block", # "block" | "flag" | "monitor"
)
# All your existing routes are now protected — no other changes needed
@app.post("/api/contact")
async def contact(body: ContactForm):
...
FastAPI (Per-Route Dependency)
from fastapi import Depends
from antiscamai.middleware.fastapi import antiscam_fastapi
checker = antiscam_fastapi(api_key=os.environ["ANTISCAM_API_KEY"])
@app.post("/api/payment")
async def payment(body: PaymentForm, _=Depends(checker)):
...
Django
# settings.py
ANTISCAMAI = {
"API_KEY": os.environ.get("ANTISCAM_API_KEY"),
"MODE": "block", # block | flag | monitor
"ENDPOINT": "http://localhost:5000",
"EXCLUDE_PATHS": ["/health/", "/static/"],
"INSPECT_METHODS": ["POST", "PUT", "PATCH"],
}
MIDDLEWARE = [
# ... your existing middleware ...
"antiscamai.middleware.django.AntiScamDjangoMiddleware",
]
Flask
from flask import Flask
from antiscamai.middleware.flask import antiscam_flask
import os
app = Flask(__name__)
antiscam_flask(app, api_key=os.environ["ANTISCAM_API_KEY"])
What Gets Blocked
| Threat | Example |
|---|---|
| Phishing messages | "Your account is suspended — verify now" |
| Investment fraud | "Guaranteed 500% ROI — risk-free" |
| Lottery / prize scams | "You've won $50,000 — claim your prize" |
| Social engineering | "I'm from Apple Support, share your OTP" |
| Phishing URLs in body | http://secur3-paypal.xyz/verify |
| Prompt injection (LLM APIs) | "Ignore previous instructions…" |
| Credential phishing | "Enter your password to verify identity" |
Response on Blocked Request
HTTP 403 Forbidden
{
"error": "Request blocked by AntiScam AI",
"requestId": "a4f2c1d3...",
"riskLevel": "HIGH",
"reason": "High urgency language + suspicious patterns detected"
}
Read the Inspection Result
# FastAPI — result stored in request.state
@app.post("/api/contact")
async def contact(request: Request, body: ContactForm):
result = request.state.antiscam
# result.threat_score → 0–100
# result.risk_level → MINIMAL | LOW | MEDIUM | HIGH | CRITICAL
# result.decision → allow | flag | block
# result.threats → list of detected threats with explanations
# Django — result stored in request.antiscam
def my_view(request):
result = getattr(request, "antiscam", None)
# Flask — result stored in g.antiscam
from flask import g
result = g.antiscam
Threat Callback
from antiscamai.middleware.fastapi import AntiScamFastAPIMiddleware
async def on_threat(result):
print(f"Threat! score={result.threat_score} level={result.risk_level}")
# Send to Slack, PagerDuty, your SIEM...
app.add_middleware(
AntiScamFastAPIMiddleware,
api_key="...",
on_threat=on_threat,
)
Modes
| Mode | Behaviour |
|---|---|
block |
Requests scoring ≥65 return HTTP 403 (default) |
flag |
Allowed but sets X-AntiScam-Flag: true header |
monitor |
All requests pass; threats are only logged |
Configuration
| Parameter | Default | Description |
|---|---|---|
api_key |
required | Your API key |
endpoint |
http://localhost:5000 |
AntiScam AI gateway URL |
mode |
"block" |
block, flag, or monitor |
timeout_ms |
3000 |
AI call timeout in ms |
on_error |
"allow" |
Fail-open (allow) or fail-closed (block) |
exclude_paths |
["/health", "/metrics"] |
URL prefixes to skip |
inspect_methods |
["POST","PUT","PATCH"] |
HTTP methods to inspect |
on_threat |
None |
Async/sync callback on threat detection |
Self-Hosting
git clone https://github.com/antiscamai/backend
cd backend/deploy/docker
docker-compose up -d
AntiScamFastAPIMiddleware(app, api_key="YOUR_KEY", endpoint="http://localhost:5000")
Requirements
- Python 3.10+
httpx >= 0.27.0
License
MIT © AntiScam AI
Metadata
Release files for antiscamai 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| antiscamai-1.0.2.tar.gz | 12.1 kB | Without provenance | Details for antiscamai-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| antiscamai-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for antiscamai-1.0.2-py3-none-any.whl |
Total release size: 24.9 kB
Release files / antiscamai-1.0.2.tar.gz
| Download URL | antiscamai-1.0.2.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
87e86dc50dc7a8ce83f3c627e341caf1af29b0ede517d63cf2b54faa1f6600bc
|
|
BLAKE2b-256 checksum How to use checksums |
c8fdc557bea19282210d84a26ba53753003946131b9ed971138ab213e9d8dcbd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / antiscamai-1.0.2-py3-none-any.whl
| Download URL | antiscamai-1.0.2-py3-none-any.whl |
|---|---|
| Size | 12.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b04fe62ea421313c511c86ef9e5671280c30dd5b09d62e6c1a3bfbad1ccadb70
|
|
BLAKE2b-256 checksum How to use checksums |
1a81534c3df25a24876708aef15749fa0a79d1c7a67e90c8c4cd6aafb0cbf2b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Security for antiscamai 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.