Image Generation & Editing
Comprehensive guide to LibreChat's built-in image generation and editing tools
LibreChat ships with built-in image tools that you add to an Agent. Each tool has its own model, price point, and setup, usually just an API key or a URL. There is no separate image page: you generate or edit images by chatting with an Agent that has an image tool enabled.
How image generation works
Upload an image when you want an edit, or send a plain text prompt when you want a new image. Generated images follow the configured fileStrategy and the tool output is sent to the LLM as part of the chat context immediately after generation.
Quick Start
Get image generation working in a few minutes with OpenAI Image Tools.
Create an agent. Select Agents from the endpoint menu, open the Agent Builder from the side panel, and create a new agent. Give it a name like "Image Creator".
Add OpenAI Image Tools. Open the agent's Tools list, select OpenAI Image Tools, and save the agent. This adds both image generation and image editing capabilities.
Set your API key. Add the following to your .env file:
IMAGE_GEN_OAI_API_KEY=sk-your-openai-api-key
# Optional; defaults to gpt-image-2.5-flare
IMAGE_GEN_OAI_MODEL=gpt-image-2.5-flareRestart and test. Restart LibreChat, then send a message like "Generate an image of a sunset over mountains" to your agent.
| Deployment | Command |
|---|---|
| Docker | docker compose down && docker compose up -d |
| Local | Stop (Ctrl+C) then npm run backend |
Good to know
- API keys can be omitted to let users enter their own key from the UI.
- Image outputs are sent to the LLM only immediately after generation, not on every message. The LLM otherwise gets vision context only from images attached to user messages. See Image Storage and Handling.
- MCP server tools can also output images, though they may not always use the correct format. See the MCP section.
OpenAI Image Tools
"OpenAI Image Tools" is an agent toolkit made up of two separate tools:
- Image Generation creates brand-new images from text prompts (no upload required).
- Image Editing edits or remixes images you uploaded: change colors, add objects, extend the canvas, and more.
Both default to gpt-image-2.5-flare. Use IMAGE_GEN_OAI_MODEL to choose a different OpenAI image model when your deployment supports it. OpenAI retires gpt-image-1 on October 23, 2026, so remove it from IMAGE_GEN_OAI_MODEL if you set it explicitly. See OpenAI's Image Generation documentation for more details.
Generation vs. Editing
| Use case | Invokes |
|---|---|
| "Start from scratch" | Image Generation |
| "Use existing image(s)" | Image Editing |
Both tools are always available, and the agent chooses the appropriate one based on the request:
- Image Generation creates new images from text descriptions only.
- Image Editing modifies or remixes existing images using their image IDs. These can be images from the current message or previously generated and referenced images. The LLM keeps track of image IDs as long as they remain in the context window and includes them in the tool output.
Image editing relies on image IDs
- Image IDs are retained in the chat history. When files are uploaded to the current request, their IDs are added to the LLM's context before any tokens are generated.
- Previously referenced or generated image IDs can be used for editing as long as they remain within the context window. The LLM includes any relevant IDs in the
image_idsarray when calling the editing tool. - You can attach previously uploaded images from the side panel without uploading them again. This also gives a vision model the image context, which can help inform the
promptfor the editing tool.
Parameters
Image Generation
- prompt: text description (required)
- size:
auto(default),1024x1024(square),1536x1024(landscape), or1024x1536(portrait); models that support custom dimensions, such asgpt-image-2.5-flare, accept anyWIDTHxHEIGHTwithin their limits, for example2048x1152or3840x2160 - quality:
auto(default),high,medium, orlow - background:
auto(default),transparent, oropaque(transparent requires PNG or WebP format)
Image Editing
- image_ids: array of image IDs to use as reference for editing (required)
- prompt: text description of the changes (required)
- size:
auto(default),1024x1024,1536x1024, or1024x1536; models that support custom dimensions accept anyWIDTHxHEIGHTwithin their limits, for example3840x2160 - quality:
auto(default),high,medium, orlow
Keeping large sizes
By default, LibreChat resizes saved images so their shorter side is at most 768 pixels, so a 3840x2160 result is stored at 1365x768. To keep the requested size, set fileConfig.imageGeneration to percentage: 100, or to a px cap large enough for your sizes.
Setup
Create or reuse an OpenAI key and add it to .env, then add "OpenAI Image Tools" to your agent's Tools list:
IMAGE_GEN_OAI_API_KEY=sk-...
# optional extras
IMAGE_GEN_OAI_MODEL=gpt-image-2.5-flare
IMAGE_GEN_OAI_BASEURL=https://...For Azure OpenAI, deploy an image model in your Azure OpenAI resource, then add your credentials to .env. Set IMAGE_GEN_OAI_MODEL to the deployment name:
IMAGE_GEN_OAI_API_KEY=your-api-key
# optional extras
IMAGE_GEN_OAI_MODEL=your-deployment-name
IMAGE_GEN_OAI_BASEURL=https://your-resource-name.openai.azure.com/openai/deployments/your-deployment-name/
IMAGE_GEN_OAI_AZURE_API_VERSION=2025-04-01-previewAdvanced Configuration
Customize the tool descriptions and prompt guidance with these environment variables:
# Image Model
IMAGE_GEN_OAI_MODEL=gpt-image-2.5-flare
# Image Generation Tool Descriptions
IMAGE_GEN_OAI_DESCRIPTION=...
IMAGE_GEN_OAI_PROMPT_DESCRIPTION=...
# Image Editing Tool Descriptions
IMAGE_EDIT_OAI_DESCRIPTION=...
IMAGE_EDIT_OAI_PROMPT_DESCRIPTION=...Pricing
See OpenAI's API pricing page and Image Generation documentation for image generation costs.
Gemini Image Tools
Gemini Image Tools integrate Google's latest image generation models, supporting both text-to-image generation and image context-aware editing.
- Text-to-image generation: create high-quality images from detailed text descriptions.
- Image context support: use existing images as context or inspiration for new generations.
- Image editing: generate new images based on modifications to existing ones (include the original image ID).
- Multiple models: choose
gemini-2.5-flash-image(default) orgemini-3-pro-image-preview. - Dual API support: works with both simple Gemini API keys and Google Cloud Vertex AI.
Parameters
- prompt: detailed text description of the desired image (required, up to 32,000 characters)
- image_ids: optional array of image IDs to use as visual context for generation
- aspectRatio: optional; one of
1:1(default),2:3,3:2,3:4,4:3,4:5,5:4,9:16,16:9, or21:9 - imageSize: optional;
1K(default),2K, or4K
Setup
LibreChat picks credentials in this order: the user's own key (entered in the UI), GEMINI_API_KEY, GOOGLE_KEY (shared with the Google chat endpoint), then a Vertex AI service account.
For the Gemini API, get a key from Google AI Studio:
GEMINI_API_KEY=your_api_key_hereFor Vertex AI (Google Cloud users with Vertex AI access):
GOOGLE_SERVICE_KEY_FILE=/path/to/service-account.json
GOOGLE_CLOUD_LOCATION=us-central1 # optional, default: globalGOOGLE_LOC is also accepted as the location when GOOGLE_CLOUD_LOCATION is not set.
Model Selection
# Default model (fast and efficient)
GEMINI_IMAGE_MODEL=gemini-2.5-flash-image
# Higher quality model
GEMINI_IMAGE_MODEL=gemini-3-pro-image-previewAdvanced Configuration
Customize tool descriptions via environment variables:
GEMINI_IMAGE_GEN_DESCRIPTION=...
GEMINI_IMAGE_GEN_PROMPT_DESCRIPTION=...
GEMINI_IMAGE_IDS_DESCRIPTION=...More details are in the dedicated Gemini Image Gen guide.
Stable Diffusion (local)
Run images entirely on your own machine or server. Point LibreChat at any Automatic1111 (or compatible) endpoint and you're set.
Parameters
- prompt: detailed keywords describing desired elements in the image (required)
- negative_prompt: keywords describing elements to exclude from the image (required)
The Stable Diffusion implementation uses these fixed default parameters, which produce good results for most use cases:
- cfg_scale: 4.5
- steps: 22
- width: 1024
- height: 1024
Setup
No API key is required, just the reachable URL of your Automatic1111 WebUI:
SD_WEBUI_URL=http://127.0.0.1:7860 # URL to your Automatic1111 WebUIMore details on setting up Automatic1111 are in the dedicated Stable Diffusion guide.
Flux
Cloud generator with an emphasis on speed and optional fine-tuned models.
- Fast cloud-based image generation
- Support for fine-tuned models
- Multiple quality levels and aspect ratios
- Raw mode for less processed, more natural-looking images
Parameters
The Flux tool supports three main actions:
- generate: create a new image from a text prompt
- generate_finetuned: create an image using a fine-tuned model
- list_finetunes: list available custom models for the user
More details are in the dedicated Flux guide.
Setup
Choose the Flux tool inside the agent. Prompts are plain text, and one call produces one image.
FLUX_API_KEY=flux_live_...
FLUX_API_BASE_URL=https://api.us1.bfl.ai # default is fine for most usersPricing
See the Flux pricing page for image generation costs.
Model Context Protocol (MCP)
Image outputs are supported from MCP servers. For example, the Puppeteer MCP Server can generate screenshots of web pages, which output the image in the expected format and are treated the same as LibreChat's built-in image tools.
MCP image support is still emerging
- The examples below assume LibreChat runs outside of Docker, directly using Node.js. The Model Context Protocol is a relatively new framework, and many developers are still learning how to serve their systems with uv/node for scalable distribution.
- Few image-generating servers exist, and many have yet to adopt the correct response format for images.
- While many MCP servers function well within Docker, the following examples do not, or not without more advanced configurations, showing some of the current inconsistency between MCP servers.
mcpServers:
puppeteer:
command: npx
args:
- -y
- '@modelcontextprotocol/server-puppeteer'The following is an example of an Image Generation server that outputs images using the Replicate API, but returns URLs of the images, which doesn't conform to MCP's image response standard.
Global install required
For this particular server, install the @gongrzhe/image-gen-server package globally with npm install -g @gongrzhe/image-gen-server, then point to the package's compiled files as shown below.
mcpServers:
image-gen:
command: 'node'
# First, install the package globally using npm:
# `npm install -g @gongrzhe/image-gen-server`
# Then, point to the location of the installed package,
# which you can find by running `npm root -g`
args:
- '{REPLACE_WITH_NODE_MODULES_LOCATION}/@gongrzhe/image-gen-server/build/index.js'
# Example with output from `npm root -g`:
# - "/home/danny/.nvm/versions/node/v24.16.0/lib/node_modules/@gongrzhe/image-gen-server/build/index.js"
env:
# Do not hardcode the API token here, use the environment variable instead
# The following will pick up the token from your .env file or environment
REPLICATE_API_TOKEN: '${REPLICATE_API_TOKEN}'
MODEL: 'google/imagen-3'Image Storage and Handling
All generated images are:
- Saved according to the configured
fileStrategy - Displayed directly in the chat interface
- Sent to the LLM as part of the immediate chat context following generation
A few caveats apply to that last point:
- This may cause issues with an LLM that does not support image inputs. An option to disable the behavior per agent is planned.
- Outputs are sent to the LLM only upon generation, not on every message.
- To include an image in later turns, attach it to the message from the side panel.
- In short, the LLM gets vision context only from images attached to user messages, and from generations or edits immediately after they happen.
Proxy Support
All image generation tools support proxy configuration through the PROXY environment variable:
PROXY=http://proxy-url:portWhen PROXY is unset, supported server-side clients honor HTTP_PROXY, HTTPS_PROXY, and NO_PROXY/no_proxy.
Error Handling
If a tool encounters an error, it returns a message explaining what went wrong. Common issues include:
- Invalid API key
- API unavailability
- Content policy violations
- Proxy/network issues
- Invalid parameters
- Unsupported image payload (see Image Storage and Handling above)
Prompting
You can customize the prompts for OpenAI Image Tools, but the following tips inform the default prompts the tool supplies, which is useful to know for your own writing:
- Start with the subject and style (photo, oil painting, etc.).
- Add composition and camera/medium ("wide-angle shot of…", "watercolour…").
- Mention lighting and mood ("golden hour", "dramatic shadows").
- Finish with detail keywords (textures, colours, expressions).
- Keep negatives positive: describe what should be included, not what to avoid.
Example:
A cinematic photo of an antique library bathed in warm afternoon sunlight. Tall wooden shelves overflow with leather-bound books, and dust particles shimmer in the light. A single green-shaded banker's lamp illuminates an open atlas on a polished mahogany desk in the foreground. 85 mm lens, shallow depth of field, rich amber tones, ultra-high detail.
Related Pages
How is this guide?
OCR for Documents
Learn how to configure Optical Character Recognition (OCR) to enhance text extraction in LibreChat's file upload features.
Message Composer
Write messages, attach files, and turn on tools, skills and MCP servers from the composer's + palette, then queue or steer follow-ups while a response streams.