Image API Quickstart

In this example, we’ll be using one of our most popular image models, Standard 2.

Before we proceed, you need to create an API keyarrow-up-right.

This key will be used to authenticate your requests to the Topaz Labs API.

chevron-rightHow do I get my API key?hashtag

In order to get access to the API, you'll need to log intoarrow-up-right your Topaz Labs account and create your unique API key. If you don't have an account, please follow the link herearrow-up-right to register.

  1. Log into your Topaz Labs account from our websitearrow-up-right

  2. Navigate to the API Keys section in your account portal, enter a name, and click Create

  3. Copy your API key (displayed at the top of the screen) and store it in a safe place

circle-exclamation

Now, proceed with the below steps.

npm install form-data
export TOPAZ_API_KEY="PASTE_YOUR_API_KEY_HERE"

Now you can call our Enhance endpointarrow-up-right using the Topaz Labs client:

import fs from 'fs';
import FormData from 'form-data';

const API_KEY = process.env.TOPAZ_API_KEY;
const HEADERS = { 'X-API-KEY': API_KEY };
const IMAGE_BASE = 'https://api.topazlabs.com/image/v1';

// Submit the job
const form = new FormData();
form.append('model', 'Standard V2');
form.append('output_format', 'jpeg');
form.append('image', fs.createReadStream('photo.jpg'));

const response = await fetch(`${IMAGE_BASE}/enhance/async`, {
  method: 'POST',
  headers: { ...HEADERS, ...form.getHeaders() },
  body: form,
});
const { process_id } = await response.json();

// Poll for completion
let status;
do {
  await new Promise(resolve => setTimeout(resolve, 2000));
  const statusRes = await fetch(`${IMAGE_BASE}/status/${process_id}`, {
    headers: HEADERS,
  });
  ({ status } = await statusRes.json());
  console.log(`Status: ${status}`);
  if (status === 'Failed' || status === 'Cancelled') {
    throw new Error(`Job ended with status: ${status}`);
  }
} while (status !== 'Completed');

// Download the result
const downloadRes = await fetch(`${IMAGE_BASE}/download/${process_id}`, {
  headers: HEADERS,
});
const { url } = await downloadRes.json();
console.log(`Download your image: ${url}`);

We have now made more popular image models such as Wonder 2, Bloom Creative, and Recover 3 more available as ready-to-use APIs so that you can easily integrate them into your applications.

Once you find a model that you want to use in our "Models" tab, you can grab the URL from the model's dedicated page. Individual model pages also provide some important information about the model including use cases and examples of how you can call it.

Check out our API Playgroundarrow-up-right to tinker with these models and let us know your feedback and questions on our Discordarrow-up-right.

chevron-rightHow do I make an API call from the API Playground?hashtag

It's now easier more than ever to create and send your first API request. Once you have a Topaz Labs account and you have created your first API key, navigate over to our API Playgroundarrow-up-right to better understand how to build requests. Please see the walkthrough above for an example of an image being upscaled with our Enhance Synchronous endpoint on the Image API.

More Information

chevron-rightAPI Restrictionshashtag
  • The API has access rate limits depending on the current load on the servers. If you receive a HTTP 429 response, please try again (soon). We recommend using an exponential backoff for the requests to avoid immediately hitting the limit again.

  • The API only responds to HTTPS-secured communications. Any requests sent via HTTP return an HTTP 301 redirect to the corresponding HTTPS resources.

  • The API enforces a request size limit of 500MB. If a request exceeds this limit, the server responds with an HTTP 413. Please ensure that requests stay within the size constraint to avoid this error.

Please reach out to [email protected]envelope with any questions.

Last updated