Skip to main content
Glama

generateImage

Create or edit images using text prompts or base images. Automatically opens results in your browser and provides direct links for easy access.

Instructions

Generate images using the 4o-image API and automatically open the results in your browser.

This tool generates images based on your prompt and automatically opens them in your default browser, while also returning a clickable link.

The tool supports two modes:

  1. Text-to-image - Create new images using just a text prompt

  2. Image editing - Provide a base image and prompt for editing or style transfer

The response will include a direct link to the generated image and detailed information.

Visit our website: https://4o-image.app/

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
imageBase64NoOptional base image (Base64 encoded) for image editing or upscaling
promptYesText description of the desired image content

Implementation Reference

  • Executes the generateImage tool: processes params (prompt, imageBase64), converts base64 to buffer, calls image-service.generateImage, opens result in browser, returns MCP-formatted text response with details and link.
    async processImageGeneration(params) {
      try {
        const { prompt, imageBase64 } = params;
        const endpoint = "4oimage";
        
        
        const startTime = Date.now();
        let imageBuffer = null;
        
        // Convert Base64 image to Buffer if provided
        if (imageBase64) {
          try {
            const base64Data = imageBase64.replace(/^data:image\/\w+;base64,/, "");
            imageBuffer = Buffer.from(base64Data, 'base64');
          } catch (error) {
            return {
              content: [{ 
                type: "text", 
                text: `Error converting image: ${error.message}` 
              }]
            };
          }
        }
        
        try {
          // Create progress callback
          const progressCallback = (update) => {
          };
    
          // Wait for image generation
          const result = await generateImage(imageBuffer, prompt, { endpoint, progressCallback });
    
          // Process results
          if (result.success && result.imageUrl) {
            const imageUrl = result.imageUrl;
            
            try {
              // Open image URL in browser
              await open(imageUrl);
            } catch (openError) {
    
            }
            
            // Return response
            const responseText = 
              `Image generated successfully!\n` +
              `The image has been opened in your default browser.\n\n` +
              `Generation details:\n` +
              `- Prompt: "${prompt}"\n` +
              `- Image URL: ${imageUrl}\n\n` +
              `Visit our website: https://4o-image.app/\n\n` +
              `You can also click the URL above to view the image again.`;
            
            return {
              content: [
                {
                  type: "text",
                  text: responseText
                }
              ]
            };
          } else {
            // Handle errors
            let errorMessage = "Image generation failed";
            
            if (!result.success) {
              errorMessage = result.error || "Unknown error";
            } else if (!result.imageUrl) {
              errorMessage = "Invalid image URL generated";
            }
            
            return {
              content: [{ 
                type: "text", 
                text: `Image generation failed: ${errorMessage}` 
              }]
            };
          }
        } catch (error) {
          return {
            content: [{ 
              type: "text", 
              text: `Error generating image: ${error.message}` 
            }]
          };
        }
      } catch (outerError) {
        return {
          content: [{ 
            type: "text", 
            text: `Error processing image generation request: ${outerError.message}` 
          }]
        };
      }
    }
  • Tool definition including name, description, and inputSchema for prompt (required) and optional imageBase64.
    const GENERATE_IMAGE_TOOL = {
      name: "generateImage",
      description: `Generate images using the 4o-image API and automatically open the results in your browser.
    
    This tool generates images based on your prompt and automatically opens them in your default browser, while also returning a clickable link.
    
    The tool supports two modes:
    1. Text-to-image - Create new images using just a text prompt
    2. Image editing - Provide a base image and prompt for editing or style transfer
    
    The response will include a direct link to the generated image and detailed information.
    
    Visit our website: https://4o-image.app/`,
      inputSchema: {
        type: "object",
        properties: {
          prompt: {
            type: "string",
            description: "Text description of the desired image content"
          },
          imageBase64: {
            type: "string",
            description: "Optional base image (Base64 encoded) for image editing or upscaling"
          }
        },
        required: ["prompt"]
      }
    };
  • Registers the generateImage tool by including it in the ListTools response.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      const response = { tools: [GENERATE_IMAGE_TOOL] };
      return response;
    });
  • Core helper function: submits image generation task to 4o-image API, polls status until completion, extracts and validates image URL, returns success with URL or error.
    export async function generateImage(imageBuffer, prompt = "", options = {}) {
      const endpoint = "4oimage";
      const { progressCallback } = options;
      
      const startTime = Date.now();
      
      try {
        // 1. Submit task
        const submitResult = await submitImageTask(imageBuffer, prompt);
        
        if (!submitResult.success) {
          return { success: false, error: submitResult.error, code: submitResult.code };
        }
        
        const taskId = submitResult.taskId;
        
        // 2. Poll task status
        const result = await pollTaskUntilComplete(taskId, progressCallback);
        
        // 3. Return result
        if (result && typeof result === 'object') {
          // Check if image URL exists and is valid
          if (result.image_url && typeof result.image_url === 'string' && result.image_url.startsWith('http')) {
            const totalTime = Date.now() - startTime;
            return { success: true, imageUrl: result.image_url };
          } else {
    
            return { success: false, error: "Invalid image URL" };
          }
        } else {
    
          return { success: false, error: "Invalid result object" };
        }
      } catch (error) {
        const totalTime = Date.now() - startTime;
        return { success: false, error: error.message };
      }
    } 
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It adds valuable context beyond the input schema by describing automatic browser opening, return of a clickable link, and support for two modes. However, it does not cover important behavioral traits such as rate limits, authentication needs, error handling, or response format details, leaving gaps for a mutation tool.

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

Conciseness4/5

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

The description is well-structured and front-loaded, starting with the core functionality and then detailing modes and responses. Most sentences add value, but the final promotional sentence ('Visit our website...') is extraneous and does not aid tool selection or invocation, slightly reducing efficiency.

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

Completeness3/5

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

Given the tool's complexity (image generation with two modes), no annotations, and no output schema, the description is moderately complete. It covers purpose, usage modes, and some behavioral aspects (browser opening, link return), but lacks details on output structure, error cases, or operational constraints, which are important for a tool without structured output documentation.

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%, so the input schema already documents both parameters (imageBase64 and prompt) adequately. The description adds marginal value by explaining the two modes that correspond to these parameters, but it does not provide additional syntax, format, or constraint details beyond what the schema states. This meets the baseline for high schema coverage.

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 tool's purpose: 'Generate images using the 4o-image API' and specifies it 'automatically opens the results in your browser.' It distinguishes between text-to-image and image editing modes, providing specific functionality details. However, without sibling tools, differentiation from alternatives is not applicable, preventing a perfect score.

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

Usage Guidelines4/5

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

The description provides clear usage context by outlining two modes (text-to-image and image editing) and indicating when to use each based on whether an imageBase64 parameter is provided. It mentions that the tool opens results in the browser and returns a clickable link, offering practical guidance. However, it lacks explicit exclusions or comparisons to alternatives, as no sibling tools exist.

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

Related 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/Antipas/4oimage-mcp'

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