# Grouping Brackets and Processing Orders

This API endpoint allows you to group/merge HDR brackets in your order. To group the brackets in the order, you must provide the `order_id` and a valid API key.

{% hint style="info" %}
You can group your images by specific amount of brackets when using the property `number_of_brackets_per_image`, we will group you brackets based on a visual analysis if you don't specify the number of brackets.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}

```javascript
const apiKey = "YOUR_API_KEY";
const orderId = "ID_OF_YOUR_ORDER";
const preferences = {
  ai_version: "5.x",
  enhance: true,
  enhance_type: 'property',
  hdr: true
}
const mergeOrder = async (apiKey,orderId, preferences) => {
    return await fetch(
      `https://api.autoenhance.ai/v3/orders/${orderId}/process`,
      {
        method: "POST",
        headers: {
          "x-api-key": apiKey,
        },
        body: JSON.stringify({
          image_name: "your-image-name",
          contentType: "image/jpeg",
          ...preferences
        }),
      }
    );
}
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

api_key = "YOUR_API_KEY"
order_id = "ID_OF_YOUR_ORDER"
preferences = {
    "ai_version": "5.x",
    "enhance": True,
    "enhance_type": "property",
    "hdr": True
}

def merge_order(api_key, order_id, preferences):
    url = f"https://api.autoenhance.ai/v3/orders/{order_id}/merge"
    headers = {
        "x-api-key": api_key,
        "Content-Type": "application/json"
    }
    body = {
        "image_name": "your-image-name",
        "contentType": "image/jpeg",
        **preferences
    }
    response = requests.post(url, headers=headers, data=json.dumps(body))
    return response
```

{% endtab %}

{% tab title="PHP" %}

```php
$api_key = "YOUR_API_KEY";
$order_id = "ID_OF_YOUR_ORDER";
$preferences = array(
    "ai_version" => "5.x",
    "enhance" => true,
    "enhance_type" => "property",
    "hdr" => true
);

function merge_order($api_key, $order_id, $preferences) {
    $url = "https://api.autoenhance.ai/v3/orders/$order_id/merge";

    $options = array(
        'http' => array(
            'header'  => "Content-Type: application/json\r\n" .
                         "x-api-key: $api_key",
            'method'  => 'POST',
            'content' => json_encode($preferences)
        )
    );

    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);

    if ($result === FALSE) {
        return 'Error merging order';
    }

    return $result;
}
```

{% endtab %}

{% tab title="cURL" %}

```
curl -X POST \
  'https://api.autoenhance.ai/v3/orders/YOUR_ORDER_ID/merge' \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: YOUR_API_KEY' \
  -d '{
        "ai_version": "5.x",
        "enhance": true,
        "enhance_type": "property",
        "hdr": true,
        "image_name": "your-image-name",
        "contentType": "image/jpeg"
    }'
