Skip to main content
Glama

generate_video

Create videos from text descriptions or starting images using AI models. Specify prompts, duration, aspect ratio, and model parameters to generate custom video content.

Instructions

Generate videos from text prompts (text-to-video) or from images (image-to-video). Use list_models with category='video' to discover available models.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesText description for the video (e.g., 'A slow-motion drone shot of Tokyo at night')
image_urlNoStarting image URL for image-to-video models. Optional for text-to-video models.
modelNoModel ID. Use 'fal-ai/kling-video/v2/master/text-to-video' for text-only, or image-to-video models like 'fal-ai/wan-i2v'.fal-ai/wan-i2v
durationNoVideo duration in seconds
aspect_ratioNoVideo aspect ratio (e.g., '16:9', '9:16', '1:1')16:9
negative_promptNoWhat to avoid in the video (e.g., 'blur, distort, low quality')
cfg_scaleNoClassifier-free guidance scale (0.0-1.0). Lower values give more creative results.

Implementation Reference

  • The core handler function for the 'generate_video' tool. It resolves the model ID, constructs parameters for the Fal.ai model, executes the generation using the queue strategy with timeout handling, and returns the generated video URL or an error message.
    async def handle_generate_video(
        arguments: Dict[str, Any],
        registry: ModelRegistry,
        queue_strategy: QueueStrategy,
    ) -> List[TextContent]:
        """Handle the generate_video tool."""
        model_input = arguments.get("model", "fal-ai/wan-i2v")
        try:
            model_id = await registry.resolve_model_id(model_input)
        except ValueError as e:
            return [
                TextContent(
                    type="text",
                    text=f"❌ {e}. Use list_models to see available options.",
                )
            ]
    
        fal_args: Dict[str, Any] = {
            "prompt": arguments["prompt"],
        }
        # image_url is optional - only needed for image-to-video models
        if "image_url" in arguments:
            fal_args["image_url"] = arguments["image_url"]
        if "duration" in arguments:
            fal_args["duration"] = arguments["duration"]
        if "aspect_ratio" in arguments:
            fal_args["aspect_ratio"] = arguments["aspect_ratio"]
        if "negative_prompt" in arguments:
            fal_args["negative_prompt"] = arguments["negative_prompt"]
        if "cfg_scale" in arguments:
            fal_args["cfg_scale"] = arguments["cfg_scale"]
    
        # Use queue strategy with timeout protection for long-running video generation
        logger.info("Starting video generation with %s", model_id)
        try:
            video_result = await asyncio.wait_for(
                queue_strategy.execute(model_id, fal_args, timeout=180),
                timeout=185,  # Slightly longer than internal timeout
            )
        except asyncio.TimeoutError:
            return [
                TextContent(
                    type="text",
                    text=f"❌ Video generation timed out after 180 seconds with {model_id}",
                )
            ]
    
        if video_result is None:
            return [
                TextContent(
                    type="text",
                    text=f"❌ Video generation failed or timed out with {model_id}",
                )
            ]
    
        # Check for error in response
        if "error" in video_result:
            error_msg = video_result.get("error", "Unknown error")
            return [
                TextContent(
                    type="text",
                    text=f"❌ Video generation failed: {error_msg}",
                )
            ]
    
        # Extract video URL from result
        video_dict = video_result.get("video", {})
        if isinstance(video_dict, dict):
            video_url = video_dict.get("url")
        else:
            video_url = video_result.get("url")
    
        if video_url:
            return [
                TextContent(
                    type="text",
                    text=f"🎬 Video generated with {model_id}: {video_url}",
                )
            ]
    
        return [
            TextContent(
                type="text",
                text="❌ Video generation completed but no video URL was returned. Please try again.",
            )
        ]
  • The input schema and Tool definition for 'generate_video', defining parameters like prompt, optional image_url, model, duration, etc., with validation rules.
    Tool(
        name="generate_video",
        description="Generate videos from text prompts (text-to-video) or from images (image-to-video). Use list_models with category='video' to discover available models.",
        inputSchema={
            "type": "object",
            "properties": {
                "prompt": {
                    "type": "string",
                    "description": "Text description for the video (e.g., 'A slow-motion drone shot of Tokyo at night')",
                },
                "image_url": {
                    "type": "string",
                    "description": "Starting image URL for image-to-video models. Optional for text-to-video models.",
                },
                "model": {
                    "type": "string",
                    "default": "fal-ai/wan-i2v",
                    "description": "Model ID. Use 'fal-ai/kling-video/v2/master/text-to-video' for text-only, or image-to-video models like 'fal-ai/wan-i2v'.",
                },
                "duration": {
                    "type": "integer",
                    "default": 5,
                    "minimum": 2,
                    "maximum": 10,
                    "description": "Video duration in seconds",
                },
                "aspect_ratio": {
                    "type": "string",
                    "default": "16:9",
                    "description": "Video aspect ratio (e.g., '16:9', '9:16', '1:1')",
                },
                "negative_prompt": {
                    "type": "string",
                    "description": "What to avoid in the video (e.g., 'blur, distort, low quality')",
                },
                "cfg_scale": {
                    "type": "number",
                    "default": 0.5,
                    "description": "Classifier-free guidance scale (0.0-1.0). Lower values give more creative results.",
                },
            },
            "required": ["prompt"],
        },
    ),
  • Registration of the 'generate_video' handler in the TOOL_HANDLERS dictionary used by the MCP server to route tool calls to the appropriate handler function.
    TOOL_HANDLERS = {
        # Utility tools (no queue needed)
        "list_models": handle_list_models,
        "recommend_model": handle_recommend_model,
        "get_pricing": handle_get_pricing,
        "get_usage": handle_get_usage,
        "upload_file": handle_upload_file,
        # Image generation tools
        "generate_image": handle_generate_image,
        "generate_image_structured": handle_generate_image_structured,
        "generate_image_from_image": handle_generate_image_from_image,
        # Image editing tools
        "remove_background": handle_remove_background,
        "upscale_image": handle_upscale_image,
        "edit_image": handle_edit_image,
        "inpaint_image": handle_inpaint_image,
        "resize_image": handle_resize_image,
        "compose_images": handle_compose_images,
        # Video tools
        "generate_video": handle_generate_video,
        "generate_video_from_image": handle_generate_video_from_image,
        "generate_video_from_video": handle_generate_video_from_video,
        # Audio tools
        "generate_music": handle_generate_music,
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. While it mentions the need to discover models via list_models, it lacks critical details such as whether this is a read-only or destructive operation, potential rate limits, authentication requirements, or what the output format looks like (e.g., video URL, file). This leaves significant gaps for an AI agent to understand the tool's behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, with two concise sentences that directly state the tool's purpose and usage guidance. Every sentence earns its place without redundancy, making it efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a video generation tool with 7 parameters, no annotations, and no output schema, the description is incomplete. It fails to address key behavioral aspects (e.g., mutation effects, output format) and does not compensate for the lack of structured data, leaving the AI agent with insufficient context for safe and effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds minimal value beyond the schema by hinting at model discovery but does not provide additional semantic context for parameters like prompt or image_url. Baseline score of 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('generate videos') and resources ('from text prompts' and 'from images'), distinguishing it from sibling tools like generate_image or generate_music by specifying video generation. It explicitly mentions both text-to-video and image-to-video capabilities.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context on when to use this tool (for video generation from text or images) and references an alternative tool (list_models) for discovering available models. However, it does not explicitly state when NOT to use it or compare it to similar siblings like generate_video_from_image, which might cause ambiguity.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/raveenb/fal-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server