Create Stunning Videos with the Luma Ray Cognitive Actions

22 Apr 2025
Create Stunning Videos with the Luma Ray Cognitive Actions

In today's digital landscape, the ability to generate high-quality video content from text prompts and images is a game changer for developers. The Luma Ray Cognitive Actions allow you to harness advanced video AI technology to create both realistic and fantastical scenes quickly and efficiently. With these pre-built actions, you can integrate powerful video generation capabilities into your applications, saving time and resources while enhancing user engagement.

Prerequisites

Before diving into the implementation of the Luma Ray Cognitive Actions, you should ensure that you have the following:

  • An API key for the Cognitive Actions platform.
  • Familiarity with making HTTP requests and handling JSON data in your programming language of choice.

For authentication, you'll typically pass the API key in the request headers to ensure secure access to the Cognitive Actions.

Cognitive Actions Overview

Generate Realistic and Fantastical Videos

The Generate Realistic and Fantastical Videos action utilizes Luma's Ray video AI model to create high-quality videos based on text prompts and images. This allows developers to produce visually stunning video content tailored to specific themes or narratives.

  • Category: Video Generation

Input

The input for this action requires a JSON object that includes the following fields:

  • prompt (required): A descriptive text prompt guiding the video generation.
  • loop (optional): A boolean indicating if the video should loop when played. Default is false.
  • aspectRatio (optional): Defines the video’s aspect ratio, with options like "16:9", "4:3", etc. Default is "16:9".
  • startImageUrl (optional): URL of an image to be used as the starting frame.
  • endImageUrl (optional): URL of an image to specify the ending frame of the video.
  • startVideoId (optional): ID of an existing video to extend the generated content from its end.
  • endVideoId (optional): ID of an existing video to prepend the generated content.

Example Input:

{
  "loop": false,
  "prompt": "This video shows the majestic beauty of a waterfall cascading down a cliff into a serene lake. The waterfall, with its powerful flow, is the central focus of the video. The surrounding landscape is lush and green, with trees and foliage adding to the natural beauty of the scene",
  "aspectRatio": "16:9"
}

Output

The output of this action will typically return a URL pointing to the generated video file.

Example Output:

https://assets.cognitiveactions.com/invocations/1e66e45d-afaf-42e7-a4cd-30ec4b49c1d7/68f43981-2486-4d19-adb4-fb0b7b60986e.mp4

Conceptual Usage Example (Python)

Here’s a conceptual example of how you might call the Generate Realistic and Fantastical Videos 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 = "ee9a8fb5-eb8a-4aac-8d84-d328f03cc58a" # Action ID for Generate Realistic and Fantastical Videos

# Construct the input payload based on the action's requirements
payload = {
    "loop": false,
    "prompt": "This video shows the majestic beauty of a waterfall cascading down a cliff into a serene lake. The waterfall, with its powerful flow, is the central focus of the video. The surrounding landscape is lush and green, with trees and foliage adding to the natural beauty of the scene",
    "aspectRatio": "16:9"
}

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 code snippet, replace the placeholders with your actual API key and endpoint. The action_id is set to the ID of the Generate Realistic and Fantastical Videos action. The input payload follows the schema provided, and the output is processed to display the result or any error messages.

Conclusion

The Luma Ray Cognitive Actions offer powerful tools for generating stunning videos from text prompts and images, enabling developers to create engaging content with ease. As you explore these capabilities, consider the various use cases where dynamic video generation could enhance user experiences in your applications. Start integrating Luma Ray today and unleash the potential of video AI in your projects!