Skip to main content
Glama

generate_image

Create images from text prompts using AI models. Specify dimensions and settings to generate visual content for various applications.

Instructions

Generate an image using Pollinations API. Returns a URL to the generated image.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesText prompt for image generation
modelNoModel ID (default: flux)flux
widthNoImage width
heightNoImage height
enhanceNoEnhance prompt with AI
seedNoSeed for reproducibility

Implementation Reference

  • The handler function for the 'generate_image' tool, which processes the input arguments, validates the model, builds the Pollinations API URL, and returns the result.
    export async function handleGenerateImage(
      args: z.infer<typeof generateImageSchema>
    ) {
      const model = getModel(args.model);
      if (!model || model.type !== "image") {
        return {
          content: [
            {
              type: "text" as const,
              text: `Unknown image model: ${args.model}. Use list_models to see available models.`,
            },
          ],
          isError: true,
        };
      }
      if (!model.free && !API_KEY) {
        return {
          content: [
            {
              type: "text" as const,
              text: `Model "${args.model}" requires a Pollinations API key. Set POLLINATIONS_API_KEY env variable.`,
            },
          ],
          isError: true,
        };
      }
    
      const params = new URLSearchParams({
        model: args.model,
        width: String(args.width),
        height: String(args.height),
        enhance: String(args.enhance),
        nologo: "true",
      });
      if (args.seed !== undefined) params.set("seed", String(args.seed));
      if (API_KEY) params.set("token", API_KEY);
    
      const encodedPrompt = encodeURIComponent(args.prompt);
      const url = `https://gen.pollinations.ai/image/${encodedPrompt}?${params}`;
    
      return {
        content: [
          {
            type: "text" as const,
            text: [
              `Image generated successfully!`,
              `Model: ${model.name}`,
              `Size: ${args.width}x${args.height}`,
              `URL: ${url}`,
            ].join("\n"),
          },
        ],
      };
    }
  • The Zod schema definition for the 'generate_image' tool input parameters.
    export const generateImageSchema = z.object({
      prompt: z.string().describe("Text prompt for image generation"),
      model: z.string().default("flux").describe("Model ID (default: flux)"),
      width: z.number().min(256).max(2048).default(1024).describe("Image width"),
      height: z.number().min(256).max(2048).default(1024).describe("Image height"),
      enhance: z.boolean().default(true).describe("Enhance prompt with AI"),
      seed: z.number().optional().describe("Seed for reproducibility"),
    });

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/doctorm333/promptpilot-mcp-server'

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