Skip to main content
AI Translations for Laravel supports three major LLM providers. You can configure which provider to use and customize the models for different use cases.

Selecting a provider

Set the active provider in your config/ai-translations.php file:
'provider' => 'anthropic', // Options: 'openai', 'anthropic', 'gemini'
Or use the environment variable in your .env file:
AI_TRANSLATIONS_PROVIDER=anthropic
The default provider is Gemini, which offers a good balance of speed, quality, and cost.

Provider configuration

OpenAI setup

OpenAI provides high-quality translations with models like GPT-4 and GPT-5.

Environment variables

Add these variables to your .env file:
.env
OPENAI_API_KEY=sk-proj-...

Configuration

Configure OpenAI in config/ai-translations.php:
'provider' => 'openai',
'openai' => [
    'model' => 'gpt-5-mini',
    'fast_model' => 'gpt-5-nano',
    'api_key' => env('OPENAI_API_KEY'),
],

Available models

openai.model
string
default:"gpt-5-mini"
The primary model used for standard translations. Recommended options:
  • gpt-5-mini - Latest efficient model (default)
  • gpt-4o - Previous generation flagship model
  • gpt-4-turbo - Faster GPT-4 variant
openai.fast_model
string
default:"gpt-5-nano"
The model used when running with the --fast flag. Optimized for speed and cost:
  • gpt-5-nano - Ultra-fast model (default)
  • gpt-4o-mini - Compact but capable
openai.api_key
string
required
Your OpenAI API key. Get one from platform.openai.com.

Getting an API key

  1. Sign up at platform.openai.com
  2. Navigate to API keys section
  3. Create a new secret key
  4. Add the key to your .env file
Keep your API key secure. Never commit it to version control.

Fast mode

When you run the translate command with the --fast flag, the package automatically switches to the configured fast_model:
php artisan translate --fast
Fast models are:
  • More cost-effective
  • Faster to respond
  • Slightly less precise for complex translations
Use fast mode for large translation jobs or when iterating quickly. Use standard models for production translations where quality is critical.

Model selection best practices

For production translations

  • OpenAI: gpt-5-mini or gpt-4o
  • Anthropic: claude-sonnet-4-5 or claude-opus-4
  • Gemini: gemini-flash-latest or gemini-pro-latest

For development or large batches

  • OpenAI: gpt-5-nano or gpt-4o-mini
  • Anthropic: claude-haiku-4-5
  • Gemini: gemini-flash-lite-latest

Troubleshooting

Invalid API key error

If you receive an authentication error:
  1. Verify your API key is correctly set in .env
  2. Ensure there are no extra spaces or quotes around the key
  3. Check that you’ve cleared the config cache: php artisan config:clear
  4. Verify your API key is active in the provider’s console

Provider not found

If you see a “Invalid provider” error:
  1. Verify the provider setting in config/ai-translations.php
  2. Ensure it’s one of: openai, anthropic, or gemini
  3. Clear the config cache: php artisan config:clear

Next steps

Configure languages

Set up which languages to translate

Build docs developers (and LLMs) love