```

{% endtab %}
{% endtabs %}

Merging can take between 10 seconds to 5 minutes, depending on the number of brackets that need grouping. During this time, no images will show up when you try to [retrieve your order](https://docs.autoenhance.ai/orders/managing-orders/retrieving).

Once a grouping has been completed all groups will show up when you [retrieve your order](https://docs.autoenhance.ai/orders/managing-orders/retrieving), and the AI will start to merge HDRs and enhance them.

### Specification

## Process Order

> Triggers the grouping of any brackets contained in the order and process the final images in the order.\
> \
> TODO: Ideally we use transactions to help deal with errors but it;s a pain with MongoEngine so need to do it as part of Django or other ORM

```json
{"openapi":"3.0.3","info":{"title":"Autoenhance API","version":"2026-06-02"},"tags":[{"name":"Orders"}],"servers":[{"url":"https://api.autoenhance.ai"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"in":"header","name":"x-api-key","type":"apiKey"}},"schemas":{"OrderHDRProcessIn":{"properties":{"ai_version":{"description":"The version of the AI model to use for enhancing the image. Versions ending in an .x will use the latest minor version as soon as it's published.","type":"string"},"cloud_type":{"description":"The type of clouds in the new sky to replace the original sky with. Options include: CLEAR, LOW_CLOUD, HIGH_CLOUD","enum":["CLEAR","LOW_CLOUD","HIGH_CLOUD",null],"nullable":true,"type":"string"},"enhance":{"default":true,"description":"Whether to enhance the image.","type":"boolean"},"enhance_type":{"description":"The type of enhancement to apply to the image. PROPERTY or PROPERTY_USA is used with AI version < 4.0, for >= 4.0 use WARM or NEUTRAL..","enum":["property","property_usa","warm","neutral","modern"],"type":"string"},"finetune_settings":{"anyOf":[{"nullable":true,"type":"object"},{"$ref":"#/components/schemas/FinetuneOptions"}]},"images":{"items":{"$ref":"#/components/schemas/OrderHDRImageIn"},"type":"array"},"lens_correction":{"default":true,"description":"Correct any lens distortion in the image.","type":"boolean"},"number_of_brackets_per_image":{"description":"If provided then group into an image after every specified number of brackets, if  not provided or set to 0 then we automatically group based on visual analysis.","type":"integer"},"preset_id":{"nullable":true,"type":"string"},"privacy":{"description":"Whether to blur any faces or license plates in the image.","nullable":true,"type":"boolean"},"restage":{"anyOf":[{"$ref":"#/components/schemas/Restage"},{"nullable":true,"type":"object"}],"description":"Restage options for in-painting or modifying scene elements. Allows correcting details like lighting a fireplace, removing fingerprints from a TV screen, or removing unwanted items like tripods."},"sky_replacement":{"description":"Enable the replacement of the original sky for a summer sky.","type":"boolean"},"upscale":{"description":"Whether to upscale the image.","type":"boolean"},"vertical_correction":{"default":true,"description":"Correct any vertical distortion in the image so that it appears straight.","type":"boolean"},"window_pull_type":{"description":"What type of window pull to apply to the image (Available since AI version >= 4.0, WITH_SKIES can only be used from AI version 5.2 or higher).","enum":["NONE","ONLY_WINDOWS","WINDOWS_WITH_SKIES",null],"nullable":true,"type":"string"}},"type":"object"},"FinetuneOptions":{"additionalProperties":false,"properties":{},"type":"object"},"OrderHDRImageIn":{"additionalProperties":false,"properties":{"bracket_ids":{"items":{"type":"string"},"type":"array"}},"type":"object"},"Restage":{"properties":{"fire_in_fireplaces":{"description":"Controls the appearance of fireplaces. 'AS_SHOT' leaves the fireplace exactly as captured (e.g., unlit). 'ALIGHT' in-paints fire into the fireplace to make it appear active.","enum":["AS_SHOT","ALIGHT",null],"nullable":true,"type":"string"},"grass":{"description":"Controls grass appearance enhancement. 'AS_SHOT' leaves the grass exactly as captured. 'GREEN' applies grass greening to make brown/dead grass appear lush and green.","enum":["AS_SHOT","GREEN",null],"nullable":true,"type":"string"},"photographer":{"description":"Controls removal of photographer. 'AS_SHOT' leaves the photographer exactly as captured. 'REMOVE' removes the photographer including their shadow, reflection and hands.","enum":["AS_SHOT","REMOVE",null],"nullable":true,"type":"string"},"tvs":{"description":"Controls the appearance of television screens in the photo. 'AS_SHOT' leaves the TV screen exactly as captured. 'BLACK_OUT' in-paints the screen to appear completely black/off.","enum":["AS_SHOT","BLACK_OUT",null],"nullable":true,"type":"string"}},"type":"object"},"OrderHDRProcessOut":{"additionalProperties":false,"properties":{"created_at":{"description":"The creation date of the order.","format":"date-time","type":"string"},"default_image_sort_order":{"description":"Default sort order for images in the order.","enum":["name","-name","date_added","-date_added","custom"]},"images":{"description":"The list of images for the order.","readOnly":true},"is_deleted":{"description":"The status of the order.","type":"boolean"},"is_merging":{"description":"The processing status for the order","type":"boolean"},"is_processing":{"description":"The processing status for the order","type":"boolean"},"last_updated_at":{"description":"The last updated date of the order.","format":"date-time","type":"string"},"name":{"description":"The name for the order.","type":"string"},"order_id":{"description":"The ID for the order.","type":"string"},"status":{"description":"The status of the order.","readOnly":true},"total_images":{"description":"Number of images in the  order.","type":"number"}},"type":"object"},"HTTPError":{"properties":{"detail":{"type":"object"},"message":{"type":"string"}},"type":"object"},"ValidationError":{"properties":{"detail":{"properties":{"<location>":{"properties":{"<field_name>":{"items":{"type":"string"},"type":"array"}},"type":"object"}},"type":"object"},"message":{"type":"string"}},"type":"object"}}},"paths":{"/v3/orders/{id}/process":{"post":{"description":"Triggers the grouping of any brackets contained in the order and process the final images in the order.\n\nTODO: Ideally we use transactions to help deal with errors but it;s a pain with MongoEngine so need to do it as part of Django or other ORM","operationId":"process_order","parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/OrderHDRProcessIn"}}}},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/OrderHDRProcessOut"}}},"description":"Successful response"},"401":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Authentication error"},"404":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Not found"},"422":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}},"description":"Validation error"}},"summary":"Process Order","tags":["Orders"]}}}}
```
