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 requestsimport time# get it from https://animatric.ai/api-keys # it can look like this: 6989d2ca-df0c-4747-9c4c-57691b03bbcdAPIKEY ="your API Key goes here"defdownload_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 200try: res1.raise_for_status()exceptExceptionas 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 =5for i inrange(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 againif"Finished prompt not found"in res2.json()["message"]: time.sleep(3)continue# Text to motion failed due to bad prompt or random failureelif"Prompt failed"inin res2.json()["message"]:raiseException(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 retriesraiseException(f"Failed to download the animation after {max_retries} retries...")