Skip to main content

AntiScam AI – AI-powered request inspection middleware for Python

Project description

antiscamai

PyPI version Python versions Downloads License: MIT

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

antiscamai-1.0.1.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

antiscamai-1.0.1-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file antiscamai-1.0.1.tar.gz.

File metadata

  • Download URL: antiscamai-1.0.1.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for antiscamai-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a277f447a44c453a18f2ff71ac48a655951b424a27c34faf4b425f24fad177fd
MD5 abcb0b280b73d5d3963f7154466f1f87
BLAKE2b-256 4c0ca0e5d1945ee5d4e9e5680710a6b3fd3f163730847976d85acc78af9ad10f

See more details on using hashes here.

File details

Details for the file antiscamai-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: antiscamai-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for antiscamai-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7c5a8e4a6f3798e3c608d674db9e4fb02494d63bac78d8183bbff3ceb37d1ed4
MD5 2f7d59b4e2e08cacd1431aa0076b371d
BLAKE2b-256 0b53a089334502d2c632c58a1cba100bd520b9af8f10efd4b22dfaab10d2a7b1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page