Skip to main content
Glama

generate_image

Create images from text prompts with customizable styles and variations.

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 registration in ListToolsRequestSchema handler - defines the 'generate_image' tool name, description, and its JSON Schema input validation.
      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"],
      },
    },
  • Handler in CallToolRequestSchema - extracts args into ImageGenerationRequest and delegates 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;
  • TypeScript interface for ImageGenerationRequest used as input to the image generation pipeline.
    export interface ImageGenerationRequest {
      prompt: string;
      inputImage?: string;
      outputCount?: number;
      mode: "generate" | "edit" | "restore";
      // Batch generation options
      styles?: string[];
      variations?: string[];
      format?: "grid" | "separate";
      fileFormat?: "png" | "jpeg";
      seed?: number;
      // Preview options
      preview?: boolean;
      noPreview?: boolean;
    }
  • Core implementation of text-to-image generation - builds prompts, calls OpenRouter API, parses image from response, saves files, and handles preview.
    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),
        };
      }
    }
Behavior2/5

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

No annotations are provided, so the description must carry the full burden of behavioral disclosure. It does not mention return format, side effects, authentication, or rate limits, leaving significant gaps for an AI agent.

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, front-loaded sentence of 12 words with no redundancy. Every word adds value, making it highly concise.

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 and no output schema, the description is too brief. It does not explain output format behavior, return values, or how to use the preview option, leaving the agent under-informed about key aspects.

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 coverage is 100%, so the baseline is 3. The description adds minimal extra meaning beyond the schema, only loosely grouping parameters under 'style and variation options'.

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

Purpose5/5

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

The description clearly states the tool generates single or multiple images from text prompts, specifying the key feature of style and variation options. This distinguishes it from sibling tools like edit_image (editing) and generate_diagram (diagrams), providing a clear purpose.

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?

The description lacks any guidance on when to use or when not to use this tool. It does not mention alternatives or conditions, leaving the agent to infer usage from the name alone.

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