Create Engaging Videos Easily with wan-video/wan-2.1-1.3b Cognitive Actions

22 Apr 2025
Create Engaging Videos Easily with wan-video/wan-2.1-1.3b Cognitive Actions

In today's digital landscape, the ability to generate captivating video content is essential for many applications, from marketing to entertainment. The wan-video/wan-2.1-1.3b API offers a robust Cognitive Action that allows developers to leverage advanced visual generation models by Tongyi Lab of Alibaba Group. With the action to generate short videos, developers can automate video creation based on text prompts, ensuring high performance and quality output.

Prerequisites

Before you start integrating the Cognitive Actions into your application, make sure you have the following:

  • API Key: You will need an API key to authenticate your requests to the Cognitive Actions platform.
  • Setup: Ensure you have a working HTTP client (like requests in Python) for making API calls.

Authentication typically involves passing your API key in the headers of your requests.

Cognitive Actions Overview

Generate Short Video with Wan

The Generate Short Video with Wan action is designed to create 5-second videos at a resolution of 480p. This action supports various tasks including Text-to-Video conversion, allowing developers to specify the content through descriptive prompts.

Input

The input for this action requires the following fields:

  • prompt (required): A string that describes the desired content or scenario for the video generation.
    Example: "a dog is riding on a skateboard down a hill"
  • resolution (optional): Specifies the video resolution. Default is "480p".
  • aspectRatio (optional): Defines the video aspect ratio (default is "16:9").
  • frameNumber (optional): Specifies the video duration in frames (default is 81 frames).
  • sampleShift (optional): A factor for shifting sample flow matching, recommended to be between 8 and 12 (default is 8).
  • sampleSteps (optional): Specifies the number of sampling steps (default is 30).
  • sampleGuideScale (optional): The scale for classifier-free guidance (default is 6).

Here's an example of the input JSON payload:

{
  "prompt": "a dog is riding on a skateboard down a hill",
  "resolution": "480p",
  "aspectRatio": "16:9",
  "frameNumber": 81,
  "sampleShift": 8,
  "sampleSteps": 30,
  "sampleGuideScale": 6
}

Output

Upon successful execution, the action returns a URL link to the generated video. This link can be used to access the video directly.

Example Output:
https://assets.cognitiveactions.com/invocations/ec575959-226b-419c-8fc1-d9e6b87dfafc/8ab86845-938b-4058-b39d-f79af598c3e2.mp4

Conceptual Usage Example (Python)

Here's a conceptual Python code snippet demonstrating how to invoke the Generate Short Video with Wan action:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "76daa04d-8938-4be8-8aa1-e692ee5826bd" # Action ID for Generate Short Video with Wan

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "a dog is riding on a skateboard down a hill",
    "resolution": "480p",
    "aspectRatio": "16:9",
    "frameNumber": 81,
    "sampleShift": 8,
    "sampleSteps": 30,
    "sampleGuideScale": 6
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload} # Hypothetical structure
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this snippet, be sure to replace the placeholder API key with your actual key and adjust the endpoint as necessary. The action_id is set to the ID for generating a short video, and the payload is structured according to the action's requirements.

Conclusion

The wan-video/wan-2.1-1.3b Cognitive Actions provide a powerful tool for developers looking to integrate video generation capabilities into their applications. By simply providing a text prompt, you can create engaging video content efficiently. Explore use cases like automated content creation, marketing videos, or even educational materials by leveraging this action. Happy coding!