Skip to main content
Glama

generate_image

Create AI-generated images from text descriptions using Kling AI models. Customize aspect ratios, exclude unwanted elements, and maintain character consistency with reference images.

Instructions

Generate images from text prompts using Kling AI. Create high-quality images with multiple aspect ratios and optional character reference support. Supports models v1, v1.5, and v2 with customizable parameters for creative control.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesText prompt describing the image to generate
negative_promptNoText describing what to avoid in the image (optional)
model_nameNoModel version to use (default: kling-v2-master)
aspect_ratioNoImage aspect ratio (default: 1:1)
num_imagesNoNumber of images to generate (default: 1)
ref_image_urlNoOptional reference image URL for character consistency
ref_image_weightNoWeight of reference image influence (0-1, default: 0.5)

Implementation Reference

  • Core handler function in KlingClient that makes the API call to Kling AI's image generation endpoint, processes reference images if provided, and handles the request/response.
    async generateImage(request: ImageGenerationRequest): Promise<{ task_id: string }> { const path = '/v1/images/generation'; // Process reference image URL if provided const ref_image_url = await this.processImageUrl(request.ref_image_url); const body: any = { prompt: request.prompt, negative_prompt: request.negative_prompt || '', aspect_ratio: request.aspect_ratio || '1:1', num_images: request.num_images || 1, ...(ref_image_url && { ref_image_url }), ...(request.ref_image_weight && { ref_image_weight: request.ref_image_weight }), }; // Always add model_name body.model_name = request.model_name || 'kling-v2-master'; 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; } }
  • MCP server tool handler for 'generate_image' that validates and maps input arguments to ImageGenerationRequest, invokes KlingClient.generateImage, and formats the response with task ID.
    case 'generate_image': { const imageRequest: ImageGenerationRequest = { 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', aspect_ratio: (args.aspect_ratio as '16:9' | '9:16' | '1:1' | '4:3' | '3:4' | '2:3' | '3:2') || '1:1', num_images: (args.num_images as number) || 1, ref_image_url: args.ref_image_url as string | undefined, ref_image_weight: (args.ref_image_weight as number) ?? 0.5, }; const result = await klingClient.generateImage(imageRequest); return { content: [ { type: 'text', text: `Image generation started successfully!\nTask ID: ${result.task_id}\n\nGenerating ${imageRequest.num_images} image(s) with aspect ratio ${imageRequest.aspect_ratio}.\nUse the check_image_status tool with this task ID to check the progress.`, }, ], }; }
  • src/index.ts:328-370 (registration)
    Tool registration in the TOOLS array, defining name, description, and detailed inputSchema for the generate_image tool.
    name: 'generate_image', description: 'Generate images from text prompts using Kling AI. Create high-quality images with multiple aspect ratios and optional character reference support. Supports models v1, v1.5, and v2 with customizable parameters for creative control.', inputSchema: { type: 'object', properties: { prompt: { type: 'string', description: 'Text prompt describing the image to generate', }, negative_prompt: { type: 'string', description: 'Text describing what to avoid in the image (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)', }, aspect_ratio: { type: 'string', enum: ['16:9', '9:16', '1:1', '4:3', '3:4', '2:3', '3:2'], description: 'Image aspect ratio (default: 1:1)', }, num_images: { type: 'number', description: 'Number of images to generate (default: 1)', minimum: 1, maximum: 4, }, ref_image_url: { type: 'string', description: 'Optional reference image URL for character consistency', }, ref_image_weight: { type: 'number', description: 'Weight of reference image influence (0-1, default: 0.5)', minimum: 0, maximum: 1, }, }, required: ['prompt'], }, },
  • TypeScript interface defining the structure of ImageGenerationRequest used by the generateImage handler.
    export interface ImageGenerationRequest { 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' | '4:3' | '3:4' | '2:3' | '3:2'; num_images?: number; ref_image_url?: string; ref_image_weight?: number; }

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