Skip to main content
Glama

generate_image

Create images from text prompts with customizable styles, variations, and output formats for visual content generation.

Instructions

Generate single or multiple images from text prompts with style and variation options

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesThe text prompt describing the image to generate
outputCountNoNumber of variations to generate (1-8, default: 1)
stylesNoArray of artistic styles: photorealistic, watercolor, oil-painting, sketch, pixel-art, anime, vintage, modern, abstract, minimalist
variationsNoArray of variation types: lighting, angle, color-palette, composition, mood, season, time-of-day
formatNoOutput format: separate files or single grid imageseparate
seedNoSeed for reproducible variations
previewNoAutomatically open generated images in default viewer

Implementation Reference

  • Tool schema definition including input parameters for generate_image tool (prompt, outputCount, styles, variations, etc.) used in ListTools response.
    {
      name: "generate_image",
      description:
        "Generate single or multiple images from text prompts with style and variation options",
      inputSchema: {
        type: "object",
        properties: {
          prompt: {
            type: "string",
            description: "The text prompt describing the image to generate",
          },
          outputCount: {
            type: "number",
            description:
              "Number of variations to generate (1-8, default: 1)",
            minimum: 1,
            maximum: 8,
            default: 1,
          },
          styles: {
            type: "array",
            items: { type: "string" },
            description:
              "Array of artistic styles: photorealistic, watercolor, oil-painting, sketch, pixel-art, anime, vintage, modern, abstract, minimalist",
          },
          variations: {
            type: "array",
            items: { type: "string" },
            description:
              "Array of variation types: lighting, angle, color-palette, composition, mood, season, time-of-day",
          },
          format: {
            type: "string",
            enum: ["grid", "separate"],
            description:
              "Output format: separate files or single grid image",
            default: "separate",
          },
          seed: {
            type: "number",
            description: "Seed for reproducible variations",
          },
          preview: {
            type: "boolean",
            description:
              "Automatically open generated images in default viewer",
            default: false,
          },
        },
        required: ["prompt"],
      },
    },
  • MCP CallToolRequest handler case for 'generate_image': parses arguments, builds ImageGenerationRequest, and delegates execution to ImageGenerator.generateTextToImage().
    case "generate_image": {
      const imageRequest: ImageGenerationRequest = {
        prompt: args?.prompt as string,
        outputCount: (args?.outputCount as number) || 1,
        mode: "generate",
        styles: args?.styles as string[],
        variations: args?.variations as string[],
        format: (args?.format as "grid" | "separate") || "separate",
        seed: args?.seed as number,
        preview: args?.preview as boolean,
        fileFormat: (args?.fileFormat as "png" | "jpeg") || "png",
        noPreview:
          (args?.noPreview as boolean) ||
          (args?.["no-preview"] as boolean),
      };
      response =
        await this.imageGenerator.generateTextToImage(imageRequest);
      break;
    }
  • Core handler function implementing generate_image tool logic: builds batch prompts, calls OpenRouter API via postJson, parses base64 image data, saves files using FileHandler, handles multiple variations, previews, and returns generated files list.
    async generateTextToImage(
      request: ImageGenerationRequest
    ): Promise<ImageGenerationResponse> {
      try {
        const outputPath = FileHandler.ensureOutputDirectory();
        const generatedFiles: string[] = [];
        const prompts = this.buildBatchPrompts(request);
        let firstError: string | null = null;
        const fileFormat = this.resolveFileFormat(request);
    
        logger.debug(`Generating ${prompts.length} image variation(s)`);
    
        for (let i = 0; i < prompts.length; i++) {
          const currentPrompt = prompts[i];
          logger.debug(
            `Generating variation ${i + 1}/${prompts.length}:`,
            currentPrompt
          );
    
          try {
            const payload: Record<string, unknown> = {
              model: this.modelName,
              input: [
                {
                  role: "user",
                  content: [
                    {
                      type: "input_text",
                      text: currentPrompt,
                    },
                  ],
                },
              ],
            };
    
            if (request.seed !== undefined) {
              payload.seed = request.seed;
            }
    
            const response = await this.postJson<OpenRouterImageResponse>(
              this.generationPath,
              payload
            );
    
            const imageBase64 = this.parseImageFromResponse(response);
    
            if (imageBase64) {
              const filename = FileHandler.generateFilename(
                request.styles || request.variations
                  ? currentPrompt
                  : request.prompt,
                fileFormat,
                i
              );
              const fullPath = await FileHandler.saveImageFromBase64(
                imageBase64,
                outputPath,
                filename
              );
              generatedFiles.push(fullPath);
              logger.debug("Image saved to:", fullPath);
            } else {
              logger.warn("No valid image data found in OpenRouter response");
            }
          } catch (error: unknown) {
            const errorMessage = this.handleApiError(error);
            if (!firstError) {
              firstError = errorMessage;
            }
            logger.warn(`Error generating variation ${i + 1}:`, errorMessage);
    
            if (errorMessage.toLowerCase().includes("authentication failed")) {
              return {
                success: false,
                message: "Image generation failed",
                error: errorMessage,
              };
            }
          }
        }
    
        if (generatedFiles.length === 0) {
          return {
            success: false,
            message: "Failed to generate any images",
            error:
              firstError ||
              "No image data returned from OpenRouter. Try adjusting your prompt.",
          };
        }
    
        await this.handlePreview(generatedFiles, request);
    
        return {
          success: true,
          message: `Successfully generated ${generatedFiles.length} image variation(s)`,
          generatedFiles,
        };
      } catch (error: unknown) {
        logger.error("Error in generateTextToImage:", error);
        return {
          success: false,
          message: "Failed to generate image",
          error: this.handleApiError(error),
        };
      }
    }
  • Helper utility to generate multiple prompt variations from styles, variations parameters, and outputCount for batch image generation.
    private buildBatchPrompts(request: ImageGenerationRequest): string[] {
      const prompts: string[] = [];
      const basePrompt = request.prompt;
    
      if (!request.styles && !request.variations && !request.outputCount) {
        return [basePrompt];
      }
    
      if (request.styles && request.styles.length > 0) {
        for (const style of request.styles) {
          prompts.push(`${basePrompt}, ${style} style`);
        }
      }
    
      if (request.variations && request.variations.length > 0) {
        const basePrompts = prompts.length > 0 ? prompts : [basePrompt];
        const variationPrompts: string[] = [];
    
        for (const baseP of basePrompts) {
          for (const variation of request.variations) {
            switch (variation) {
              case "lighting":
                variationPrompts.push(`${baseP}, dramatic lighting`);
                variationPrompts.push(`${baseP}, soft lighting`);
                break;
              case "angle":
                variationPrompts.push(`${baseP}, from above`);
                variationPrompts.push(`${baseP}, close-up view`);
                break;
              case "color-palette":
                variationPrompts.push(`${baseP}, warm color palette`);
                variationPrompts.push(`${baseP}, cool color palette`);
                break;
              case "composition":
                variationPrompts.push(`${baseP}, centered composition`);
                variationPrompts.push(`${baseP}, rule of thirds composition`);
                break;
              case "mood":
                variationPrompts.push(`${baseP}, cheerful mood`);
                variationPrompts.push(`${baseP}, dramatic mood`);
                break;
              case "season":
                variationPrompts.push(`${baseP}, in spring`);
                variationPrompts.push(`${baseP}, in winter`);
                break;
              case "time-of-day":
                variationPrompts.push(`${baseP}, at sunrise`);
                variationPrompts.push(`${baseP}, at sunset`);
                break;
              default:
                variationPrompts.push(`${baseP}, ${variation}`);
                break;
            }
          }
        }
    
        if (variationPrompts.length > 0) {
          prompts.splice(0, prompts.length, ...variationPrompts);
        }
      }
    
      if (
        prompts.length === 0 &&
        request.outputCount &&
        request.outputCount > 1
      ) {
        for (let i = 0; i < request.outputCount; i++) {
          prompts.push(basePrompt);
        }
      }
    
      if (request.outputCount && prompts.length > request.outputCount) {
        prompts.splice(request.outputCount);
      }
    
      return prompts.length > 0 ? prompts : [basePrompt];
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions generating images with options but lacks critical behavioral details: it doesn't disclose rate limits, authentication needs, output formats (e.g., file types), error handling, or whether it's a read/write operation. For a tool with 7 parameters and no annotations, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose ('generate single or multiple images from text prompts') and adds key features ('with style and variation options'). Every word earns its place with zero waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 7 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain return values (e.g., image URLs, file paths), error cases, or operational constraints like costs or latency. For a complex image generation tool, more context is needed to guide effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, providing detailed descriptions for all 7 parameters. The description adds minimal value beyond the schema, only implying that 'style and variation options' refer to the 'styles' and 'variations' parameters without additional context. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('generate images from text prompts') and resource ('images'), specifying it can handle single or multiple outputs with style and variation options. It distinguishes from siblings like 'edit_image' or 'restore_image' by focusing on generation from text, but doesn't explicitly contrast with other generation tools like 'generate_diagram' or 'generate_icon'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool versus alternatives is provided. The description mentions 'style and variation options' but doesn't specify when to choose this over siblings like 'generate_diagram' for diagrams or 'edit_image' for modifications. Usage context is implied but not articulated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/Aeven-AI/mcp-nanobanana'

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