Image-Upscaling.net API Documentation

This page describes how to interact with the Image Upscaling, Background Removal, Text-to-Speech, and Flux Style APIs. The following Python code samples demonstrate how to use these endpoints.

You can copy this code right into your program and test it out (but change the client id). The daily free quota applies to all requests. You can run this code as a notebook here.

Your client id is your secret identifier. Use a random client id to avoid collisions with other users!

1. Setup

First we need a sample image. I highly recommend you use your own sample image because many people submitting the byte-perfect same image could be seen as suspicious and could lead to a ban of your ip.
!wget https://image-upscaling.net/assets/images/test_image.jpg

The client id always should be included in the headers. This is how you identify yourself. You have to use 32 digits, allowed are: 0-9, a-z, A-Z.
Only when downloading results you can also specify the client id as get parameter (?client_id=76..42)
import requests
import json

serverurl = "https://image-upscaling.net"
client_id = "1234567890asdfghjklqwertzUIOPYXC"
cookies = { "client_id": client_id }

2. Upscaling API

Upload an image

You specify the target scale (1,2,3,4) and whether you want to use the face repair mode or not. Face repair is slower and costs a little more, so only use it if you need it.
use_face_enhance = False
scale = 4
path = "test_image.jpg"

url = "/".join([serverurl, "upscaling_upload"])
data = {"scale": scale}
if use_face_enhance:
    data["fx"] = ""

files = {"image": open(path, "rb")}
response = requests.post(url, data=data, files=files, cookies=cookies)
print(response.text)

Get status

All 3 APIs have an endpoint to query the processing status. They will provide you with the download urls.
url = "/".join([serverurl, "upscaling_get_status"])
response = requests.get(url, cookies=cookies)
print(response.json())

Download processed files

A good way to download all your result files is to query the processing status and download all images that are marked as processed.
When using ?delete_after_download the server will automatically delete your file after you downloaded it. You can repeat this until there are no more files left.
while True:
    url = "/".join([serverurl, "upscaling_get_status"])
    response = requests.get(url, cookies=cookies).json()

    for url in response["processed"]:
        filename = url.split("/")[-1]
        params = {"delete_after_download": ""}
        content = requests.get(url, cookies=cookies, params=params).content
        with open(filename, "wb") as f:
            f.write(content)

    if not response["pending"] and not response["processing"] and not response["processed"]:
        break
    else:
        import time
        time.sleep(1)

3. Background Removal API

This API is almost the same as the upscaling API, it just has different endpoints and no extra data when uploading a file.

Upload an image

url = "/".join([serverurl, "removebg_upload"])
files = {"image": open("test_image.jpg", "rb")}
response = requests.post(url, files=files, cookies=cookies)
print(response.text)

Download results

while True:
    url = "/".join([serverurl, "removebg_get_status"])
    response = requests.get(url, cookies=cookies).json()

    for url in response["processed"]:
        filename = url.split("/")[-1]
        params = {"delete_after_download": ""}
        content = requests.get(url, cookies=cookies, params=params).content
        with open(filename, "wb") as f:
            f.write(content)

    if not response["pending"] and not response["processing"] and not response["processed"]:
        break
    else:
        import time
        time.sleep(1)

4. Text-to-Speech API

Submit text

You need to specify:
url = "/".join([serverurl, "tts_submit"])
data = {
    "text": "This is the text to speech api",
    "voice": "am_michael",
    "speed": 1.1
}
response = requests.post(url, json=data, cookies=cookies)
print(response.text)

Download results

This endpoint returns a list of your requests with a download link for the mp3 files. Your file is ready when "result" is not empty.
while True:
    url = "/".join([serverurl, "tts_get_data"])
    response = requests.get(url, cookies=cookies).json()

    for element in response:
        url = element["result"]
        if url != "":
            print(url)
            params = {"delete_after_download": ""}
            content = requests.get(url, params=params, cookies=cookies).content
            with open(url.split("/")[-1] + ".mp3", "wb") as f:
                f.write(content)

    if not response:
        break
    else:
        import time
        time.sleep(1)

5. Flux Style API

