> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sunra.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Image to Video

### 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 images using pre-trained models. This endpoint is perfect for creating video clips from your images for various use cases such as social media, marketing, and more.

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

<CodeGroup>
  ```javascript Javascript theme={null}
  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.',
      negative_prompt: '',
      guidance_scale: 0.5,
      aspect_ratio: '16:9',
      duration: 5,
      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);
  ```

  ```python Python theme={null}
  import sunra_client

  result = sunra_client.subscribe(
      "kling/kling-v2-master/image-to-video",
      arguments={
          "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.",
          "guidance_scale": 0.5,
          "aspect_ratio": "16:9",
          "duration": 5,
          "start_image": "https://assets.sunra.ai/uploads/1748811753168-05ceab0d.png"
      },
      with_logs=True,
      on_enqueue=print,
      on_queue_update=print,
  )
  print(result)
  ```

  ```java Java theme={null}
  import ai.sunra.client.*;
  import ai.sunra.client.queue.*;
  import java.util.Map;
  import com.google.gson.JsonObject;
  import java.util.function.Consumer;

  ClientConfig config = ClientConfig.builder()
      .withCredentials(CredentialsResolver.fromEnv())
      .build();

  SunraClient client = SunraClient.withConfig(config);
  Map<String, Object> input = Map.of(
      "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.",
      "guidance_scale", 0.5,
      "aspect_ratio", "16:9",
      "duration", 5,
      "start_image", "https://assets.sunra.ai/uploads/1748811753168-05ceab0d.png"
  );

  Consumer<QueueStatus.StatusUpdate> statusUpdateHandler = update -> {
      String status = update.getStatus().toString();
      String message = String.format("\nStatus Update: %s, Request ID: %s",
          status, update.getRequestId());
      System.out.println(message);
  };

  SubscribeOptions<JsonObject> options = SubscribeOptions.<JsonObject>builder()
      .input(input)
      .resultType(JsonObject.class)
      .onQueueUpdate(statusUpdateHandler)
      .logs(true)
      .build();

  Output<JsonObject> response = client.subscribe("kling/kling-v2-master/image-to-video", options);
  System.out.println("Completed!");
  System.out.println(response.getData());
  ```

  ```bash Curl theme={null}
  curl --request POST \
    --url https://api.sunra.ai/v1/queue/kling/kling-v2-master/image-to-video \
    --header "Authorization: Key $SUNRA_KEY" \
    --header "Content-Type: application/json" \
    --data '{"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.","negative_prompt":"","guidance_scale":0.5,"aspect_ratio":"16:9","duration":5,"start_image":"https://assets.sunra.ai/uploads/1748811753168-05ceab0d.png"}'
  ```
</CodeGroup>

### 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/image-to-video](https://sunra.ai/models/kling/kling-v2-master/image-to-video): Kling V2 Master is designed to improve prompt adherence, motion dynamics, and visual aesthetics.
* [minimax/i2v-01/image-to-video](https://sunra.ai/models/sunra-ai/minimax-video/image-to-video): Generates 6-second HD videos from images and text prompts

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](https://sunra.ai/models?modalities%5B0%5D=modality-image-video) page.
