generateVideo(payload)
This method allows you to initiate a video generation task. It is available on both the ImagineoAIClient (for browser environments) and ServerImagineoAIClient (for Node.js server environments).
The method takes a payload object and returns a Promise that resolves with the video generation response, including the run_id for tracking the task.
Parameters
-
payload(GenerateVideoPayload): An object containing the parameters for video generation. This object must conform to theGenerateVideoPayloadSchema.Key fields in
payload:prompt(string, optional): A textual description of the desired video content.negative_prompt(string, optional): A textual description of what to avoid in the video.image_url(string, optional): URL of an initial image to base the video on. Eitherimage_urlorsource_run_idmust be provided, but not both.source_run_id(string, optional): The ID of a previous run whose output image will be used as the initial image. Eitherimage_urlorsource_run_idmust be provided, but not both.aspect_ratio(string, optional): The desired aspect ratio of the video (e.g., "16:9", "1:1", "9:16"). Defaults to "16:9".duration(number, optional): The desired duration of the video in seconds. Defaults to 3 seconds.seed(number, optional): A seed for the random number generator to ensure reproducibility.cfg_scale(number, optional): Classifier-Free Guidance scale. Controls how much the video generation should follow the prompt. Higher values mean stricter adherence.motion_bucket_id(number, optional): Controls the amount of motion in the generated video.fps(number, optional): Frames per second for the generated video.webhook_url(string, optional): A URL to which a webhook will be sent upon completion or failure of the video generation.webhook_secret(string, optional): A secret token to verify the authenticity of the webhook.
Refer to
GenerateVideoPayloadSchemaintypes.tsfor the complete and most up-to-date schema definition.
Returns
-
Promise<GenerateVideoResponse>: A Promise that resolves to an object containing details about the initiated video generation run.Key fields in
GenerateVideoResponse:run_id(string): The unique identifier for this video generation run.status(string): The initial status of the run (e.g., "queued", "processing").input(object, optional): The input parameters that were used for the generation.error(object, optional): An error object if the request failed immediately (e.g., due to validation issues).
Refer to
GenerateVideoResponseSchemaintypes.tsfor the complete schema.
Example Usage
import { ImagineoAIClient } from "@imagineoai/javascript-sdk";
// Or for server-side:
// import { ServerImagineoAIClient } from "@imagineoai/javascript-sdk/server";
const client = new ImagineoAIClient({
auth: { apiKey: "YOUR_API_KEY" },
});
async function createVideo() {
try {
const videoPayload = {
prompt: "A futuristic cityscape with flying cars",
aspect_ratio: "16:9",
duration: 5, // 5 seconds
// You can also use an image_url or source_run_id
// image_url: "https://example.com/your-image.png"
};
const response = await client.generateVideo(videoPayload);
console.log("Video generation started:", response);
console.log("Run ID:", response.run_id);
// You can use the run_id to track the status of the video generation
// using the getRunStatus method (if available and applicable).
} catch (error) {
console.error("Error generating video:", error);
}
}
createVideo();
Notes
- Ensure that either
image_urlorsource_run_idis provided in the payload, but not both. If neither or both are provided, a validation error will occur. - The actual video generation is an asynchronous process. This method initiates the task and returns a
run_idfor tracking. You might need to poll an endpoint using thisrun_idor use webhooks to determine when the video is ready.