The Flux Editor API allows you to apply various styles to images. The process is divided into two main parts: first you generate or upload an image, then you submit a job to process the selected image.

Upload an image for processing

Upload an image that will be automatically selected for processing.

path = "test_image.jpg"
url = "/".join([serverurl, "iedit_upload"])
files = {"image": open(path, "rb")}
response = requests.post(url, files=files, cookies=cookies)
print(response.text)
# Output: image uploaded

Get status and check selected image

Check the status of your images and see which one is currently selected. The uploaded image will be selected automatically.

url = "/".join([serverurl, "iedit_get_status"])
response = requests.get(url, cookies=cookies).json()
print(response)
# Output example:
# {'entries': [{'req_id': 1755256007178,
#    'result': 'http://image-upscaling.net/iedit_download_data/1755256007178',
#    'status': 0,
#    'text': ''}],
#  'selected': 1755256007178}

Change selected image (optional)

To change which image is selected for processing, use the following endpoint. You can provide a request ID or -1 to clear the canvas.

req_id = "1755256007178"  # or -1 to clear canvas
url = "/".join([serverurl, "iedit_set_selected"])
params = {"req_id": req_id}
response = requests.get(url, params=params, cookies=cookies)
print(response.text)

Submit a style processing job

Submit a job to apply a style to the currently selected image.

url = "/".join([serverurl, "iedit_submit_job"])
data = {
    "model": "style",           # select style model
    "selectedStyle": "Oil_Painting"  # select the desired style
}
request_id = requests.post(url, data=data, cookies=cookies).text
print(request_id)
# Output example: 1755256008533

Monitor processing status

Check if your style processing job is complete. Status 0 means processed, status 1 means still processing.

url = "/".join([serverurl, "iedit_get_status"])
data = requests.get(url, cookies=cookies).json()
entries = data['entries']

for entry in entries:
    if entry['req_id'] == int(request_id):
        print(entry)
        if entry['status'] == 0:
            print("the image is processed")
        else:
            print("the image is processing")
# Output example:
# {'req_id': 1755256008533, 'result': 'http://image-upscaling.net/iedit_download_data/1755256008533?get_input_image=True', 'status': 1, 'text': 'Turn this image into the Oil Painting style.'}
# the image is processing

Wait for processing and download result

A helper function to wait for processing to complete and download the result.

import time

def wait_and_download(request_id, filename):
    while True:
        url = "/".join([serverurl, "iedit_get_status"])
        data = requests.get(url, cookies=cookies).json()
        entries = data['entries']

        for entry in entries:
            if entry['req_id'] == int(request_id):
                if entry['status'] == 0:
                    print("the image is processed")
                    url = entry['result']
                    response = requests.get(url, cookies=cookies)
                    with open(filename, "wb") as f:
                        f.write(response.content)
                    return
        time.sleep(1)

# Usage example
filename = "test_image_processed.jpg"
wait_and_download(request_id, filename)
# Output: the image is processed

Display the processed image (optional)

If you're using this in a Jupyter notebook, you can display the result:

import matplotlib.pyplot as plt
import matplotlib.image as mpimg

img = mpimg.imread(filename)
imgplot = plt.imshow(img)
plt.show()

6. Account info

Use this endpoint to get information on your account.
url = "/".join([serverurl, "get_account_info"])
response = requests.get(url, cookies=cookies).json()
print(response)
# {'balance': 361.1489, 'client_id': 'af25d8e9971a747bf55c17195f39757a', 'email': 'marvineckhardt04092003@gmail.com', 'has_free_quota_left': False, 'ip': '35.221.153.79', 'quota_free': 0.2, 'quota_used': 0.3765}
  

7. Bonus: change client id in browser

If you want to change client id in browser, you can use
/account?client_id=xxxxx
with a valid client id and it will make the browser switch to the given client id.
The image-upscaling.net app uses this feature.
© 2024 image-upscaling.net
marvineckhardt04092003@gmail.com
Twitter social icon
Impressum
Marvin Eckhardt
Hinter dem kleinen Dorfe 170
38822 Aspenstedt
Germany