Skip to main content
Glama

batch_render

Generate multiple images from a single template by applying different data sets. Use for creating e-commerce catalogs, certificates, or social media series in batches up to 20 items.

Instructions

Generate multiple images from the same template with different data. Perfect for e-commerce catalogs, certificates, social media series. Up to 20 items per batch.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
template_idYesTemplate ID to use for all items
itemsYesArray of items to render (max 20)

Implementation Reference

  • Main implementation of the batch_render tool. Contains registerBatchRenderTool function that defines the tool with its input schema (Zod validation) and the async handler that processes batch render requests, maps the input parameters, calls the API client, and formats the response with generated images and any errors.
    export function registerBatchRenderTool(
      server: McpServer,
      client: RendrKitClient,
    ): void {
      server.registerTool(
        "batch_render",
        {
          description:
            "Generate multiple images from the same template with different data. Perfect for e-commerce catalogs, certificates, social media series. Up to 20 items per batch.",
          inputSchema: {
            template_id: z
              .string()
              .describe("Template ID to use for all items"),
            items: z
              .array(
                z.object({
                  slots: z.record(z.string(), z.string()).describe("Slot values for this item"),
                  image_url: z.string().optional().describe("Photo URL for this item"),
                }),
              )
              .describe("Array of items to render (max 20)"),
          },
        },
        async ({ template_id, items }) => {
          try {
            const result = await client.batchRender({
              templateId: template_id,
              items: items.map((item) => ({
                slots: item.slots,
                imageUrl: item.image_url,
              })),
            });
    
            const lines = result.images.map(
              (img, i) => `${i + 1}. ${img.url}`,
            );
            const errorLines = result.errors?.map(
              (e) => `Error at index ${e.index}: ${e.message}`,
            ) ?? [];
    
            return {
              content: [
                {
                  type: "text" as const,
                  text: [
                    `Batch complete: ${result.images.length} images generated`,
                    ``,
                    ...lines,
                    ...(errorLines.length > 0 ? [``, `Errors:`, ...errorLines] : []),
                  ].join("\n"),
                },
              ],
            };
          } catch (error) {
            return {
              content: [{ type: "text" as const, text: `Batch render failed: ${error instanceof Error ? error.message : String(error)}` }],
              isError: true,
            };
          }
        },
      );
    }
  • Type definitions for batch render parameters and response. BatchRenderParams defines the templateId and array of items with slots and optional imageUrl. BatchRenderResponse defines the response containing an array of GeneratedImage objects and optional errors array.
    export interface BatchRenderParams {
      templateId: string;
      items: Array<{
        slots: Record<string, string>;
        imageUrl?: string;
      }>;
    }
    
    /** Response from batch render */
    export interface BatchRenderResponse {
      images: GeneratedImage[];
      errors?: Array<{ index: number; code: string; message: string }>;
    }
  • src/server.ts:9-24 (registration)
    Tool registration point. Imports registerBatchRenderTool from the tools module and calls it to register the batch_render tool with the MCP server during server initialization.
    import { registerBatchRenderTool } from "./tools/batch-render.js";
    import { registerCloneTemplateTool } from "./tools/clone-template.js";
    
    export function createServer(client: RendrKitClient): McpServer {
      const server = new McpServer({
        name: "rendrkit",
        version: "0.3.0",
      });
    
      registerGenerateImageTool(server, client);
      registerGetImageTool(server, client);
      registerListBrandKitsTool(server, client);
      registerGetUsageTool(server, client);
      registerListTemplatesTool(server, client);
      registerUploadImageTool(server, client);
      registerBatchRenderTool(server, client);
  • API client method that performs the actual HTTP POST request to the batch-render endpoint. Accepts BatchRenderParams and returns a Promise<BatchRenderResponse>.
    async batchRender(params: BatchRenderParams): Promise<BatchRenderResponse> {
      return this.request<BatchRenderResponse>("POST", "/api/v1/generate/batch-render", params);
    }

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/vbiff/rendr-kit'

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