letzai_create_image
Generate custom images from text prompts using AI, with adjustable dimensions, quality, creativity levels, and generation modes.
Instructions
Create an image using the LetzAI public api
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | Image prompt to generate a new image. Can also include @tag to generate an image using a model from the LetzAi Platform | |
| width | No | Width of the image should be between 520 and 2160 max pixels. Default is 1600. | |
| height | No | Height of the image should be between 520 and 2160 max pixels. Default is 1600. | |
| quality | No | Defines how many steps the generation should take. Higher is slower, but generally better quality. Min: 1, Default: 2, Max: 5 | |
| creativity | No | Defines how strictly the prompt should be respected. Higher Creativity makes the images more artificial. Lower makes it more photorealistic. Min: 1, Default: 2, Max: 5 | |
| hasWatermark | No | Defines whether to set a watermark or not. Default is true | |
| systemVersion | No | Allowed values: 2, 3. UseLetzAI V2, or V3 (newest). | |
| mode | No | Select one of the different modes that offer different generation settings. Allowed values: default, sigma, turbo. Default is slow but high quality. Sigma is faster and great for close ups. Turbo is fastest, but lower quality. | turbo |
Implementation Reference
- src/tools.ts:22-131 (handler)Main execution logic for the letzai_create_image tool. Parses arguments, calls LetzAI API to generate image, polls status with progress updates via console, opens image in browser, returns text content with URL.
if (request.params.name === "letzai_create_image") { try { let { prompt, width, height, quality, creativity, hasWatermark, systemVersion, mode, } = request.params.arguments as any; mode = !mode || !mode.includes(mode || "") ? "turbo" : mode; width = parseInt(width) || 1600; height = parseInt(height) || 1600; quality = parseInt(quality) || 2; creativity = parseInt(creativity) || 2; systemVersion = parseInt(systemVersion) || 3; hasWatermark = typeof hasWatermark === "boolean" ? hasWatermark : false; // Step 1: Create the image request const responseCreate = await axios.post( "https://api.letz.ai/images", { prompt, width, height, quality, creativity, hasWatermark, systemVersion, mode, }, { headers: { Authorization: `Bearer ${process.env.LETZAI_API_KEY}`, }, } ); let imageFinished = false; let imageVersions: { original: string; "96x96": string; "240x240": string; "640x640": string; "1920x1920": string; } | null = null; let imageId = responseCreate.data.id; // Step 2: Poll for image creation status while (!imageFinished) { await new Promise((resolve) => setTimeout(resolve, 5000)); // Wait before checking again const responseImage = await axios.get( `https://api.letz.ai/images/${imageId}`, { headers: { Authorization: `Bearer ${process.env.LETZAI_API_KEY}`, }, } ); if (responseImage.data.progress < 100) { // Send a progress notification (through stdout for Stdio transport) console.log( JSON.stringify({ jsonrpc: "2.0", method: "progress_update", params: { message: `Image is still being processed. Progress: ${responseImage.data.progress}%`, }, }) ); } else { imageFinished = true; imageVersions = responseImage.data.imageVersions; } } // Convert the image to Base64 after processing is complete /* const imageBase64 = convertImageUrlToBase64( imageVersions?.["640x640"] as string ); */ // Open the image in browser open(imageVersions?.original as string); // Return the response to the client return { content: [ { type: "text", text: `Image generated successfully!\nThe image has been opened in your default browser.\n\n Image URL: ${imageVersions?.original}\n\nYou can also click the URL above to view the image again.`, }, ], }; } catch (err: any) { return { content: [ { type: "text", text: `Error happened: ${err.toString()}`, }, ], }; } } else if (request.params.name === "letzai_upscale_image") { - src/tools/createImage.ts:5-61 (schema)Input schema and metadata for the letzai_create_image tool, defining parameters like prompt, dimensions, quality, and mode.
export const createImageTool = { name: "letzai_create_image", description: "Create an image using the LetzAI public api", inputSchema: { type: "object", properties: { prompt: { type: "string", description: "Image prompt to generate a new image. Can also include @tag to generate an image using a model from the LetzAi Platform", }, width: { type: "number", default: 1600, description: "Width of the image should be between 520 and 2160 max pixels. Default is 1600.", }, height: { type: "number", default: 1600, description: "Height of the image should be between 520 and 2160 max pixels. Default is 1600.", }, quality: { type: "number", default: 2, description: "Defines how many steps the generation should take. Higher is slower, but generally better quality. Min: 1, Default: 2, Max: 5", }, creativity: { type: "number", default: 2, description: "Defines how strictly the prompt should be respected. Higher Creativity makes the images more artificial. Lower makes it more photorealistic. Min: 1, Default: 2, Max: 5", }, hasWatermark: { type: "boolean", default: true, description: "Defines whether to set a watermark or not. Default is true", }, systemVersion: { type: "number", default: 3, description: "Allowed values: 2, 3. UseLetzAI V2, or V3 (newest).", }, mode: { type: "string", default: "turbo", enum: modes, description: "Select one of the different modes that offer different generation settings. Allowed values: default, sigma, turbo. Default is slow but high quality. Sigma is faster and great for close ups. Turbo is fastest, but lower quality.", }, }, required: ["prompt"], }, }; - src/tools.ts:13-17 (registration)Registers the letzai_create_image tool (as createImageTool) in the list of available tools returned by ListToolsRequestSchema.
server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [createImageTool, upscaleImageTool], }; }); - src/tools/createImage.ts:3-3 (helper)Helper constant defining available modes for image generation, used in schema enum and handler validation.
export const modes = ["default", "turbo", "sigma"]; - src/tools.ts:9-9 (registration)Import of the createImageTool schema and modes helper into the main tools file.
import { createImageTool, modes } from "./tools/createImage.js";