Create Stunning Videos from Text with Hunyuan Video Cognitive Actions

21 Apr 2025
Create Stunning Videos from Text with Hunyuan Video Cognitive Actions

In the realm of video creation, the Hunyuan Video Cognitive Actions provide a powerful toolset for developers to transform text descriptions into high-quality videos. Leveraging advanced motion consistency and visual quality, these pre-built actions simplify the video generation process, allowing you to focus on creativity rather than technical complexities.

Prerequisites

Before diving into the integration of Hunyuan Video Cognitive Actions, ensure you have an API key from the Cognitive Actions platform. This key is necessary for authentication when making requests to the API. Conceptually, you will pass this API key in the headers of your HTTP requests to ensure secure access to the action functionalities.

Cognitive Actions Overview

Generate Video From Text with HunyuanVideo

The Generate Video From Text with HunyuanVideo action enables developers to create videos based on textual prompts. This action falls under the category of video-generation and is designed to produce engaging visual content from written descriptions.

Input

The input for this action is structured as follows:

  • seed (integer, optional): A random seed for reproducibility.
  • width (integer, optional): Width of the video in pixels (default: 854).
  • height (integer, optional): Height of the video in pixels (default: 480).
  • prompt (string, required): The text prompt to generate the video.
  • flowShift (number, optional): Adjusts the flow shift in video generation (default: 7).
  • guidanceScale (number, optional): Scale for embedded guidance during video generation (default: 6).
  • inferenceSteps (integer, optional): Number of steps during the inference process (default: 50).
  • exclusionPrompt (string, optional): Defines elements to exclude from the video.
  • videoDurationInFrames (integer, optional): Length of the video in frames (default: 129).

Example Input:

{
  "width": 854,
  "height": 480,
  "prompt": "A cat walks on the grass, realistic style.",
  "flowShift": 7,
  "guidanceScale": 6,
  "inferenceSteps": 50,
  "videoDurationInFrames": 129
}

Output

Upon successful execution, this action returns a URL pointing to the generated video. An example output could look like this:

https://assets.cognitiveactions.com/invocations/3382683b-a818-4539-ac14-ba3c08393bb8/de582a8b-6dbd-45e1-849a-cecc87f49c71.mp4

Conceptual Usage Example (Python)

Here’s how a developer might call the Generate Video From Text with HunyuanVideo action using Python:

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 = "84265a73-0379-43e4-b45a-d37f26cd7304"  # Action ID for Generate Video From Text with HunyuanVideo

# Construct the input payload based on the action's requirements
payload = {
    "width": 854,
    "height": 480,
    "prompt": "A cat walks on the grass, realistic style.",
    "flowShift": 7,
    "guidanceScale": 6,
    "inferenceSteps": 50,
    "videoDurationInFrames": 129
}

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

    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 code snippet, the action_id variable holds the ID for the video generation action. The payload is constructed according to the required fields, and the request is sent to the hypothetical endpoint. The response is then processed to retrieve the generated video URL.

Conclusion

The Hunyuan Video Cognitive Actions offer an innovative approach to video generation from text, enabling developers to easily create engaging visual content. Whether for marketing, education, or entertainment, the potential applications are vast. Start integrating these actions into your projects today and unlock the power of automated video creation!