Skip to content

Text to Video

Shows how to submit a text-to-video generation task with Vidu and poll for the result.

This example assumes using Vidu; is in scope and apiKey contains your Vidu API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
using var client = new ViduClient(apiKey);

// Submit a text-to-video generation task with viduq3-turbo at 720p.
var task = await client.Generation.CreateTextToVideoTaskAsync(
    model: Model.Viduq3Turbo,
    prompt: "A golden retriever running through a sunlit meadow in cinematic slow motion",
    duration: 5,
    aspectRatio: AspectRatio.x16_9,
    resolution: Resolution.x720p);

Console.WriteLine($"Task ID: {task.TaskId}");
Console.WriteLine($"State: {task.State}");

// Poll the task until it reaches a terminal state (success/failed).
var creations = await client.Tasks.GetTaskCreationsAsync(id: task.TaskId!);
Console.WriteLine($"Creations state: {creations.State}");

// When the task succeeds, the result contains one or more creation URLs valid for 24 hours.
if (creations.State == TaskState.Success && creations.Creations is { Count: > 0 })
{
    Console.WriteLine($"Video URL: {creations.Creations[0].Url}");
}