Skip to main content
Glama

generate_batch

Generate multiple images simultaneously in a single call to improve efficiency when creating batches of up to 10 images from text prompts.

Instructions

Generate multiple images in one call (up to 10). More efficient than calling generate_image repeatedly.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptsYesArray of image prompts to generate (max 10)

Implementation Reference

  • The handler function for 'generate_batch' which iterates through provided prompts, validates them, and generates image URLs.
    export async function handleGenerateBatch(
      args: z.infer<typeof generateBatchSchema>
    ) {
      const results: string[] = [];
    
      for (const item of args.prompts) {
        const model = getModel(item.model);
        if (!model || model.type !== "image") {
          results.push(`❌ ${item.prompt.slice(0, 40)}... — unknown model: ${item.model}`);
          continue;
        }
        if (!model.free && !API_KEY) {
          results.push(`❌ ${item.prompt.slice(0, 40)}... — model "${item.model}" requires API key`);
          continue;
        }
    
        const params = new URLSearchParams({
          model: item.model,
          width: String(item.width ?? 1024),
          height: String(item.height ?? 1024),
          nologo: "true",
          seed: String(item.seed ?? Math.floor(Math.random() * 999999999)),
        });
        if (API_KEY) params.set("token", API_KEY);
    
        const url = `https://gen.pollinations.ai/image/${encodeURIComponent(item.prompt)}?${params}`;
        results.push(`✅ ${item.prompt.slice(0, 50)}...\n   Model: ${model.name} | URL: ${url}`);
      }
    
      return {
        content: [
          {
            type: "text" as const,
            text: [`Batch generation (${args.prompts.length} items):`, "", ...results].join("\n"),
          },
        ],
      };
    }
  • Zod schema definition for 'generate_batch' inputs.
    export const generateBatchSchema = z.object({
      prompts: z
        .array(
          z.object({
            prompt: z.string().describe("Text prompt"),
            model: z.string().default("flux").describe("Model ID"),
            width: z.number().default(1024).optional(),
            height: z.number().default(1024).optional(),
            seed: z.number().optional(),
          })
        )
        .min(1)
        .max(10)
        .describe("Array of image prompts to generate (max 10)"),
    });

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