Building a Deepfake Detection API with Python and TruthLens

Dev.to / 4/8/2026

💬 OpinionDeveloper Stack & InfrastructureTools & Practical Usage

Key Points

  • The article argues that deepfake detection is becoming essential for apps that accept or process user-uploaded images, citing the growing prevalence of synthetic media and related scams.
  • It introduces the TruthLens API as a REST-based service that can detect AI-generated images through a dedicated detect endpoint.
  • It provides a “quick start” Python example showing how to call the TruthLens API using an API key in the Authorization header and upload an image file via a POST request.
  • The code demonstrates parsing the API’s JSON response and using the returned `is_ai_generated` flag (and associated confidence) to decide how the app should react to the content.

Why Every App Needs Deepfake Detection in 2026

Deepfakes are everywhere. From fake celebrity endorsements to AI-generated scam profiles, synthetic media is a $4B problem. If you build apps that handle user-uploaded images, you need deepfake detection.

The TruthLens API

TruthLens provides a simple REST API for detecting AI-generated images. Here is how to integrate it in 5 minutes.

Quick Start with Python

import requests

API_KEY = "your_truthlens_api_key"
API_URL = "https://truthlensbyai.online/api/detect"

def check_image(image_path):
    with open(image_path, "rb") as f:
        response = requests.post(
            API_URL,
            headers={"Authorization": f"Bearer {API_KEY}"},
            files={"image": f}
        )
    result = response.json()

    if result["is_ai_generated"]:
        print(f"AI Generated! Confidence: {result["confidence"]}")
    else:
        print("Looks authentic.")

    return result

# Check a suspicious image
result = check_image("suspicious_photo.jpg")

Integration Examples

Flask Middleware

from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route("/upload", methods=["POST"])
def upload():
    image = request.files["image"]
    # Check with TruthLens before accepting
    result = check_image_bytes(image.read())
    if result.get("is_ai_generated") and result["confidence"] > 0.8:
        return jsonify({"error": "AI-generated images not allowed"}), 400
    # Process normally
    return jsonify({"status": "accepted"})

Content Moderation Pipeline

Use TruthLens as part of your moderation stack:

  1. User uploads image
  2. TruthLens API checks authenticity
  3. Flag high-confidence AI images for review
  4. Auto-reject obvious deepfakes
  5. Log results for audit trail

Pricing

Plan Detections/mo Price
Free 50 $0
Pro 5,000 $29/mo
Business Unlimited $99/mo

Get Your API Key

  1. Sign up at truthlensbyai.online
  2. Go to Dashboard
  3. Copy your API key
  4. Start detecting!

Have questions about integration? Drop them in the comments or check our API docs.