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 Fine Tuning Enhancements.

const apiKey = 'YOUR_API_KEY';
const preferences = {
    lens_correction: true,
    brightness_boost: 'LOW',
    contrast_boost: 'MEDIUM',
    saturation_level: 'NONE',
    sharpen_level: 'MEDIUM',
    denoise_level: 'MEDIUM',
    clarity_level: 'HIGH',
};

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');
    }
};

Last updated