# Best Practices for Working with Images

> Learn how to optimize performance when using the Copyleaks AI Image Detection API, including compression, multipart uploads and throughput optimization.

Follow these best practices to **maximize performance, reduce bandwidth usage and improve throughput** when working with the Copyleaks [AI Image Detection](https://copyleaks.com/ai-detector/ai-image-detector) API.

<Note>
This guide covers best practices specifically for **AI Image Detection**. For text and document scanning optimization, see the [Text & Document Best Practices](/concepts/performance/best-practices) guide.
</Note>

## Use Multipart/Form-Data Format

Always use **multipart/form-data** instead of JSON with base64 encoding:
- **Smaller payload size**: Avoids 33% base64 encoding overhead
- **Faster uploads**: Direct binary transfer is more efficient
- **Better memory usage**: Reduces processing overhead

## Enable Response Compression

Add this header to your requests to reduce response size:

```http
Accept-Encoding: gzip
```

Image detection results can include large RLE masks. Most HTTP clients automatically decompress gzip responses.

## Submit Scans at an Optimal Rate

The API has rate limits to ensure optimal performance:
- **900 requests per 15 minutes** per host
- **10 requests per second** per user (default)

Send images at a steady rate rather than in bursts, and implement retry logic with exponential backoff when rate limits are reached.

<Tip>
Need higher rate limits? Contact [support@copyleaks.com](mailto:support@copyleaks.com) to discuss custom plans.
</Tip>

## Scale Across Multiple Servers

For higher throughput, distribute uploads across multiple servers. Each server can independently send up to 900 requests per 15 minutes, allowing parallel processing of large image batches.

## Reuse Your Authentication Token

JWT tokens are **valid for 48 hours**:
- Cache and reuse tokens for multiple requests
- Refresh before the 48-hour window ends
- Avoid calling the login API for every image submission

## Preserve Original Image Data

Submit images in their original form for accurate [AI detection](https://copyleaks.com/ai-detector) results.

**Avoid:**
- Resizing or cropping
- Recompressing or converting formats
- Applying filters or adjustments

**Best practice:** Submit the exact image file as received or captured, preserving EXIF metadata and original format. AI-generated images have subtle patterns in pixel data that can be lost through manipulation.

## Summary

- Use **multipart/form-data** format
- Enable **response compression** with `Accept-Encoding: gzip`
- Submit at a **steady rate** (under 900/15min per host, 10/sec per user)
- **Distribute load across multiple servers** for higher throughput
- **Reuse authentication tokens** for up to 48 hours
- **Submit original images** without modifications

## Next Steps

<CardGroup cols={2}>
  <Card title="AI Image Detection Guide" icon="image" href="/guides/ai-detector/ai-image-detection/">Learn how to implement AI image detection in your application.</Card>
  <Card title="AI Image Detection API Reference" icon="code" href="/reference/actions/ai-image-detector/check/">View the complete API specification and parameters.</Card>
</CardGroup>
