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
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | Text prompt for image generation | |
| model | No | Model ID (default: flux) | flux |
| width | No | Image width | |
| height | No | Image height | |
| enhance | No | Enhance prompt with AI | |
| seed | No | Seed for reproducibility |
Implementation Reference
- src/tools.ts:160-213 (handler)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"), }, ], }; } - src/tools.ts:57-64 (schema)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"), });