AI Image Suggestions
Overview
The AI Image Suggestions feature allows users to get image recommendations assisted by AI when creating or editing content in Consul Democracy. Instead of manually searching for and uploading images, users can click a button to receive relevant stock image suggestions from Pexels based on the title and description of their content.
The feature uses a Large Language Model (LLM) to analyze the title and description fields of a resource, extract meaningful concepts, and generate an optimized search query. This query is then used to search the Pexels API for relevant stock images. When a user selects a suggested image, it is downloaded and attached to their content just like a user-uploaded image.
Prerequisites
To use this feature, you need:
LLM Provider Account: An account with an LLM provider (OpenAI, Anthropic, DeepSeek, etc.) or a self-hosted Ollama endpoint
Pexels API Key: A free API key from Pexels
Getting a Pexels API Key
Visit Pexels API
Sign up for a free account or log in
Navigate to your API dashboard
Create a new application to get your API key
Copy the API key for use in configuration
Note: Pexels offers a generous free tier with 200 requests per hour and 20,000 requests per month, which should be sufficient for most use cases.
Configuration
Step 1: Configure Secrets
First, you need to set up your LLM provider. For detailed instructions, see the User content translations documentation, which covers LLM configuration in detail.
In summary:
Add your LLM API key to the
secrets.ymlfile in theapis:section underllm::
Add Pexels API Key
Add your Pexels API key to the secrets.yml file in the apis: section:
For multitenancy setups: You can override the Pexels API key for specific tenants:
Step 2: Configure the Image Suggestion Prompt (Optional)
You can customize the prompt used to generate image search queries by editing config/llm_prompts.yml:
The prompt uses %{title} and %{description} placeholders that will be replaced with the actual content from the resource being created or edited.
Step 3: Enable the Feature
Once you have configured both the LLM provider and the Pexels API key:
Navigate to Admin > Global Settings > LLM Settings
Enable the AI Image Suggestions feature toggle
The feature will be enabled if:
LLM provider is configured
LLM model is selected
Pexels API key is present in secrets

How It Works
User Experience
When creating or editing budget investments:
User fills in title and/or description: The feature uses whichever of these fields is present to generate image suggestions.
User clicks "Suggest an image with AI": A button appears next to the image upload field (only when no image is currently attached).

Image upload form with AI suggestion button System generates suggestions:
The LLM analyzes the title and description
Extracts key concepts and generates a search query
Searches Pexels API with the generated query
Returns up to 4 relevant image suggestions
User views suggestions: A grid of suggested images appears below the upload button.

Suggested images grid User selects an image: Clicking on a suggested image:
Downloads the image from Pexels
Attaches it to the form as if it were user-uploaded
Replaces the upload interface with the selected image preview

Selected image preview
Technical Flow
Frontend: User clicks the suggestion button, which sends an AJAX request with the form data (title, description, resource type, etc.)
Backend Processing:
ImageSuggestionsController#createreceives the requestExtracts the relevant attributes from the request
Calls
ImageSuggestions::Llm::Clientto generate a search queryThe LLM client:
Validates LLM configuration
Validates that title and/or description are present
Sends the prompt to the LLM with title and description
Receives a search query string
Searches Pexels API with the query
Returns up to 4 image results
Image Attachment:
When user clicks a suggested image,
ImageSuggestionsController#attachis calledDownloads the image from Pexels
Creates an
ActionDispatch::Http::UploadedFilefrom the downloaded imageUses the existing
DirectUploadsystem to attach the imageReturns JSON with attachment details for frontend processing
Supported Resources
The image suggestions feature works with any resource that:
Has
titleanddescriptionattributes (or responds to these methods)Supports image attachments through the standard image attachment system
Uses the
Images::NestedComponent
Currently, this is only implemented on with Budget Investments feature!
Customization
Styling
The suggested images grid uses CSS classes that can be customized:
.suggested-images-container: Container for all suggested images.js-attach-suggested-image: Individual image button.suggested-image: The image element itself
Styles are defined in app/assets/stylesheets/mixins/uploads.scss.
Pricing Considerations
LLM Costs
Image suggestion queries are relatively short (typically 10-50 tokens), so costs are minimal. Each suggestion request:
Input: ~50-100 tokens (title + description + prompt)
Output: ~5-15 tokens (search query)
Pexels Costs
Pexels offers a free tier that should be sufficient for most installations:
200 requests per hour
20,000 requests per month
For higher usage, Pexels offers paid plans. See Pexels API pricing for details.
Troubleshooting
Feature button doesn't appear
Check that LLM provider and model are configured in Admin > Global Settings > LLM Settings
Verify that Image suggestions setting is enabled
Ensure Pexels API key is present in
secrets.ymlCheck browser console for JavaScript errors
No images are suggested
Pexels might be missing stock photos for certain terms.
Check that LLM is responding correctly (check application logs)
Verify Pexels API key is valid and has remaining quota
Last updated