spatie/laravel-url-ai-transformer
Laravel package to transform URLs and their web content with AI. Extract structured data (JSON-LD), generate summaries, images, or custom outputs via transformers and prompts. Runs via an Artisan command and stores results in the database for later retrieval.
Transformer base class, enabling tailored AI-driven transformations (e.g., summarization, structured data extraction).Prism (a Laravel AI wrapper), allowing easy swapping of models/providers.transformation_results table, enabling querying, caching, and retries.transform-urls for CLI execution, ideal for scheduled jobs (e.g., cron).TransformationCompleted) for post-processing (e.g., indexing, notifications).| Risk Area | Mitigation Strategy |
|---|---|
| AI Costs | Implement rate-limiting, caching, or conditional triggers (e.g., only transform changed URLs). |
| URL Fetching Limits | Configure HttpClient timeouts/retry logic; use shouldRun() to skip stale URLs. |
| Transformer Errors | Leverage latest_exception_* fields for debugging; implement retry logic in custom jobs. |
| Database Bloat | Archive old results or use soft deletes; add TTL policies for transient data. |
| AI Provider Lock-in | Abstract Prism calls behind interfaces for easier provider swaps. |
spatie/laravel-prism (supports OpenAI, Anthropic, etc.).transformation_results.composer require spatie/laravel-url-ai-transformer
php artisan vendor:publish --provider="Spatie\LaravelUrlAiTransformer\UrlAiTransformerServiceProvider"
AI_PROVIDER and AI_MODEL in .env (e.g., AI_PROVIDER=openai).prism.php for API keys/endpoints.php artisan migrate to create transformation_results table.Transform::urls('https://example.com/*')->usingTransformers(new LdJsonTransformer);
app/Console/Kernel.php:
$schedule->command('transform-urls')->daily();
spatie/laravel-prism (v1.0+).SummaryTransformer).ProcessTransformerJob).php artisan transform-urls --now.02:00 daily).latest_exception_seen_at).spatie/laravel-prism and spatie/laravel-url-ai-transformer for updates..env or a secrets manager.log channel for structured logging.transformation_results for failed jobs:
SELECT * FROM transformation_results
WHERE latest_exception_seen_at IS NOT NULL
ORDER BY latest_exception_seen_at DESC;
$result->regenerate()).| Failure Mode | Impact | Mitigation Strategy |
|---|---|---|
| AI Provider Outage | Transformations fail | Implement fallback models or retry logic. |
| Queue Worker Crash | Jobs pile up | Use failed_jobs table + Supervisor to restart workers. |
| Database Locks | Slow transformations | Optimize queries; use database connection pooling. |
| Rate Limiting | AI provider throttles requests | Implement exponential backoff in custom jobs. |
| Malformed URLs | Invalid data in result field |
Validate URLs before transformation; use shouldRun() to skip invalid ones. |
| Transformer Bugs | Corrupted output | Unit test custom transformers; use regenerate() to overwrite bad results. |
getPrompt() patterns).latest_exception_message).How can I help you explore Laravel packages today?