Web SDK (Beta)

In this guide we will be walking you through how to enhance your first image via the /SDK, you will:

  1. Learn how to register the fact you want to enhance an image with Autoenhance

  2. Upload your image file to Autoenhance using the SDK

  3. Downloading the final enhanced image

This guide assumes you have already have an API key, if you don't have one please see our guide here.

1. Creating our frontend

We first need to create a HTML form which will display the Autoenhance Image Uploader. Firstly we install the SDK using the script tag and provide the API key as an attribute in the HTML.

<script src="https://unpkg.com/@autoenhance.ai/web" api-key="YOUR_API_KEY_GOES_HERE"></script>

You can specify a specific version of the SDK according to the rules documented here https://unpkg.com

All we need to is add the image-uploader tag to the page and give it a name that will be used to populate the form with it's data once the user has uploaded their image.s

<image-uploader name="order_id" required></image-uploader>

Now when the page has loaded you should see automatically the Autoenhance uploader. Your code should now look something like this:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>My Application</title>
  <script src="https://unpkg.com/@autoenhance.ai/web" api-key="YOUR_API_KEY_GOES_HERE"></script>
</head>
<body>
  <h2>Upload a photo to enhance</h2>
<form>
  <image-uploader name="order_id" required></image-uploader>
 <!-- This sends the order ID as "order_id" to your server where you can carry on communicating with Autoenhnace-->
  <input type="submit"/>
</form>
</body>
</html>

2. Downloading image

Once successfully uploaded and the user submits the form, your image will start being processed with our AI. To check it's current status we can use a GET request to the /orders/:order_id:/ using the order_id passed to your backend in the form data. Once the status field returned is "processed"we can download the image using the /images/:image_id:/enhanced endpoint. If you only wish to allow your users to see a preview of the image before downloading without consuming any of your credits then you can use the /images/:image_id:/preview endpoint

const express = require('express');
const fetch = require('node-fetch');

const app = express();
app.use(express.urlencoded({ extended: true }));
app.use(express.json());

const API_KEY = "YOUR_API_KEY";
const BASE_URL = "https://api.autoenhance.ai/v3";

async function getOrder(orderId) {
  const res = await fetch(`${BASE_URL}/orders/${orderId}`, {
    method: 'GET',
    headers: { 'x-api-key': API_KEY }
  });
  if (!res.ok) throw new Error(`Failed to get order: ${res.statusText}`);
  return res.json();
}

async function downloadImage(imageId) {
  const res = await fetch(`${BASE_URL}/images/${imageId}/enhanced`, {
    method: 'GET',
    headers: { 'x-api-key': API_KEY }
  });
  if (!res.ok) throw new Error(`Failed to download image: ${res.statusText}`);
  return res.json();
}

app.post('/', async (req, res) => {
  const { order_id: orderId } = req.body;
  if (!orderId) return res.status(400).json({ error: 'Missing order_id' });

  try {
    const order = await getOrder(orderId);
    const enhancedImages = [];

    for (const img of order.images || []) {
      if (img.enhance) {
        const downloaded = await downloadImage(img.image_id);
        enhancedImages.push(downloaded);
      }
    }

    res.json({ order, enhancedImages });
  } catch (err) {
    res.status(500).json({ error: err.message });
  }
});

app.listen(3000, () => console.log('Server running on port 3000'));

If you want to read more about the options and settings for the Web SDK, follow this link

Last updated