PHP code example of runapi-ai / kling

1. Go to this page and download the library: Download runapi-ai/kling 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 / kling example snippets




unApi\Kling\KlingClient;

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

$task = $client->textToVideo->create([
    'model' => 'kling-3.0',
    'prompt' => 'A cat walking through a garden',
]);

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

$result = $client->textToVideo->run([
    'model' => 'kling-3.0',
    'prompt' => 'A cinematic drone shot over a misty forest',
]);

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

$result = $client->textToVideo->run([
    'model' => 'kling-o1',
    'prompt' => 'Keep <<<image_1>>> beside the performer from <<<video_1>>>',
    'reference_image_urls' => ['https://cdn.runapi.ai/public/samples/portrait.jpg'],
    'reference_video_url' => 'https://cdn.runapi.ai/public/samples/video.mp4',
    'reference_video_type' => 'feature',
    'preserve_reference_video_audio' => true,
    'mode' => 'pro',
    'duration_seconds' => 5,
]);