PHP code example of runapi-ai / heygen-video

1. Go to this page and download the library: Download runapi-ai/heygen-video library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

runapi-ai / heygen-video example snippets




unApi\HeygenVideo\HeygenVideoClient;

$client = new HeygenVideoClient(); // reads RUNAPI_API_KEY

$imageToVideoTask = $client->imageToVideo->create([
    'model' => 'heygen-video-1',
    'duration_seconds' => 5,
    'first_frame_image_url' => 'https://cdn.runapi.ai/public/samples/image.jpg',
    'output_resolution' => '768p',
    'prompt' => 'Make it golden hour',
]);

$task = $client->textToVideo->create([
    'model' => 'heygen-video-1',
    'aspect_ratio' => 'adaptive',
    'duration_seconds' => 5,
    'output_resolution' => '768p',
    'prompt' => 'A precise product render on white marble',
    'reference_audio_urls' => ['https://cdn.runapi.ai/public/samples/voice.mp3'],
    'reference_image_urls' => ['https://cdn.runapi.ai/public/samples/image.jpg'],
    'reference_video_urls' => ['https://cdn.runapi.ai/public/samples/video.mp4'],
]);

$status = $client->textToVideo->get($task->id);

$result = $client->textToVideo->run([
    'model' => 'heygen-video-1',
    'aspect_ratio' => 'adaptive',
    'duration_seconds' => 5,
    'output_resolution' => '768p',
    'prompt' => 'A serene mountain lake at dawn',
    'reference_audio_urls' => ['https://cdn.runapi.ai/public/samples/voice.mp3'],
    'reference_image_urls' => ['https://cdn.runapi.ai/public/samples/image.jpg'],
    'reference_video_urls' => ['https://cdn.runapi.ai/public/samples/video.mp4'],
]);

echo $result->videos[0]->url . PHP_EOL;