You can install the package via composer:
composer require spatie/laravel-url-ai-transformer
Upgrading from v1? Follow the upgrade guide before updating the package.
##Publishing the config file
Optionally, you can publish the config file with this command:
php artisan vendor:publish --tag="url-ai-transformer-config"
This is the content of the published config file:
return [
'ai' => [
'provider' => Laravel\Ai\Enums\Lab::OpenAI,
'model' => Spatie\LaravelUrlAiTransformer\Enums\Model::Cheapest,
],
'model' => Spatie\LaravelUrlAiTransformer\Models\TransformationResult::class,
'actions' => [
'fetch_url_content' => Spatie\LaravelUrlAiTransformer\Actions\FetchUrlContentAction::class,
'prepare_url_content' => Spatie\LaravelUrlAiTransformer\Actions\PrepareUrlContentAction::class,
'process_registration' => Spatie\LaravelUrlAiTransformer\Actions\ProcessRegistrationAction::class,
],
'process_transformer_job' => Spatie\LaravelUrlAiTransformer\Jobs\ProcessTransformerJob::class,
];
##Migrating the database
This package stores transformation results in the database. To create the transformation_results table, you must publish and run the migration.
php artisan vendor:publish --tag="url-ai-transformer-migrations"
php artisan migrate
##Configuring AI providers
This package uses the official Laravel AI package under the hood to interact with various AI services. It provides a unified interface for working with different AI providers.
By default, the package is configured to use OpenAI. To get started, you'll need to add your OpenAI API key to your .env file:
OPENAI_API_KEY=your-api-key-here
##Using different AI providers
Laravel AI supports multiple providers including OpenAI, Anthropic Claude, Google Gemini, and more. Providers are represented by the Laravel\Ai\Enums\Lab enum. You can switch providers by updating the config file:
'ai' => [
'provider' => Laravel\Ai\Enums\Lab::Anthropic,
'model' => 'claude-haiku-4-5-20251001',
],
Don't forget to add the corresponding API key to your .env file:
ANTHROPIC_API_KEY=your-api-key-here
GEMINI_API_KEY=your-api-key-here
For more information about configuring providers, check out the Laravel AI documentation.