Skip to main content
Glama

generate_image_to_video

Transform static images into animated videos using AI. Specify motion and transformation with text prompts to create dynamic visual content from pictures.

Instructions

Generate a video from an image using Kling AI

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_urlYesURL of the starting image
image_tail_urlNoURL of the ending image (optional)
promptYesText prompt describing the motion and transformation
negative_promptNoText describing what to avoid in the video (optional)
model_nameNoModel version to use (default: kling-v2-master)
durationNoVideo duration in seconds (default: 5)
modeNoVideo generation mode (default: standard)
cfg_scaleNoCreative freedom scale 0-1 (default: 0.5)

Implementation Reference

  • MCP CallToolRequest handler case for 'generate_image_to_video': validates and constructs VideoGenerationRequest from tool arguments, calls klingClient.generateImageToVideo, returns task_id response.
    case 'generate_image_to_video': {
      const videoRequest: VideoGenerationRequest = {
        prompt: args.prompt as string,
        negative_prompt: args.negative_prompt as string | undefined,
        model_name: (args.model_name as 'kling-v1' | 'kling-v1.5' | 'kling-v1.6' | 'kling-v2-master' | undefined) || 'kling-v2-master',
        duration: (args.duration as '5' | '10') || '5',
        mode: (args.mode as 'standard' | 'professional') || 'standard',
        cfg_scale: (args.cfg_scale as number) ?? 0.5,
        image_url: args.image_url as string,
        image_tail_url: args.image_tail_url as string | undefined,
      };
    
      const result = await klingClient.generateImageToVideo(videoRequest);
      
      return {
        content: [
          {
            type: 'text',
            text: `Image-to-video generation started successfully!\nTask ID: ${result.task_id}\n\nUse the check_video_status tool with this task ID to check the progress.`,
          },
        ],
      };
    }
  • src/index.ts:163-209 (registration)
    Tool registration object in TOOLS array: defines name, description, and inputSchema for generate_image_to_video, registered via server.setRequestHandler(ListToolsRequestSchema).
    {
      name: 'generate_image_to_video',
      description: 'Generate a video from an image using Kling AI',
      inputSchema: {
        type: 'object',
        properties: {
          image_url: {
            type: 'string',
            description: 'URL of the starting image',
          },
          image_tail_url: {
            type: 'string',
            description: 'URL of the ending image (optional)',
          },
          prompt: {
            type: 'string',
            description: 'Text prompt describing the motion and transformation',
          },
          negative_prompt: {
            type: 'string',
            description: 'Text describing what to avoid in the video (optional)',
          },
          model_name: {
            type: 'string',
            enum: ['kling-v1', 'kling-v1.5', 'kling-v1.6', 'kling-v2-master'],
            description: 'Model version to use (default: kling-v2-master)',
          },
          duration: {
            type: 'string',
            enum: ['5', '10'],
            description: 'Video duration in seconds (default: 5)',
          },
          mode: {
            type: 'string',
            enum: ['standard', 'professional'],
            description: 'Video generation mode (default: standard)',
          },
          cfg_scale: {
            type: 'number',
            description: 'Creative freedom scale 0-1 (default: 0.5)',
            minimum: 0,
            maximum: 1,
          },
        },
        required: ['image_url', 'prompt'],
      },
    },
  • Core implementation in KlingClient: processes image_url, constructs API request body for Kling AI /v1/videos/image2video endpoint, handles API call and error.
    async generateImageToVideo(request: VideoGenerationRequest): Promise<{ task_id: string }> {
      const path = '/v1/videos/image2video';
      
      if (!request.image_url) {
        throw new Error('image_url is required for image-to-video generation');
      }
      
      // Process the image URL
      const imageUrl = await this.processImageUrl(request.image_url);
    
      const body: any = {
        image: imageUrl, // API uses 'image' not 'image_url'
        prompt: request.prompt,
        negative_prompt: request.negative_prompt || '',
        cfg_scale: request.cfg_scale || 0.8,
        duration: request.duration || '5',
        aspect_ratio: request.aspect_ratio || '16:9',
        model_name: request.model_name || 'kling-v2-master', // V2-master is default
      };
    
      try {
        const response = await this.axiosInstance.post(path, body);
        return response.data.data;
      } catch (error) {
        if (axios.isAxiosError(error)) {
          throw new Error(`Kling API error: ${error.response?.data?.message || error.message}`);
        }
        throw error;
      }
    }

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/199-mcp/mcp-kling'

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