# Object Detection

> Locate and segment specific objects within an image.

<RequestExample>

```bash title="cURL" icon="terminal"
curl --request POST \
  --url https://api.copyleaks.com/v1/object-detection/my-scan-123/check \
  --header 'Authorization: Bearer YOUR_LOGIN_TOKEN' \
  --form 'image=@/path/to/test-image.png' \
  --form 'filename=test-image.png' \
  --form 'sandbox=true' \
  --form 'objectDetection=[{"object":"face"},{"object":"hand"}]'
```

```javascript title="JavaScript" icon="square-js"
const imageFile = document.getElementById('fileInput').files[0];
const formData = new FormData();

formData.append('image', imageFile);
formData.append('filename', imageFile.name);
formData.append('sandbox', 'true');
formData.append('objectDetection', JSON.stringify([{ object: 'face' }, { object: 'hand' }]));

const response = await fetch(
  'https://api.copyleaks.com/v1/object-detection/my-scan-123/check',
  {
    method: 'POST',
    headers: { 'Authorization': 'Bearer YOUR_LOGIN_TOKEN' },
    body: formData,
  }
);
const result = await response.json();
```

```http title="HTTP" icon="globe"
POST https://api.copyleaks.com/v1/object-detection/my-scan-123/check
Content-Type: multipart/form-data
Authorization: Bearer YOUR_LOGIN_TOKEN

image=<binary>
filename=test-image.png
sandbox=true
objectDetection=[{"object":"face"},{"object":"hand"}]
```

</RequestExample>

<ResponseExample>

```json 200 OK
{
  "imageInfo": {
    "shape": { "height": 1024, "width": 768 }
  },
  "detectedObjects": [
    {
      "object": "face",
      "mask": {
        "starts": [200, 412],
        "lengths": [50, 30]
      }
    }
  ],
  "scannedImage": {
    "scanId": "my-scan-123",
    "credits": 1,
    "expectedCredits": 1,
    "creationTime": "2023-01-10T10:07:58.9459512Z"
  }
}
```

</ResponseExample>

Locate and segment specific objects within an image. You supply a list of objects to look for, and the endpoint returns a Run-Length Encoded (RLE) segmentation mask for each object it finds.

This endpoint performs object segmentation only - it does not classify whether the image is AI-generated. To detect AI-generated content, use [AI Image Detection](/reference/actions/ai-image-detector/check).

<Warning>
**Authentication Required.** You need to login with a user and API key in order to access this method. Add this HTTP header to your request:

**Authorization: Bearer &lt;Your-Login-Token&gt;**
</Warning>

## Request

### Path Parameters

<ParamField path="scanId" type="string" required>
  A unique scan id provided by you. We recommend you use the same id in your database to represent the scan in the Copyleaks database. This will help you to debug incidents. Using the same ID for the same file will help you to avoid network problems that may lead to multiple scans for the same file. Learn more about [the criteria for creating a Scan ID](/concepts/management/choosing-scan-id).

  `>= 3 characters` `<= 36 characters`
</ParamField>

### Content Type

Submit images using **multipart/form-data**.

**Headers:**
```http
Content-Type: multipart/form-data
Authorization: Bearer YOUR_LOGIN_TOKEN
```

### Body Parameters

<ParamField body="image" type="file" required>
  Binary image file.

  **Requirements:**
  - **Size:** Minimum 512x512px, maximum 6000x4500px (27 megapixels)
  - **File size:** Less than 32MB
  - **Formats:** PNG, JPG, JPEG, BMP, WebP, HEIC/HEIF
</ParamField>
<ParamField body="filename" type="string" required>
  The name of the image file including its extension.

  **Requirements:**
  - Allowed file extensions: `.png`, `.jpg`, `.jpeg`, `.bmp`, `.webp`, `.heic`, `.heif`
  - `<= 255 characters`
</ParamField>
<ParamField body="objectDetection" type="array" required>
  The list of objects to locate and segment within the image. Sent as a single JSON-encoded form field, for example `objectDetection=[{"object":"face"},{"object":"hand"}]`.

  Each entry wraps the object name in an object (`{ "object": "face" }`) so future per-entry fields can be added without a breaking change.

  - Required. At least one entry.
  - Maximum 3 entries.
  - Each entry's `object` value must be a non-empty string of at most 32 characters.
</ParamField>
<ParamField body="sandbox" type="boolean" default="false">
  Use sandbox mode to test your integration with the Copyleaks API without consuming any credits.
</ParamField>

## Responses

<Tabs>
  <Tab title="200">
    <Check>**200 OK** - The image was successfully analyzed. See the [Object Detection Response](/reference/data-types/object-detection/object-detection-response) for the full field reference.</Check>
  </Tab>
  <Tab title="400">
    <Warning>**400 Bad Request** - Invalid request parameters, missing or malformed `objectDetection`, unsupported image format, or image processing issues.</Warning>
  </Tab>
  <Tab title="401">
    <Warning>**401 Unauthorized** - Authentication or authorization issues.</Warning>
  </Tab>
  <Tab title="402">
    <Warning>**402 Payment Required** - Insufficient credits.</Warning>
  </Tab>
  <Tab title="429">
    <Warning>**429 Too Many Requests** - Too many requests have been sent. The request has been rejected.</Warning>
  </Tab>
  <Tab title="500">
    <Warning>**500 Internal Server Error** - The server encountered an internal error or misconfiguration.</Warning>
  </Tab>
</Tabs>
