generate_image
Generate AI images from text prompts and save them to your media library for use in social media posts. Choose from four models based on quality and cost. Requires AI scope.
Instructions
Generate an AI image from a text prompt on PostEverywhere. The image is saved to your media library and can be attached to posts via media_ids. Choose from 4 models: nano-banana-pro (best quality, 15 credits), ideogram-v2 (best for text-in-image, 8 credits), gemini-3-pro (balanced, 5 credits), flux-schnell (fastest, 1 credit). Requires the "ai" scope on your API key.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | Text description of the image to generate | |
| aspect_ratio | No | Aspect ratio for the generated image | 1:1 |
| model | No | AI model to use for generation | nano-banana-pro |
Implementation Reference
- src/tools.ts:217-231 (registration)The 'generate_image' tool is registered using server.tool() in the registerTools function. It defines the tool name, description, input schema (prompt, aspect_ratio, model), and the handler callback.
server.tool( 'generate_image', 'Generate an AI image from a text prompt on PostEverywhere. The image is saved to your media library and can be attached to posts via media_ids. Choose from 4 models: nano-banana-pro (best quality, 15 credits), ideogram-v2 (best for text-in-image, 8 credits), gemini-3-pro (balanced, 5 credits), flux-schnell (fastest, 1 credit). Requires the "ai" scope on your API key.', { prompt: z.string().max(2000).describe('Text description of the image to generate'), aspect_ratio: z.enum(['1:1', '16:9', '9:16', '4:3', '3:4', '4:5', '5:4']).optional().default('1:1').describe('Aspect ratio for the generated image'), model: z.enum(['nano-banana-pro', 'ideogram-v2', 'gemini-3-pro', 'flux-schnell']).optional().default('nano-banana-pro').describe('AI model to use for generation'), }, async ({ prompt, aspect_ratio, model }) => { const result = await client.generateImage({ prompt, aspect_ratio, model }); return { content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2) }], }; } ); - src/tools.ts:225-230 (handler)The handler function for 'generate_image' that receives {prompt, aspect_ratio, model} and delegates to client.generateImage(), returning the JSON-stringified result.
async ({ prompt, aspect_ratio, model }) => { const result = await client.generateImage({ prompt, aspect_ratio, model }); return { content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2) }], }; } - src/tools.ts:220-224 (schema)Input schema defined with Zod: prompt (string, max 2000), aspect_ratio (enum, optional, default '1:1'), model (enum, optional, default 'nano-banana-pro').
{ prompt: z.string().max(2000).describe('Text description of the image to generate'), aspect_ratio: z.enum(['1:1', '16:9', '9:16', '4:3', '3:4', '4:5', '5:4']).optional().default('1:1').describe('Aspect ratio for the generated image'), model: z.enum(['nano-banana-pro', 'ideogram-v2', 'gemini-3-pro', 'flux-schnell']).optional().default('nano-banana-pro').describe('AI model to use for generation'), }, - src/client.ts:212-218 (helper)The client method generateImage() on PostEverywhereClient that sends a POST request to /ai/generate-image with the prompt, aspect_ratio, and model body. Returns a Promise with media_id, model, aspect_ratio, credits_used, credits_remaining, and message.
async generateImage(body: { prompt: string; aspect_ratio?: string; model?: string; }): Promise<{ media_id: string; model: string; aspect_ratio: string; credits_used: number; credits_remaining: number; message: string }> { return this.request('POST', '/ai/generate-image', body); }