Skip to main content
Glama

generate_video

Create videos from text prompts or existing media using AI generation, with options for duration, resolution, and aspect ratio control.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYes
modelNogrok-imagine-video
image_pathNo
image_urlNo
video_pathNo
video_urlNo
durationNo
aspect_ratioNo
resolutionNo

Implementation Reference

  • The `generate_video` function is defined as an MCP tool and handles the video generation request using the xAI SDK.
    async def generate_video(
        prompt: str,
        model: str = "grok-imagine-video",
        image_path: Optional[str] = None,
        image_url: Optional[str] = None,
        video_path: Optional[str] = None,
        video_url: Optional[str] = None,
        duration: Optional[int] = None,
        aspect_ratio: Optional[str] = None,
        resolution: Optional[str] = None
    ):
        
        client = Client(api_key=XAI_API_KEY)
        
        params = {
            "model": model,
            "prompt": prompt
        }
        
        if image_path:
            base64_string = encode_image_to_base64(image_path)
            ext = Path(image_path).suffix.lower().replace('.', '')
            params["image_url"] = f"data:image/{ext};base64,{base64_string}"
        elif image_url:
            params["image_url"] = image_url
        
        if video_path:
            base64_string = encode_video_to_base64(video_path)
            ext = Path(video_path).suffix.lower().replace('.', '')
            params["video_url"] = f"data:video/{ext};base64,{base64_string}"
        elif video_url:
            params["video_url"] = video_url
        
        if duration:
            params["duration"] = duration
        if aspect_ratio:
            params["aspect_ratio"] = aspect_ratio
        if resolution:
            params["resolution"] = resolution
    
        response = client.video.generate(**params)
        client.close()
    
        result = [f"## Generated Video\n\n**URL:** {response.url}"]
        if hasattr(response, 'duration') and response.duration:
            result.append(f"**Duration:** {response.duration}s")
        return "\n".join(result)

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/merterbak/Grok-MCP'

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