Summarize this article with:
The rise of AI-generated content has made it increasingly difficult to distinguish between human and machine-created text, images, and deepfakes.
Whether you're a journalist, a researcher, or simply a concerned internet user, detecting AI-generated content is a crucial skill.
In this guide, we will explore how to build an AI content detection API using FastAPI and Eden AI APIs to spot fake content quickly and efficiently.
Why AI Detection Matters
AI-generated content can be used for both beneficial and harmful purposes. While it helps automate content creation, it also poses risks such as misinformation, fraud, and deepfake scams.
With the right tools, we can verify content authenticity and mitigate these risks.
Setting Up the AI Content Detection API
If you want a complete, in-depth breakdown of this tutorial, be sure to watch our YouTube tutorial with Developer Advocate Krishna Kompalli, where we walk you through each step, explain the details of the code, and discuss how to best integrate these tools into your projects.
Prerequisites
Before we begin, ensure you have the following installed:
- Python 3.8+
- FastAPI (for building the API)
- Uvicorn (for running the FastAPI server)
- Requests (for making API calls)
- Dotenv (for managing environment variables)
You can install the required packages using:
Creating the FastAPI Application
Let's begin by creating a simple FastAPI application that will host our AI detection endpoints. FastAPI makes it easy to build RESTful APIs with automatic interactive documentation.
Configuring Logging and Environment Variables
Before diving into the API endpoints, it’s important to set up logging and manage sensitive data like API keys using environment variables. Logging helps track API requests and potential errors, while environment variables store sensitive data such as API keys.
Here, we use dotenv to load the EDENAI_API_KEY from a .env file. This key is necessary to interact with the Eden AI API, which provides AI content detection services.
Initializing FastAPI and CORS Middleware
Next, we initialize FastAPI and set up CORS (Cross-Origin Resource Sharing) to allow requests from any domain. This is important if the API is going to be used across different client applications.
Now, we’re ready to define the API endpoints.
Defining API Endpoints
We will create three key endpoints to detect different types of AI-generated content:
- Text AI Detection: Detects whether the given text is AI-generated.
- Image AI Detection: Identifies AI-generated images, either uploaded as a file or provided via a URL.
- Deepfake Detection: Analyzes images or videos for deepfake content.
1. Detecting AI-Generated Text
This function sends the given text to Eden AI's AI Detection API and checks whether it's AI-generated.
This function takes a text input and uses the Eden AI API to detect if it's AI-generated. The API response is then returned as JSON, which includes the analysis result.
2. Detecting AI-Generated Images
This endpoint checks if an uploaded image or a provided image URL is AI-generated.
Here, we handle both file uploads and URLs. The image file or URL is sent to Eden AI's image detection endpoint for analysis.
3. Detecting Deepfakes
This function detects deepfake content by analyzing uploaded files or URLs.
This endpoint focuses on detecting deepfake images or videos, which is critical for verifying the authenticity of media content.
Running the API
To run the FastAPI server, use the following command:
This command will start the API server, making it accessible on localhost at port 8000.
Testing the API
Once the server is running, you can test the endpoints using Postman or cURL.
For example, to test the text detection endpoint, you can use the following cURL command:
Conclusion
In this guide, we built an AI content detection API using FastAPI and Eden AI APIs. With this API, you can:
- Detect AI-generated text
- Identify AI-created images
- Spot deepfake media
By implementing this solution, you’ll be able to enhance your content verification workflows and help mitigate the risks of misinformation and deception. Don't forget to watch our Youtube tutorial for a thorough breakthrough.
Whether you're working in media, cybersecurity, or simply seeking to improve your personal content validation practices, integrating this API into your projects will allow you to spot fake content in seconds!

.jpg)

.avif)
.avif)