The Copyleaks AI Image Detection API is a powerful tool to determine if a given image was generated or partially generated by an AI. As a consumer, you might have a PDF with images. If you want to scan those images separately from the PDF, this guide is for you. This guide will walk you through the process of extracting images from a pdf file and submitting them to the Copyleaks AI Detector and understanding the results.

Get started

1

Before you begin

Before you start, ensure you have the following:
2

Installation

Install the relevant packages using pip install -U PyMuPDF Pillow copyleaks.
3

Login

To perform a scan, we first need to generate an access token. For that, we will use the login endpoint. The API key can be found on the Copyleaks API Dashboard.Upon successful authentication, you will receive a token that must be attached to subsequent API calls via the Authorization: Bearer <TOKEN> header. This token remains valid for 48 hours.
Response
Save this token. It is valid for 48 hours and can be reused for subsequent API calls.
4

Extracting images from a PDF file

Next, we are going to extract all the images from the PDF. The function below will take a pdf file path and extract all its images to a specified directory.The following example takes the input PDF file and outputs all its nested images to the output_folder directory
5

Submit for analysis

Once we have the extracted images, you can submit them for analysis.We are going to use the AI Image Detector Endpoint to send an image for analysis.

AI Detection scan

This function takes your image, converts it to base64, and submits it via the SDK’s ImageDetectionClient. The SDK handles authentication and HTTP transport.
6

Interpreting the response

See the Interpreting The Response page on Detecting AI-Generated Images

Summary

You have successfully submitted images from PDF for AI detection. You are free to adapt this code to your needs.

Next steps

API Reference

Explore the full API reference for the AI Image Detection endpoint.

AI Image Detector Response

Explore the full response for the AI Image Detection.

Accuracy & 3rd Party Evaluations

Discover how Copyleaks AI Detector maintains top accuracy in third-party evaluations.