API

We currently provide an API for text-to-video and image-to-video. Copy the code segments for each function below. You need to purchase credits in advance to use the API. Text-to-Video and Image-to-Video are 200 credits each (roughly 20 cents). Depending on your volume, reach out to us at team@warpvideo.ai and we can provide significantly reduced pricing (less than 10 cents per video). To create your API key, go to the table below and create your API Key.

Text-to-Video


import os
os.environ['WARP_API_KEY'] =  "YOUR API KEY"

def generate_txt2vid(
        prompt: str, 
        aspect_ratio: str, 
        version: str = "v1"
):
    try:
        import requests
        import time

        headers = {
                'Content-Type': 'application/json',
                'x-api-key': os.environ['WARP_API_KEY']  # Replace with your actual access token
        }
        
        height = 768
        width = 768

        if aspect_ratio == "16:9":
            height = 1080
            width = 1920
        elif aspect_ratio == "9:16":
            height = 1920
            width = 1080
        
        endpoint = "https://api.flushai.cloud/web/v1/txt2img2vid"

        input_json = {
            "prompt": prompt, 
            "height": height, 
            "width": width, 
            "version": version
        }

        input_json = {k: v for k, v in input_json.items() if v is not None}
        response = requests.post(endpoint, json = input_json, headers=headers)
        response_json = response.json()
        print(response_json)
        urls = response_json['urls']
        file_paths = []
        for i, url in enumerate(urls, start=1):
            valid = False
            while not valid:
                try:
                    head_response = requests.head(url)
                    if head_response.status_code == 200:
                        file_paths.append(url)
                        valid = True
                    else:
                        time.sleep(30)
                except requests.RequestException as e:
                    print(f"An error occurred: {e}")
                    time.sleep(1)
        return file_paths
    except Exception as e:
        print(f"An error occurred: {e}")

# aspect_ratio = ['9:16', '16:9', '1:1']
# model_type = ['v1', 'v2']

prompt = "a beautiful sunset ocean waves beach view, contrasting colors in the sky"
aspect_ratio = "16:9"
version = 'v2'

urls = generate_txt2vid(prompt=prompt, aspect_ratio=aspect_ratio, version=version)
print(urls)

Image-to-Video


import os
os.environ['WARP_API_KEY'] =  "YOUR API KEY"

def generate_img2vid(
        prompt: str, 
        image1: str, 
        image2: str,
):
    try:
        import requests
        import time

        headers = {
                'Content-Type': 'application/json',
                'x-api-key': os.environ['WARP_API_KEY']  # Replace with your actual access token
        }
        
        endpoint = "https://api.flushai.cloud/web/v1/video/img2vid"

        input_json = {
            "prompt": prompt, 
            "input_image": image1, 
            "image2": image2,
            "type": "tooncrafter",
        }

        input_json = {k: v for k, v in input_json.items() if v is not None}
        response = requests.post(endpoint, json = input_json, headers=headers)
        response_json = response.json()
        print(response_json)
        urls = response_json['urls']
        file_paths = []
        for i, url in enumerate(urls, start=1):
            valid = False
            while not valid:
                try:
                    head_response = requests.head(url)
                    if head_response.status_code == 200:
                        file_paths.append(url)
                        valid = True
                    else:
                        time.sleep(30)
                except requests.RequestException as e:
                    print(f"An error occurred: {e}")
                    time.sleep(1)
        return file_paths
    except Exception as e:
        print(f"An error occurred: {e}")

prompt = "An anime scene"
image1 = "https://flush-user-images.s3.us-east-2.amazonaws.com/f1.jpeg" # requires a valid image url, place your own here
image2 = "https://flush-user-images.s3.us-east-2.amazonaws.com/f2.jpeg" # requires a valid image url, place your own here

urls = generate_img2vid(prompt=prompt, image1=image1, image2=image2)
print(urls)

API Keys

Do not share your API key with others, or expose it in the browser or other client-side code.

Key