# AI Image Detection for Images and PDFs (Async)

> Submit an image or a PDF for AI-generated content detection. Every image in the file is checked, and one result document is delivered to your webhook.

Submit an image or a PDF for AI-generated content detection. The endpoint is **asynchronous** - it returns `201 Created` immediately, and one result document, holding a result for every image in the file, is delivered to your webhook once processing is complete.

For a PDF, Copyleaks finds the images embedded in the document, checks each image, and tells you where it is drawn. A single image is answered with the same document shape, holding one image, so your webhook parses one format whatever you sent.

Use this endpoint for PDFs, or when you want one webhook format for images and PDFs alike. The [v1 asynchronous endpoint](/reference/actions/ai-image-detector/submit) and the synchronous [AI Image Detection](/reference/actions/ai-image-detector/check) endpoint are unchanged and still accept images only.

Authentication is required. See [Login](/reference/actions/account/login) for how to obtain a bearer token.

## Path parameters

<ParamField path="scanId" type="string" required>
  A unique scan id provided by you. We recommend using the same id in your database to represent the scan in the Copyleaks database - this helps debug incidents and avoid duplicate scans for the same file. See [criteria for creating a Scan ID](/concepts/management/choosing-scan-id).

  `>= 3 characters` &nbsp; `<= 36 characters`

  Match pattern: ``[a-z0-9!@$^&+%=_(){}<>'";:/.,~`|\\-]`` (`\\` is a single backslash)

  Scan IDs that contain `g`, then one or more `o` or `0`, then `gle` (for example `google`, `gogle`, `g00gle`) are rejected.

  Submitting a scan id that already exists returns `409 Conflict`.
</ParamField>

## Headers

```http
Content-Type: application/json
Authorization: Bearer YOUR_LOGIN_TOKEN
```

## Body parameters

Provide the file either as a `url` or as `base64`.

<ParamField body="url" type="string">
  Publicly accessible `http` or `https` URL of the image or PDF to analyze. Required unless `base64` is provided.

  The URL must resolve to a public address. URLs that point to private, loopback or link-local addresses are refused with the `bad_url` error, and every redirect (up to 5) is checked the same way.

  Example: `"https://example.com/annual-report.pdf"`
</ParamField>

<ParamField body="base64" type="string">
  The file content, base64-encoded. Required unless `url` is provided. When both are sent, `base64` is used. The whole request body is limited to 70MB, so a file sent this way must also stay under the 50MB file limit once decoded.

  Example: `"JVBERi0xLjcKJeLjz9M..."`
</ParamField>

<ParamField body="fileName" type="string" required>
  The name of the file including its extension. The extension decides whether the file is handled as an image or as a PDF.

  **Supported extensions:** `.pdf`, `.jpg`, `.jpeg`, `.png`, `.webp`, `.bmp`, `.heic`, `.heif`, `.avif`

  Any other extension is refused at submit with the `unsupported_file_type` error (code 10).

  Example: `"annual-report.pdf"`
</ParamField>

<ParamField body="model" type="string" required>
  The AI image detection model to use for analysis.

  - AI Image 1 Ultra: `"ai-image-1-ultra"`

  Example: `"ai-image-1-ultra"`
</ParamField>

<ParamField body="maskType" type="string" default="binary">
  The type of detection mask to include for each analyzed image.

  Supported values:
  - `"binary"` (default) - a mask of the regions flagged as AI-generated, as a transparent PNG in `result.base64`: palette index `0` is human, `1` is AI.
  - `"heatmap"` - the same transparent PNG, where the palette index is the confidence level, `1` to `5` (`0` is human). Higher levels mean higher confidence.
  - `"none"` - no mask. Each image carries its scores only, which keeps the webhook body small for large PDFs.

  Any other value is refused at submit with a `400`.

  Example: `"none"`
</ParamField>

<ParamField body="maskStyle" type="object">
  Optional. The colours and opacity drawn into the PNG masks, so they can be laid straight over the image. Only how a mask looks changes: the palette index is the mask value whatever the style. `human`, `ai` and `levels` are ignored for `maskType: "none"`; `object` applies to the `detectedObjects` masks.

  <Expandable title="properties">
    <ParamField body="human" type="object" default="{ &quot;color&quot;: &quot;#000000&quot;, &quot;opacity&quot;: 0 }">
      Human pixels: `color` as `"#RRGGBB"` and `opacity` from `0` (fully transparent) to `1` (solid). By default human pixels are fully transparent.
    </ParamField>
    <ParamField body="ai" type="object" default="{ &quot;color&quot;: &quot;#E63946&quot;, &quot;opacity&quot;: 0.6 }">
      AI pixels of a binary mask, with the same `color` and `opacity` fields. Its `opacity` also applies to every heatmap level.
    </ParamField>
    <ParamField body="levels" type="array<string>" default="[&quot;#FFE65A&quot;, &quot;#FFBE32&quot;, &quot;#FF8C28&quot;, &quot;#EB5028&quot;, &quot;#B9143C&quot;]">
      Heatmap only: exactly five `"#RRGGBB"` colours, one per level, lowest first.
    </ParamField>
    <ParamField body="object" type="object" default="{ &quot;color&quot;: &quot;#3A86FF&quot;, &quot;opacity&quot;: 0.6 }">
      The object's pixels in each `detectedObjects` mask, with the same `color` and `opacity` fields. The rest of an object mask is always transparent.
    </ParamField>
  </Expandable>

  An invalid style (a colour that is not `#RRGGBB`, an opacity outside `0`-`1`, not exactly five levels, or an unknown field) is refused before any charge, with `missing_parameter` (1) naming the `maskStyle` field.

  Example: `{ "ai": { "color": "#00A3FF", "opacity": 0.5 } }`
</ParamField>

<ParamField body="objectDetection" type="array">
  Optional. A list of objects to locate and segment within every analyzed image, with the same rules as the [v1 asynchronous endpoint](/reference/actions/ai-image-detector/submit). When provided, each analyzed image additionally includes a `detectedObjects` array.

  - Maximum 3 entries.
  - Each entry's `object` value must be a non-empty string of at most 32 characters.
  - Object detection must be enabled for your account; otherwise the request is refused with `403 Forbidden`.

  Example: `[{ "object": "face" }]`
</ParamField>

<ParamField body="webhooks" type="object" required>
  Webhook configuration for receiving the async results.

  <Expandable title="properties">
    <ParamField body="webhooks.url" type="string" required>
      The URL that Copyleaks will POST the result document to when processing is complete.

      Example: `"https://your-server.com/webhook/receive-results"`
    </ParamField>
    <ParamField body="webhooks.headers" type="array">
      Optional custom headers to include in the webhook request. Each entry is a two-element array: `["Header-Name", "Header-Value"]`.

      Example: `[["Authorization", "Bearer my-webhook-token"]]`
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="sandbox" type="boolean" default="false">
  Use sandbox mode to test your integration without consuming any credits. The request is validated as usual, and your webhook receives a mock result document holding one image. Intended for development purposes only.
</ParamField>

<ParamField body="developerPayload" type="string">
  An optional string payload that Copyleaks will include in the webhook body, allowing you to correlate the callback with your internal data.

  Example: `"order-id-12345"`
</ParamField>

## Limits

| Limit | Value |
| ----- | ----- |
| File size | 50MB |
| Request body (with `base64`) | 70MB |
| PDF pages | 100 |
| Candidate images in a PDF | 25 |
| Each image | At least 400px on each side, at most 27 megapixels, aspect ratio at most 4:1, under 32MB |
| Result document | 20MB |

**Candidate images** are the images whose declared size is within the minimum-side, megapixel and aspect-ratio limits. They are counted before the images are decoded, and every place an image is drawn counts separately: a logo on 3 pages is 3 candidate images.

An image in a PDF that is outside the per-image limits, or fails a quality check (for example too dark, or too few colors), is not an error: it is listed in the result as `skipped`, with the reason, and is not charged.

When the result document would be larger than 20MB, the scan fails with `internal_server_error` (code 16) and all credits are refunded. Use `maskType: "none"` for PDFs with many large images.

## Billing

- **1 credit per analyzable image.**
- An image drawn several times in a PDF (for example a logo on every page) is a separate image, and is charged, each time it is drawn.
- `skipped` and `duplicate` images are free.
- Images that fail during detection are refunded, so `scannedDocument.actualCredits` is what you pay.
- A file rejected before detection (see [Errors](#errors)) is not charged.

Credits are checked once the images are counted. When your balance is too low, the webhook receives the `insufficient_credits` error (code 13) with the required number of credits, and nothing is charged.

<RequestExample>

```bash title="cURL" icon="terminal"
curl --request PUT \
  --url https://api.copyleaks.com/v2/ai-image-detector-async/my-pdf-scan-1/submit \
  --header 'Authorization: Bearer YOUR_LOGIN_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{
    "url": "https://example.com/annual-report.pdf",
    "fileName": "annual-report.pdf",
    "model": "ai-image-1-ultra",
    "maskType": "none",
    "webhooks": {
      "url": "https://your-server.com/webhook/receive-results"
    }
  }'
```

```python title="Python" icon="python"
import requests

url = 'https://api.copyleaks.com/v2/ai-image-detector-async/my-pdf-scan-1/submit'
headers = {
    'Authorization': 'Bearer YOUR_LOGIN_TOKEN',
    'Content-Type': 'application/json'
}

payload = {
    'url': 'https://example.com/annual-report.pdf',
    'fileName': 'annual-report.pdf',
    'model': 'ai-image-1-ultra',
    'maskType': 'none',
    'webhooks': {
        'url': 'https://your-server.com/webhook/receive-results'
    }
}

response = requests.put(url, json=payload, headers=headers)
print(f"Submission status: {response.status_code}")  # 201 Created
```

```javascript title="JavaScript" icon="square-js"
const response = await fetch(
  'https://api.copyleaks.com/v2/ai-image-detector-async/my-pdf-scan-1/submit',
  {
    method: 'PUT',
    headers: {
      'Authorization': 'Bearer YOUR_LOGIN_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      url: 'https://example.com/annual-report.pdf',
      fileName: 'annual-report.pdf',
      model: 'ai-image-1-ultra',
      maskType: 'none',
      webhooks: {
        url: 'https://your-server.com/webhook/receive-results'
      }
    })
  }
);

console.log('Submission status:', response.status); // 201 Created
```

```http title="HTTP" icon="globe"
PUT https://api.copyleaks.com/v2/ai-image-detector-async/my-pdf-scan-1/submit
Content-Type: application/json
Authorization: Bearer YOUR_LOGIN_TOKEN

{
  "url": "https://example.com/annual-report.pdf",
  "fileName": "annual-report.pdf",
  "model": "ai-image-1-ultra",
  "maskType": "none",
  "webhooks": {
    "url": "https://your-server.com/webhook/receive-results"
  }
}
```

</RequestExample>

<ResponseExample>

```json 201 Created
{}
```

```json 400 Bad Request
{
  "error": {
    "type": "invalid_request_error",
    "id": "unsupported_file_type",
    "code": 10,
    "message": "This file type is not supported."
  }
}
```

```json 401 Unauthorized
{
  "error": "Authentication or authorization failed."
}
```

```json 403 Forbidden
{
  "error": {
    "type": "authentication_error",
    "id": "authorization_denied",
    "code": 37,
    "message": "Please reach out to your sales representative to access the object detection feature."
  }
}
```

```json 409 Conflict
{}
```

```json 429 Too Many Requests
{
  "error": "Rate limit exceeded."
}
```

```json 500 Internal Server Error
{
  "error": "The server encountered an internal error."
}
```

</ResponseExample>

## Webhook payload

When processing completes, Copyleaks sends a `POST` request to your webhook URL with one JSON document for the whole file. See the [AI Image Document Response](/reference/data-types/ai-detector/ai-image-document-response) reference for every field.

```json
{
  "model": "ai-image-1-ultra",
  "document": {
    "type": "pdf",
    "pageCount": 3,
    "imagesFound": 3,
    "imagesAnalyzed": 2,
    "imagesSkipped": 1,
    "imagesFailed": 0
  },
  "summary": { "ai": 0.744, "human": 0.256, "isAiDetected": true, "aiImages": 1 },
  "images": [
    {
      "id": "1",
      "locations": [
        { "page": 1, "box": { "left": 0.08, "top": 0.05, "width": 0.16, "height": 0.08 } }
      ],
      "status": "analyzed",
      "summary": { "ai": 0.0, "human": 1.0 },
      "isAiDetected": false,
      "imageInfo": { "shape": { "width": 600, "height": 600 } }
    },
    {
      "id": "2",
      "locations": [ { "page": 2, "box": { "left": 0.1, "top": 0.3, "width": 0.8, "height": 0.45 } } ],
      "status": "analyzed",
      "summary": { "ai": 0.93, "human": 0.07 },
      "isAiDetected": true,
      "imageInfo": { "shape": { "width": 1600, "height": 900 } }
    },
    {
      "id": "3",
      "locations": [ { "page": 3, "box": { "left": 0.4, "top": 0.9, "width": 0.05, "height": 0.03 } } ],
      "status": "skipped",
      "error": "image_too_small"
    }
  ],
  "scannedDocument": {
    "scanId": "my-pdf-scan-1",
    "expectedCredits": 2,
    "actualCredits": 2,
    "creationTime": "11/4/2026 10:07:58 AM"
  },
  "developerPayload": "order-id-12345"
}
```

- **One entry per image drawn**: an image drawn on several pages (for example a logo) is a separate entry on each page, with its own `id`, score and location.
- **`id`** is `"1"`, `"2"`, ... in the order images first appear in the file. Ids are assigned before any image is skipped, so they stay stable.
- **`locations[].box`** places the image on its page as fractions of the page width and height, measured from the top-left corner. It is absent when the page layout could not be read. A single image is one location on page 1 covering the whole page.
- **`status`** is `analyzed`, `skipped` (free, with an `error` id such as `image_too_small` or `image_too_dark`), `duplicate` (free: the same picture stored a second time in the file, with `duplicateOf` naming the image it repeats; it carries no `result` or `detectedObjects`) or `failed` (refunded, with an `error` id).
- A single image that is outside the per-image limits is answered with a document holding one `skipped` image, at 0 credits.

<Note>
  The body grows with the number of images and with the mask: a PDF with many images, `maskType: "heatmap"` and `objectDetection` can produce a large payload, up to the 20MB result limit. Make sure your webhook accepts large bodies, or use `maskType: "none"` when you only need the scores.
</Note>

## Errors

Some errors are returned at submit, before anything is queued. The others are found once the file is downloaded and arrive at your webhook instead of the result document, in the standard [error format](/using-the-apis/api-errors). No credits are charged for any of them; the result-size error is refunded in full.

| Condition | Where | Error (code) |
| --------- | ----- | ------------ |
| `fileName` is not an image or a PDF | Submit `400` | `unsupported_file_type` (10) |
| `maskType` is not `binary`, `none` or `heatmap` | Submit `400` | `missing_parameter` (1) |
| `maskStyle` is invalid | Webhook | `missing_parameter` (1), naming the `maskStyle` field |
| `objectDetection` is invalid | Submit `400` | `missing_parameter` (1) |
| Object detection is not enabled for your account | Submit `403` | `authorization_denied` (37) |
| `base64` is not valid base64 | Submit `400` | Plain body `"Failed to process image"` |
| The request body is larger than 70MB | Submit | Rejected before validation |
| The URL resolves to a non-public address | Webhook | `bad_url` (44) |
| The file could not be downloaded | Webhook | `download_failed` (5) |
| The file is larger than 50MB | Webhook | `file_too_large` (6) |
| The PDF needs a password to open | Webhook | `file_password_protected` (41) |
| The PDF cannot be read, or has no pages | Webhook | `invalid_file` (14) |
| The PDF has more than 100 pages | Webhook | `document_too_long` (12) |
| The PDF has more than 25 candidate images | Webhook | `too_many_images` (75) |
| The PDF has no image that can be analyzed | Webhook | `no_analyzable_images` (74), with one `details` entry per skip reason |
| Not enough credits | Webhook | `insufficient_credits` (13) |
| PDF processing is temporarily unavailable | Webhook | `temporarily_unavailable` (9) |
| The result document would be larger than 20MB | Webhook | `internal_server_error` (16), all credits refunded |

When every analyzed image fails during detection, the webhook receives `internal_server_error` (16) and all credits are refunded.
