AI Image Generation

Users can generate an image from the Code Chat panel, or ask for a change to a photo already on the page. Pick one provider: OpenRouter, OpenAI or Fal.ai.

Using OpenRouter or OpenAI

Set the provider and list the models to offer. Image requests go to the endpoint Code Chat already uses, so there is nothing else to set up.

OpenRouter:

const builder = new ContentBuilder({
    // ...
    sendCommandUrl: '/openrouter',

    defaultImageGenerationProvider: 'openrouter',
    imageModels: [
        { id: 'google/gemini-3-pro-image', label: 'Gemini 3 Pro Image', image_input: true,
          sizes: ['auto', '1:1', '4:3', '3:4', '16:9', '9:16'] },
        { id: 'google/gemini-3.1-flash-image', label: 'Gemini 3.1 Flash Image', image_input: true,
          sizes: ['auto', '1:1', '4:3', '3:4', '16:9', '9:16'] },
    ],
});

OpenAI:

const builder = new ContentBuilder({
    // ...
    sendCommandUrl: '/sendcommand',

    defaultImageGenerationProvider: 'openai',
    imageModels: [
        { id: 'gpt-image-2', label: 'GPT Image 2', image_input: true,
          sizes: ['auto', '1024x1024', '1536x1024', '1024x1536', '2048x2048'] },
        { id: 'gpt-image-1-mini', label: 'GPT Image 1 Mini', image_input: true,
          sizes: ['auto', '1024x1024', '1536x1024', '1024x1536'] },
    ],
});

In each model entry:

  • id, label — the provider's model id, and the name users see in Chat Settings.
  • image_input: true — this model can work from an existing photo, so users can ask for a change to an image on the page. Without it the model only makes new images.
  • sizes — the choices in the size button. Use values the provider accepts: aspect ratios such as 16:9 for OpenRouter, pixel dimensions such as 1536x1024 for OpenAI. Include 'auto' to let the model choose — on an edit that keeps the original photo's shape.

Uses the API key you already set for Code Chat:

OPENROUTER_API_KEY=your_key
OPENAI_API_KEY=your_key

Using Fal.ai

Fal.ai needs three URLs configured.

Requirements

To enable AI image generation, you need an API key from:

Fal.ai – https://fal.ai

Configuration

Store your API key:

Node.js/Next.js (.env file):

FAL_API_KEY=your_fal_api_key

PHP (config.php file):

$FAL_API_KEY = 'your_fal_api_key';

Configure ContentBuilder:

Node.js:

const builder = new ContentBuilder({
    container: '.container',
    
    defaultImageGenerationProvider: 'fal',
    generateMediaUrl_Fal: '/request-fal',
    checkRequestStatusUrl_Fal: '/status-fal',
    getResultUrl_Fal: '/result-fal',
});

Next.js:

const builder = new ContentBuilder({
    container: '.container',
    
    defaultImageGenerationProvider: 'fal',
    generateMediaUrl_Fal: '/api/request-fal',
    checkRequestStatusUrl_Fal: '/api/status-fal',
    getResultUrl_Fal: '/api/result-fal',
});

PHP:

const builder = new ContentBuilder({
    container: '.container',
    
    defaultImageGenerationProvider: 'fal',
    generateMediaUrl_Fal: 'api/request-fal.php',
    checkRequestStatusUrl_Fal: 'api/status-fal.php',
    getResultUrl_Fal: 'api/result-fal.php',
});

Choosing Image Models

Whichever provider you use, the models you list in imageModels are what users pick from in Chat Settings, along with the size choices you gave that model.

imageModels is optional: each provider ships with a built-in list, so leaving it out gives users a ready set of models. Set it when you want to offer fewer models, different ones, or your own size choices.

Server-Side Implementation

Working examples for Node.js, PHP and Next.js are included in this package, pre-configured. OpenRouter and OpenAI are served by the Code Chat route you already have; Fal.ai uses its own three endpoints.

📢 Upgrade Note

For existing users: If you're currently using Getimg.ai for image generation (textToImageUrl, upscaleImageUrl parameters), your implementation will continue to work without any changes. The Fal.ai integration is the current recommended approach for accessing a wider range of AI models, but you can continue using your existing setup or upgrade at your own pace.

View this page on GitHub

© 2026 InnovaStudio

This site is built with Site Builder Kit