How to Generate Videos using the sunra API

sunra offers a simple and easy-to-use API that allows you to generate videos from your prompt using pre-trained models. This endpoint is perfect for creating video clips from your prompt for various use cases such as social media, marketing, and more.

Here is an example of how to generate videos using the sunra API:

import { sunra } from "@sunra/client";

const result = await sunra.subscribe("kling/kling-v2-master/text-to-video", {
  input: {
    prompt: 'A pole bear playing violin in the snow.',
    guidance_scale: 0.5,
    aspect_ratio: '16:9',
    duration: 5
  },
  logs: true,
  onQueueUpdate: (update) => {
    console.log(update)
  },
});
console.log(result.data);
console.log(result.requestId);
import { sunra } from "@sunra/client";

const result = await sunra.subscribe("kling/kling-v2-master/image-to-video", {
  input: {
  	prompt: 'A cute hamster lies leisurely on a lifebuoy, wearing fashionable sunglasses, and drifts with the gentle waves on the shimmering sea surface. The hamster reclines comfortably, enjoying a peaceful and pleasant time. Cartoon style, the camera follows the subject moving, with a heartwarming and high picture quality.',
  	start_image: 'https://assets.sunra.ai/uploads/1748811753168-05ceab0d.png'
  },
  logs: true,
  onQueueUpdate: (update) => {
    console.log(update)
  },
});
console.log(result.data);
console.log(result.requestId);

How to select the model to use

sunra offers a variety of video generation models. You can select the model that best fits your needs based on the style and quality of the videos you want to generate. Here are some of the available models:

  • kling/kling-v2-master/text-to-video: Kling V2 Master is designed to improve prompt adherence, motion dynamics, and visual aesthetics.
  • wan/wan2.1-vace-14b/text-to-video: An all-in-one 14B model for video creation and editing, supporting tasks like text-to-video, image-to-video, and video editing with multimodal inputs and advanced control features.
  • vidu/viduq1/text-to-video: Vidu Q1 — Extreme quality with crisp visuals, cinematic transitions, precise sound, and expressive animations.
  • minimax/t2v-01-director/text-to-video: The “Camera Control” model affords users cinematic language with the fluency of a professional director and to exercise meticulous creative control.

To select a model, simply specify the model ID in the subscribe method as shown in the example above. You can find more models and their descriptions in the Image to Video Models page.