> ## Documentation Index
> Fetch the complete documentation index at: https://ailabtools.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Intelligent Composition API

> Intelligent Composition API analyzes image aesthetics and returns smart crop boxes for better framing and composition.

## Request

* **URL**: `https://www.ailabapi.com/api/image/editing/intelligent-composition`
* **Method**: `POST`
* **Content-Type**: `multipart/form-data`

### Image requirements

* **Image format**: `JPEG` `JPG` `PNG` `BMP` `WEBP`
* **Image size**: No more than 3 MB.
* **Image resolution**: Larger than 32x32px, smaller than 4096x4096px.

### Headers

| Field              | Required | Type     | Description                                           |
| :----------------- | :------- | :------- | :---------------------------------------------------- |
| `ailabapi-api-key` | YES      | `string` | Application API KEY. [Get API KEY](/docs/get-api-key) |

### Body

| Field       | Required | Type      | Scope                                             | Default | Description                 |
| :---------- | :------- | :-------- | :------------------------------------------------ | :------ | :-------------------------- |
| `image`     | YES      | `file`    |                                                   |         |                             |
| `num_boxes` | NO       | `integer` | `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10` | `5`     | The number of output boxes. |

## Response

<Warning>
  **Response Field Handling Flow**

  1. **Handle `Public Response Fields`**

     Parse and validate the `Public Response Fields`, checking the status code or response message to ensure the request is successful and error-free.

  2. **Handle `Business Response Fields`**

     If the `Public Response Fields` are valid and error-free, proceed with processing the business logic in the `Business Response Fields`.
</Warning>

### Public Response Fields

<a href="/docs/response-description" target="_blank">Viewing Public Response Fields and Error Codes</a>

### Business Response Fields

| Field       | Type      | Description                                                                                                  |
| :---------- | :-------- | :----------------------------------------------------------------------------------------------------------- |
| `data`      | `object`  | The content of the result data returned.                                                                     |
| +`elements` | `array`   | Intelligent composition results.                                                                             |
| ++`min_x`   | `integer` | The horizontal coordinate of the upper-left corner of the output box.                                        |
| ++`max_x`   | `integer` | The horizontal coordinate of the lower-right corner of the output box.                                       |
| ++`min_y`   | `integer` | The vertical coordinate of the upper-left corner of the output box.                                          |
| ++`max_y`   | `integer` | The lower-right vertical coordinate of the output box.                                                       |
| ++`score`   | `float`   | The higher the score, the better the composition. 3.8 or above is recommended as a better composition score. |

### Response Example

```json theme={null}
{
  "request_id":     "",
  "log_id":         "",
  "error_code":     0,
  "error_msg":      "",
  "error_detail":   {
    "status_code":  200,
    "code":         "",
    "code_message": "",
    "message":      ""
  },
  "data": {
    "elements": [
      {
        "min_x": 0,
        "max_x": 0,
        "min_y": 0,
        "max_y": 0,
        "score": 0
      }
    ]
  }
}
```


## OpenAPI

````yaml POST /api/image/editing/intelligent-composition
openapi: 3.0.0
info:
  title: AILabAPI
  description: >-
    [<b>AILabTools</b>](https://www.ailabtools.com) is an advanced tool that
    offers a vast array of simple and flexible API endpoints to suit your
    specific needs. With just one [<b>API
    KEY</b>](https://www.ailabtools.com/doc/get-api-key), you can easily call
    any of the endpoints and integrate them quickly into your application or
    workflow, allowing for smooth and efficient operations. 
     
    [<b>AILabTools</b>](https://www.ailabtools.com) is continuously evolving,
    and you can anticipate even more API endpoints being added in the future,
    further enhancing its capabilities and usefulness for your artificial
    intelligence and machine learning requirements.
  version: 1.0.0
servers:
  - url: https://www.ailabapi.com
    description: Production server
security:
  - apiKeyAuth: []
tags:
  - name: AI IMAGE
  - name: AI IMAGE > Image Enhancement
  - name: AI IMAGE > Image Effects
  - name: AI IMAGE > Image Editing
  - name: AI IMAGE > Image Scoring
  - name: AI BACKGROUND REMOVAL
  - name: AI BACKGROUND REMOVAL > Portrait
  - name: AI BACKGROUND REMOVAL > General
  - name: AI PORTRAIT
  - name: AI PORTRAIT > Portrait Effects
  - name: AI PORTRAIT > Portrait Enhance
  - name: AI PORTRAIT > Portrait Editing
  - name: AI PORTRAIT > Portrait Analysis
  - name: AI COMMON
paths:
  /api/image/editing/intelligent-composition:
    post:
      tags:
        - AI IMAGE > Image Editing
      summary: Intelligent Composition
      description: >-
        Intelligent Composition API analyzes image aesthetics and returns smart
        crop boxes for better framing and composition.
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                image:
                  type: string
                  format: binary
                num_boxes:
                  type: string
                  description: The number of output boxes.
      responses:
        '200':
          headers:
            Content-Type:
              schema:
                type: string
                example: application/json
          content:
            application/json:
              schema:
                type: object
              example:
                request_id: ''
                log_id: ''
                error_detail:
                  code: ''
                  code_message: ''
                  message: ''
                data:
                  elements:
                    - min_x: 0
                      max_x: 0
                      min_y: 0
                      max_y: 0
                      score: 0
          description: Success
components:
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: ailabapi-api-key
      description: API Key for authentication

````