Skip to main content
Glama

generate_image_to_video

Transform static images into dynamic videos by describing desired motion and transformations. Customize video duration, style, and creative freedom using Kling AI models.

Instructions

Generate a video from an image using Kling AI

Input Schema

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

Implementation Reference

  • src/index.ts:163-209 (registration)
    Tool registration in TOOLS array, including name, description, and input schema for generate_image_to_video.
    { 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'], }, },
  • MCP tool handler in CallToolRequestSchema that validates inputs, constructs VideoGenerationRequest, calls klingClient.generateImageToVideo, and returns success message with task_id.
    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.`, }, ], }; }
  • Core implementation in KlingClient that processes image_url, makes API POST to /v1/videos/image2video, and returns task_id.
    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; } }
  • TypeScript interface defining the VideoGenerationRequest used by both generate_video and generate_image_to_video tools.
    export interface VideoGenerationRequest { prompt: string; negative_prompt?: string; model_name?: 'kling-v1' | 'kling-v1.5' | 'kling-v1.6' | 'kling-v2-master'; aspect_ratio?: '16:9' | '9:16' | '1:1'; duration?: '5' | '10'; mode?: 'standard' | 'professional'; cfg_scale?: number; image_url?: string; image_tail_url?: string; ref_image_url?: string; ref_image_weight?: number; camera_control?: CameraControl; callback_url?: string; external_task_id?: string; }
  • Helper method to process and upload local image files to a public URL if needed, used in generateImageToVideo.
    private async processImageUrl(url: string | undefined): Promise<string | undefined> { if (!url) return undefined; if (url.startsWith('file://') || !url.startsWith('http')) { try { const uploadedUrl = await uploadFromUrl(url); console.log(`Uploaded file to: ${uploadedUrl}`); return uploadedUrl; } catch (uploadError) { throw new Error(`Failed to upload file: ${uploadError instanceof Error ? uploadError.message : String(uploadError)}`); } } return url; }

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