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
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | ||
| model | No | grok-imagine-video | |
| image_path | No | ||
| image_url | No | ||
| video_path | No | ||
| video_url | No | ||
| duration | No | ||
| aspect_ratio | No | ||
| resolution | No |
Implementation Reference
- src/server.py:150-196 (handler)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)