# Usage Example

Since there's a lot of combinations of the preferences that you can use, so we've prepared an code example that will help you understand how to work with them.

Let's repeat the process of creating and uploading images, but with all of the [Basic Enhancements](/images/basic-enhancements.md).

{% hint style="info" %}
You can freely edit the preferences in any way you want. The only requirement is to follow our [Image Settings](/images/basic-enhancements.md) guide or [API specification](https://api.autoenhance.ai/docs/v3), which will help you find the appropriate values.
{% endhint %}

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

```javascript
const apiKey = 'YOUR_API_KEY';
const preferences = {
    enhance_type: 'property',
    sky_replacement: true,
    cloud_type: 'CLEAR',
    vertical_correction: true,
    auto_privacy: true,
};

const createImage = async (apiKey, preferences) => {
    const createImageResponse = await fetch('https://api.autoenhance.ai/v3/images/', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'x-api-key': apiKey,
        },
        body: JSON.stringify({
            image_name: 'your-image-name',
            contentType: 'image/jpeg',
            ...preferences
        }),
    });

    const { s3PutObjectUrl, order_id, image_id } = await createImageResponse.json();

    const uploadImageResponse = await fetch(s3PutObjectUrl, {
        method: 'PUT',
        headers: {
            'Content-Type': 'image/jpeg',
            'x-api-key': apiKey,
        },
        body: blob,
    });

    if (uploadImageResponse.ok) {
        console.log('Image successfully uploaded');
    } else {
        console.log('Error uploading image');
    }
};
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

api_key = 'YOUR_API_KEY'
preferences = {
    'enhance_type': 'property',
    'sky_replacement': True,
    'cloud_type': 'CLEAR',
    'vertical_correction': True,
    'auto_privacy': True,
}

def create_image(api_key, preferences, image_path):
    create_image_response = requests.post(
        'https://api.autoenhance.ai/v3/images/',
        headers={
            'Content-Type': 'application/json',
            'x-api-key': api_key,
        },
        json={
            'image_name': 'your-image-name',
            'contentType': 'image/jpeg',
            **preferences
        }
    )

    if create_image_response.status_code != 200:
        print('Error creating image')
        return

    create_image_data = create_image_response.json()
    s3_put_object_url = create_image_data['s3PutObjectUrl']
    order_id = create_image_data['order_id']
    image_id = create_image_data['image_id']

    with open(image_path, 'rb') as image_file:
        upload_image_response = requests.put(
            s3_put_object_url,
            headers={
                'Content-Type': 'image/jpeg',
                'x-api-key': api_key,
            },
            data=image_file
        )

    if upload_image_response.status_code == 200:
        print('Image successfully uploaded')
    else:
        print('Error uploading image')
```

{% endtab %}

{% tab title="PHP" %}

```php
$api_key = 'YOUR_API_KEY';
$preferences = array(
    'enhance_type' => 'property',
    'sky_replacement' => true,
    'cloud_type' => 'CLEAR',
    'vertical_correction' => true,
    'auto_privacy' => true
);

function create_image($api_key, $preferences) {
    $data = array_merge(array(
        'image_name' => 'your-image-name',
        'contentType' => 'image/jpeg'
    ), $preferences);

    $url = "https://api.autoenhance.ai/v3/images/";
    $options = array(
        'http' => array(
            'header'  => "Content-Type: application/json\r\n" .
                         "x-api-key: $api_key",
            'method'  => 'POST',
            'content' => json_encode($data),
        ),
    );
    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);

    if ($result === FALSE) {
        return 'Error creating image';
    }

    $response = json_decode($result, true);
    $s3PutObjectUrl = $response['s3PutObjectUrl'];

    $image_path = '/path/to/your/image.jpg';
    $image_data = file_get_contents($image_path);
    $upload_options = array(
        'http' => array(
            'header'  => "Content-Type: image/jpeg\r\n" .
                         "x-api-key: $api_key",
            'method'  => 'PUT',
            'content' => $image_data,
        ),
    );
    $upload_context  = stream_context_create($upload_options);
    $upload_result = file_get_contents($s3PutObjectUrl, false, $upload_context);

    if ($upload_result === FALSE) {
        return 'Error uploading image';
    }

    return 'Image successfully uploaded';
}
```

{% endtab %}

{% tab title="cURL" %}

```
Create the image

curl -X POST \
  https://api.autoenhance.ai/v3/images/ \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: YOUR_API_KEY' \
  -d '{
        "image_name": "your-image-name",
        "contentType": "image/jpeg",
        "enhance_type": "property",
        "sky_replacement": true,
        "cloud_type": "CLEAR",
        "vertical_correction": true,
        "auto_privacy": true
    }'
    
Upload the image

curl -X PUT \
  S3_PUT_OBJECT_URL \
  -H 'Content-Type: image/jpeg' \
  -H 'x-api-key: YOUR_API_KEY' \
  --data-binary @path/to/your/image.jpg
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.autoenhance.ai/images/basic-enhancements/usage-example.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
