AI Provider Configuration
AI Alt Text supports multiple AI providers with vision capabilities. This document provides detailed configuration instructions for each provider.
Table of Contents
Section titled “Table of Contents”- Configuration Priority
- OpenAI
- Azure OpenAI
- Anthropic Claude
- Google Gemini
- Ollama (Self-Hosted)
- Grok (xAI)
- Environment Variables Reference
- Constants Reference
- Troubleshooting
Configuration Priority
Section titled “Configuration Priority”Settings are resolved in the following priority order:
- PHP Constants (wp-config.php) - Highest priority
- Environment Variables - Second priority
- Database Settings (Admin UI) - Third priority
- Default Values - Fallback
When a setting is defined via constant or environment variable, the admin UI field becomes read-only and shows the source.
OpenAI
Section titled “OpenAI”Requirements
Section titled “Requirements”- OpenAI API account with billing enabled
- API key from OpenAI Platform
Recommended Models
Section titled “Recommended Models”| Model | Description | Cost |
|---|---|---|
gpt-4o | Best quality, multimodal (recommended) | $$$ |
gpt-4o-mini | Good quality, lower cost | $$ |
gpt-4-turbo | High quality, vision capable | $$$ |
Configuration via wp-config.php
Section titled “Configuration via wp-config.php”define( 'AI_ALT_TEXT_AI_PROVIDER', 'openai' );define( 'AI_ALT_TEXT_OPENAI_KEY', 'sk-proj-xxxxxxxxxxxxxxxxxxxx' );define( 'AI_ALT_TEXT_OPENAI_MODEL', 'gpt-4o' );define( 'AI_ALT_TEXT_OPENAI_TYPE', 'openai' ); // 'openai' or 'azure'Configuration via Environment Variables
Section titled “Configuration via Environment Variables”AI_ALT_TEXT_AI_PROVIDER=openaiAI_ALT_TEXT_OPENAI_KEY=sk-proj-xxxxxxxxxxxxxxxxxxxxAI_ALT_TEXT_OPENAI_MODEL=gpt-4oAI_ALT_TEXT_OPENAI_TYPE=openaiAPI Endpoint
Section titled “API Endpoint”POST https://api.openai.com/v1/chat/completionsAzure OpenAI
Section titled “Azure OpenAI”Requirements
Section titled “Requirements”- Azure subscription
- Azure OpenAI Service resource
- Deployed GPT-4o or GPT-4 Vision model
Setup Steps
Section titled “Setup Steps”- Create an Azure OpenAI resource in the Azure Portal
- Deploy a vision-capable model (e.g., gpt-4o)
- Copy the endpoint URL and API key
Configuration via wp-config.php
Section titled “Configuration via wp-config.php”define( 'AI_ALT_TEXT_AI_PROVIDER', 'openai' );define( 'AI_ALT_TEXT_OPENAI_TYPE', 'azure' );define( 'AI_ALT_TEXT_OPENAI_KEY', 'your-azure-api-key' );define( 'AI_ALT_TEXT_OPENAI_MODEL', 'your-deployment-name' ); // Deployment name, not model namedefine( 'AI_ALT_TEXT_AZURE_ENDPOINT', 'https://your-resource.openai.azure.com' );define( 'AI_ALT_TEXT_AZURE_API_VERSION', '2024-02-15-preview' );Configuration via Environment Variables
Section titled “Configuration via Environment Variables”AI_ALT_TEXT_AI_PROVIDER=openaiAI_ALT_TEXT_OPENAI_TYPE=azureAI_ALT_TEXT_OPENAI_KEY=your-azure-api-keyAI_ALT_TEXT_OPENAI_MODEL=your-deployment-nameAI_ALT_TEXT_AZURE_ENDPOINT=https://your-resource.openai.azure.comAI_ALT_TEXT_AZURE_API_VERSION=2024-02-15-previewAPI Endpoint Format
Section titled “API Endpoint Format”POST {endpoint}/openai/deployments/{deployment}/chat/completions?api-version={api-version}Anthropic Claude
Section titled “Anthropic Claude”Requirements
Section titled “Requirements”- Anthropic Console account
- API key from Anthropic Console
Recommended Models
Section titled “Recommended Models”| Model | Description | Cost |
|---|---|---|
claude-sonnet-4-20250514 | Best balance of quality and speed | $$$ |
claude-3-5-sonnet-20241022 | Previous generation, still excellent | $$ |
claude-3-haiku-20240307 | Fastest, lower cost | $ |
Configuration via wp-config.php
Section titled “Configuration via wp-config.php”define( 'AI_ALT_TEXT_AI_PROVIDER', 'anthropic' );define( 'AI_ALT_TEXT_ANTHROPIC_KEY', 'sk-ant-xxxxxxxxxxxxxxxxxxxx' );define( 'AI_ALT_TEXT_ANTHROPIC_MODEL', 'claude-sonnet-4-20250514' );Configuration via Environment Variables
Section titled “Configuration via Environment Variables”AI_ALT_TEXT_AI_PROVIDER=anthropicAI_ALT_TEXT_ANTHROPIC_KEY=sk-ant-xxxxxxxxxxxxxxxxxxxxAI_ALT_TEXT_ANTHROPIC_MODEL=claude-sonnet-4-20250514API Endpoint
Section titled “API Endpoint”POST https://api.anthropic.com/v1/messages- Claude requires images to be sent as base64-encoded data
- The plugin automatically handles image encoding
Google Gemini
Section titled “Google Gemini”Requirements
Section titled “Requirements”- Google account
- API key from Google AI Studio
Recommended Models
Section titled “Recommended Models”| Model | Description | Cost |
|---|---|---|
gemini-2.0-flash | Latest, fastest multimodal | Free tier available |
gemini-1.5-flash | Fast, good quality | Free tier available |
gemini-1.5-pro | Highest quality | $$ |
Configuration via wp-config.php
Section titled “Configuration via wp-config.php”define( 'AI_ALT_TEXT_AI_PROVIDER', 'gemini' );define( 'AI_ALT_TEXT_GEMINI_KEY', 'AIzaSyxxxxxxxxxxxxxxxxxxxx' );define( 'AI_ALT_TEXT_GEMINI_MODEL', 'gemini-2.0-flash' );Configuration via Environment Variables
Section titled “Configuration via Environment Variables”AI_ALT_TEXT_AI_PROVIDER=geminiAI_ALT_TEXT_GEMINI_KEY=AIzaSyxxxxxxxxxxxxxxxxxxxxAI_ALT_TEXT_GEMINI_MODEL=gemini-2.0-flashAPI Endpoint Format
Section titled “API Endpoint Format”POST https://generativelanguage.googleapis.com/v1beta/models/{model}:generateContent?key={api_key}- Gemini has a generous free tier (60 requests per minute)
- Images are sent as base64-encoded data
Ollama (Self-Hosted)
Section titled “Ollama (Self-Hosted)”Requirements
Section titled “Requirements”- Ollama installed locally or on a server
- A vision-capable model pulled (e.g., llava)
Installation
Section titled “Installation”# macOSbrew install ollama
# Linuxcurl -fsSL https://ollama.ai/install.sh | sh
# Start Ollama serverollama serve
# Pull a vision modelollama pull llavaRecommended Models
Section titled “Recommended Models”| Model | Description | Size |
|---|---|---|
llava | LLaVA 7B, good quality | 4.7 GB |
llava:13b | LLaVA 13B, better quality | 8.0 GB |
bakllava | BakLLaVA, alternative | 4.7 GB |
llava-llama3 | LLaVA with Llama 3 | 5.5 GB |
Configuration via wp-config.php
Section titled “Configuration via wp-config.php”define( 'AI_ALT_TEXT_AI_PROVIDER', 'ollama' );define( 'AI_ALT_TEXT_OLLAMA_ENDPOINT', 'http://localhost:11434' );define( 'AI_ALT_TEXT_OLLAMA_MODEL', 'llava' );Configuration via Environment Variables
Section titled “Configuration via Environment Variables”AI_ALT_TEXT_AI_PROVIDER=ollamaAI_ALT_TEXT_OLLAMA_ENDPOINT=http://localhost:11434AI_ALT_TEXT_OLLAMA_MODEL=llavaAPI Endpoint Format
Section titled “API Endpoint Format”POST {endpoint}/api/generate- Free - No API costs, runs entirely locally
- Requires local installation of Ollama
- Processing speed depends on your hardware (GPU recommended)
- For Docker deployments, use
http://host.docker.internal:11434
Running Ollama on a Remote Server
Section titled “Running Ollama on a Remote Server”If WordPress runs on a different server than Ollama:
define( 'AI_ALT_TEXT_OLLAMA_ENDPOINT', 'http://your-server-ip:11434' );Make sure the Ollama server is accessible from your WordPress server.
Grok (xAI)
Section titled “Grok (xAI)”Requirements
Section titled “Requirements”- xAI account
- API key from xAI Console
Recommended Models
Section titled “Recommended Models”| Model | Description | Cost |
|---|---|---|
grok-2-vision-1212 | Vision-capable Grok 2 | $$ |
grok-vision-beta | Beta vision model | $$ |
Configuration via wp-config.php
Section titled “Configuration via wp-config.php”define( 'AI_ALT_TEXT_AI_PROVIDER', 'grok' );define( 'AI_ALT_TEXT_GROK_KEY', 'xai-xxxxxxxxxxxxxxxxxxxx' );define( 'AI_ALT_TEXT_GROK_MODEL', 'grok-2-vision-1212' );Configuration via Environment Variables
Section titled “Configuration via Environment Variables”AI_ALT_TEXT_AI_PROVIDER=grokAI_ALT_TEXT_GROK_KEY=xai-xxxxxxxxxxxxxxxxxxxxAI_ALT_TEXT_GROK_MODEL=grok-2-vision-1212API Endpoint
Section titled “API Endpoint”POST https://api.x.ai/v1/chat/completions- Grok uses an OpenAI-compatible API format
- Vision capabilities are available in Grok 2
Environment Variables Reference
Section titled “Environment Variables Reference”| Variable | Description | Default |
|---|---|---|
AI_ALT_TEXT_AI_PROVIDER | Provider: openai, anthropic, gemini, ollama, grok | openai |
AI_ALT_TEXT_AUTO_GENERATE | Auto-generate on upload: 1 or 0 | 1 |
AI_ALT_TEXT_OPENAI_TYPE | OpenAI type: openai or azure | openai |
AI_ALT_TEXT_OPENAI_KEY | OpenAI/Azure API key | (none) |
AI_ALT_TEXT_OPENAI_MODEL | OpenAI model or Azure deployment name | gpt-4o |
AI_ALT_TEXT_AZURE_ENDPOINT | Azure OpenAI endpoint URL | (none) |
AI_ALT_TEXT_AZURE_API_VERSION | Azure API version | 2024-02-15-preview |
AI_ALT_TEXT_ANTHROPIC_KEY | Anthropic API key | (none) |
AI_ALT_TEXT_ANTHROPIC_MODEL | Anthropic model name | claude-3-5-sonnet-20241022 |
AI_ALT_TEXT_GEMINI_KEY | Google AI API key | (none) |
AI_ALT_TEXT_GEMINI_MODEL | Gemini model name | gemini-1.5-flash |
AI_ALT_TEXT_OLLAMA_ENDPOINT | Ollama server URL | http://localhost:11434 |
AI_ALT_TEXT_OLLAMA_MODEL | Ollama model name | llava |
AI_ALT_TEXT_GROK_KEY | xAI API key | (none) |
AI_ALT_TEXT_GROK_MODEL | Grok model name | grok-2-vision-1212 |
Constants Reference
Section titled “Constants Reference”All environment variables can also be defined as PHP constants in wp-config.php using the same names:
// Example: Full configuration for OpenAIdefine( 'AI_ALT_TEXT_AI_PROVIDER', 'openai' );define( 'AI_ALT_TEXT_AUTO_GENERATE', '1' );define( 'AI_ALT_TEXT_OPENAI_KEY', 'sk-proj-xxxx' );define( 'AI_ALT_TEXT_OPENAI_MODEL', 'gpt-4o' );Troubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues””Configuration is incomplete”
Section titled “”Configuration is incomplete””- Ensure you’ve set both the API key and model for your chosen provider
- Check that constants/environment variables are spelled correctly
”Unknown AI provider”
Section titled “”Unknown AI provider””- Valid providers:
openai,anthropic,gemini,ollama,grok - Check for typos in the provider name
”Failed to fetch image”
Section titled “”Failed to fetch image””- Ensure the image URL is accessible
- For local images, check file permissions
- For remote images, ensure the server allows external requests
Azure: “Resource not found”
Section titled “Azure: “Resource not found””- Verify the endpoint URL is correct (no trailing slash)
- Ensure the deployment name matches exactly
- Check the API version is supported
Ollama: “Connection refused”
Section titled “Ollama: “Connection refused””- Ensure Ollama is running:
ollama serve - Check the endpoint URL (default:
http://localhost:11434) - Verify the model is pulled:
ollama list
Enable Debug Logging
Section titled “Enable Debug Logging”Add to wp-config.php:
define( 'WP_DEBUG', true );define( 'WP_DEBUG_LOG', true );define( 'WP_DEBUG_DISPLAY', false );Logs are written to wp-content/debug.log.
Testing API Connection
Section titled “Testing API Connection”The plugin validates your configuration when you save settings. If there’s an error, you’ll see a warning message with details.
You can also test manually with curl:
# Test OpenAIcurl https://api.openai.com/v1/models \ -H "Authorization: Bearer sk-proj-xxxx"
# Test Anthropiccurl https://api.anthropic.com/v1/messages \ -H "x-api-key: sk-ant-xxxx" \ -H "anthropic-version: 2023-06-01"
# Test Ollamacurl http://localhost:11434/api/tags
# Test Geminicurl "https://generativelanguage.googleapis.com/v1beta/models?key=AIzaSy-xxxx"
# Test Grokcurl https://api.x.ai/v1/models \ -H "Authorization: Bearer xai-xxxx"📦 Source: soderlind/ai-alt-text · Edit on GitHub