Skip to main content
Glama
xujfcn
by xujfcn

generate_image

Create AI-generated images from text descriptions using models like DALL-E 3, Midjourney, or Stable Diffusion. Specify size, quantity, and model to produce custom visuals.

Instructions

Generate images using AI models via Crazyrouter. Supports DALL-E 3, Midjourney, Flux, Stable Diffusion, and more.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesText description of the image to generate
modelNoImage generation model to use (default: dall-e-3). Options: dall-e-3, midjourney, flux-pro-1.1-ultra, flux-kontext-pro, sd3.5-large, imagen-4.0-generate-001dall-e-3
sizeNoImage size. For DALL-E 3: 1024x1024, 1024x1792, 1792x1024.
nNoNumber of images to generate (1-4, default: 1)

Implementation Reference

  • The 'generate_image' tool is registered and implemented in src/index.ts. It uses the 'apiRequest' helper to interact with the Crazyrouter API.
    // --- Tool: generate_image ---
    server.tool(
      "generate_image",
      "Generate images using AI models via Crazyrouter. Supports DALL-E 3, Midjourney, Flux, Stable Diffusion, and more.",
      {
        prompt: z.string().describe("Text description of the image to generate"),
        model: z
          .string()
          .default(DEFAULT_IMAGE_MODEL)
          .describe(`Image generation model to use (default: ${DEFAULT_IMAGE_MODEL}). Options: dall-e-3, midjourney, flux-pro-1.1-ultra, flux-kontext-pro, sd3.5-large, imagen-4.0-generate-001`),
        size: z.string().optional().describe("Image size. For DALL-E 3: 1024x1024, 1024x1792, 1792x1024."),
        n: z.number().min(1).max(4).optional().describe("Number of images to generate (1-4, default: 1)"),
      },
      async ({ prompt, model, size, n }) => {
        try {
          const body: Record<string, unknown> = { model, prompt };
          if (size) body.size = size;
          if (n) body.n = n;
    
          const result = (await apiRequest("/images/generations", {
            method: "POST",
            body,
          })) as { data?: Array<{ url?: string; b64_json?: string; revised_prompt?: string }> };
    
          if (!result.data || result.data.length === 0) {
            return { content: [{ type: "text" as const, text: "No images were generated. Please try a different prompt." }] };
          }
    
          const images = result.data;
          let text = `🎨 Generated ${images.length} image(s) with ${model}:\n\n`;
          for (let i = 0; i < images.length; i++) {
            const img = images[i];
            if (img.url) text += `**Image ${i + 1}:** ${img.url}\n`;
            if (img.revised_prompt) text += `*Revised prompt:* ${img.revised_prompt}\n`;
            text += "\n";
          }
    
          return { content: [{ type: "text" as const, text }] };
        } catch (error) {
          const message = error instanceof Error ? error.message : "Unknown error occurred";
          return { content: [{ type: "text" as const, text: `Error: ${message}` }], isError: true };
        }
      }
    );

Tool Definition Quality

Score is being calculated. Check back soon.

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/xujfcn/crazyrouter-mcp'

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