avatar-standard

This documentation is valid for the following list of our models:

  • klingai/avatar-standard

From a single image and a voice track, this model generates expressive character animations aligned with the speech’s rhythm, intonation, and meaning. This version outputs 720p video at 24 fps.

Setup your API Key

If you don’t have an API key for the AI/ML API yet, feel free to use our Quickstart guide.

How to Make a Call

Step-by-Step Instructions

Generating a video using this model involves sequentially calling two endpoints:

  • The first one is for creating and sending a video generation task to the server (returns a generation ID).

  • The second one is for requesting the generated video from the server using the generation ID received from the first endpoint.

Below, you can find both corresponding API schemas.

API Schemas

Create a video generation task and send it to the server

You can create a video with this API by providing a reference image of a character and an audio file. The character will deliver the audio with full lip-sync and natural gestures. This POST request creates and submits a video generation task to the server — and returns a generation ID.

post
Body
modelundefined · enumRequiredPossible values:
image_urlstring · uriRequired

A direct link to an online image or a Base64-encoded local image that will serve as the visual base or the first frame for the video.

audio_urlstringRequired

The URL of the audio file. Supported formats: MP3, WAV, M4A, AAC. Maximum file size: 5 MB.

promptstring · max: 2500Optional

The text description of the scene, subject, or action to generate in the video.

Responses
201Success

No content

post
/v2/video/generations
POST /v2/video/generations HTTP/1.1
Host: api.aimlapi.com
Content-Type: application/json
Accept: */*
Content-Length: 104

{
  "model": "klingai/avatar-standard",
  "image_url": "https://example.com",
  "audio_url": "text",
  "prompt": "text"
}
201Success

No content

Retrieve the generated video from the server

After sending a request for video generation, this task is added to the queue. This endpoint lets you check the status of a video generation task using its generation_id, obtained from the endpoint described above. If the video generation task status is complete, the response will include the final result — with the generated video URL and additional metadata.

get
Query parameters
generation_idstringRequired
Responses
200Success

No content

get
/v2/video/generations
GET /v2/video/generations?generation_id=text HTTP/1.1
Host: api.aimlapi.com
Accept: */*
200Success

No content

Full Example: Generating and Retrieving the Video From the Server

The code below creates a video generation task, then automatically polls the server every 10 seconds until it finally receives the video URL.

import requests
import time

# replace <YOUR_AIMLAPI_KEY> with your actual AI/ML API key
api_key = "<YOUR_AIMLAPI_KEY>"
base_url = "https://api.aimlapi.com/v2"


# Creating and sending a video generation task to the server
def generate_video():
    url = f"{base_url}/video/generations"
    headers = {
        "Authorization": f"Bearer {api_key}", 
    }

    data = {
        "model": "klingai/avatar-standard",
        "image_url": "https://cdn.aimlapi.com/assets/content/office_man.png",
        "audio_url": "https://storage.googleapis.com/falserverless/example_inputs/omnihuman_audio.mp3",
        # "prompt": "A person speaking playfully, laughing frequently and gesturing wildly."
    }
 
    response = requests.post(url, json=data, headers=headers)
    if response.status_code >= 400:
        print(f"Error: {response.status_code} - {response.text}")
    else:
        response_data = response.json()
        print(response_data)
        return response_data
    

# Requesting the result of the task from the server using the generation_id
def get_video(gen_id):
    url = f"{base_url}/video/generations"
    params = {
        "generation_id": gen_id,
    }
    
    headers = {
        "Authorization": f"Bearer {api_key}", 
        "Content-Type": "application/json"
        }

    response = requests.get(url, params=params, headers=headers)
    return response.json()


def main():
    # Running video generation and getting a task id
    gen_response = generate_video()
    gen_id = gen_response.get("id")
    print("Generation ID:  ", gen_id)

    # Trying to retrieve the video from the server every 10 sec
    if gen_id:
        start_time = time.time()

        timeout = 600
        while time.time() - start_time < timeout:
            response_data = get_video(gen_id)

            if response_data is None:
                print("Error: No response from API")
                break
        
            status = response_data.get("status")
            print("Status:", status)

            if status == "waiting" or status == "active" or  status == "queued" or status == "generating":
                print("Still waiting... Checking again in 10 seconds.")
                time.sleep(10)
            else:
                print("Processing complete:/n", response_data)
                return response_data
   
        print("Timeout reached. Stopping.")
        return None     


if __name__ == "__main__":
    main()
Response
{'id': '76a3553b-7c4f-4fe1-9682-72008ef3a0fe:klingai/avatar-standard', 'status': 'queued', 'meta': {'usage': {'tokens_used': 590100}}}
Generation ID:   76a3553b-7c4f-4fe1-9682-72008ef3a0fe:klingai/avatar-standard
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: generating
Still waiting... Checking again in 10 seconds.
Status: completed
Processing complete:/n {'id': '76a3553b-7c4f-4fe1-9682-72008ef3a0fe:klingai/avatar-standard', 'status': 'completed', 'video': {'url': 'https://cdn.aimlapi.com/flamingo/files/b/zebra/-pjJHb89XFkYTPOQjb5G2_output.mp4'}}

Generation time: ~ 4 min.

Original (1280x720, with sound):

The following video was generated by adding just one line to our example:

"prompt": "A person speaking playfully, laughing frequently and gesturing wildly."

See how dramatically the prompt parameter can change the character’s behavior and mannerisms:

"prompt": "A person speaking playfully, laughing frequently and gesturing wildly."

Last updated

Was this helpful?