🤖API reference

Below is an example Python function, that first submits your prompt, waits for the result and returns an animation file (binary .fbx or plaint text .bvh):

import requests
import time

# get it from https://animatric.ai/api-keys 
# it can look like this: 6989d2ca-df0c-4747-9c4c-57691b03bbcd
APIKEY = "your API Key goes here"


def download_anim(prompt: str, filetype: str, skeleton: str) -> bytes:
    assert filetype in ["fbx", "bvh"]
    assert skeleton in ["UE4", "UE5", "Unity", "iClone", "Mixamo", "Vicon"]

    # send prompt to server
    res1 = requests.post(
        "https://staging.animatric.ai/api/external/prompts",
        headers={
            "accept": "application/json",
            "X-API-Key": APIKEY,
            "Content-Type": "application/json",
        },
        json={"prompt": prompt},
    )

    # assert status code is 200
    try:
        res1.raise_for_status()
    except Exception as e:
        print(e)
        return

    # url to download the animation
    url = res1.json()["url"]

    # increase the number of max_retries if the server is slow
    max_retries = 5  
    
    for i in range(max_retries):
        # query the server for the animation
        res2 = requests.get(
            url + f"?format={filetype}&skeleton={skeleton}",
            headers={
                "accept": "application/octet-stream",
                "X-API-Key": APIKEY,
            },
        )

        
        if res2.status_code == 500:
            # if the animation is not ready, wait for 3 seconds and try again
            if "Finished prompt not found" in res2.json()["message"]:
                time.sleep(3)
                continue
            # Text to motion failed due to bad prompt or random failure
            elif "Prompt failed" in in res2.json()["message"]:
                raise Exception(f"Animation generation failed. Try once again or choose another prompt.")
            
            
        # assert status code is 200
        res2.raise_for_status()
        
        # return animation in bytes (even for the bvh format)
        return res2.content
    
    # throw an error after exceeding max retries
    raise Exception(f"Failed to download the animation after {max_retries} retries...")

Here's how you invoke this function:

anim = download_anim(prompt="run forward", filetype="bvh", skeleton="Vicon")

You can then save this animation to a file:

with open("run_forward.bvh", "wb") as f:
    f.write(anim)

or in case of .bvh you can convert it to a string like so:

anim_str = anim.decode("utf-8")

Last updated