Frequently asked questions
What is darvis/laravel-ai-generator?
A Laravel package that writes structured content with Claude, ChatGPT, Gemini or Grok. You pass a ContentRequest with a topic and get a ContentResult with a title, a plain text intro, the main text as HTML, an SEO title, a meta description and optionally an image. It has no screens, routes or database tables; you call it from your own code and store the result yourself.
How do I generate a blog post with AI in a Laravel application?
Run composer require darvis/laravel-ai-generator and php artisan ai-generator:install to set the API key of Claude, ChatGPT, Gemini or Grok, then call AiGenerator::generate(new ContentRequest(topic: 'Your topic', includeImage: false)) on the facade Darvis\LaravelAiGenerator\Facades\AiGenerator. The result has title, intro, text as HTML with h2, p and list tags, seoTitle and seoDescription.
What do I need to use darvis/laravel-ai-generator, and what does it cost?
PHP 8.2 or higher, Laravel 11, 12 or 13, and an API key of at least one provider: Anthropic (Claude), OpenAI (ChatGPT), Google (Gemini) or xAI (Grok). The package is free and MIT licensed. The provider bills every call to your own account. Run php artisan ai-generator:install to set up the keys.
Does my ChatGPT Plus or Claude Pro subscription work with this package?
No. A chat subscription such as ChatGPT Plus, Claude Pro, Google AI Pro or SuperGrok does not include API access. You create a developer account at the provider, load credits or add billing, and create an API key there. The API keys page of the documentation shows the steps per provider.
Can I use Claude and ChatGPT together?
Yes. Put both keys in .env, set AI_GENERATOR_DRIVER=anthropic so Claude writes, and OpenAI makes the images because Claude cannot. Add AI_GENERATOR_FALLBACKS=openai to let OpenAI write when Claude fails, and use AiGenerator::using('openai') to pick a provider for one call. The wizard sets this up for you.
Which provider makes the images?
The driver in AI_GENERATOR_IMAGE_DRIVER when you set it: openai, gemini or xai. Otherwise the text driver when it can make images, and OpenAI when it cannot. Claude has no image model, so with Claude as text driver the image comes from OpenAI and needs OPENAI_API_KEY.
Do I need MCP to use darvis/laravel-ai-generator?
No. MCP is an extra that lets an assistant such as Claude Code generate content through your app. Install laravel/mcp (Laravel 12.41 or newer) and the package registers a local server by itself; connect it with claude mcp add ai-generator -- php artisan mcp:start ai-generator.
Does every request also generate an image?
Yes, unless you say otherwise. includeImage is true by default, which means a second, billed call to the image provider after the text. Pass includeImage: false when you only want text. For an image without text, use generateImage().
Which languages can darvis/laravel-ai-generator write in?
The language is an instruction in the prompt, so it depends on the model. Pass an ISO 639-1 code such as en, de or fr as language, or set AI_GENERATOR_LANGUAGE for the default, which is nl. For Dutch, German and French the prompt also names the form of address that fits the tone, for example je/jij or Sie.
Can I use a provider or a local model the package does not ship?
Yes, for the text. Write a class that implements AiContentDriver and register it with app(AiGeneratorManager::class)->extend('name', fn () => new YourDriver); the custom drivers page shows the exact code. Images then come from OpenAI, or from the driver in AI_GENERATOR_IMAGE_DRIVER.
Is it safe to output the generated HTML directly in a Blade view?
Treat it as untrusted input. The text field is HTML written by a language model, and the package does not sanitise it. Run it through an HTML sanitiser with an allow list before you render it unescaped.
What happens when the AI provider fails?
A failing text call is tried twice and then throws a RuntimeException, for example Claude request failed: .... With AI_GENERATOR_FALLBACKS set, the next provider is tried first. A failing image call does not throw. You then get the text with errorMessage filled in and hasError() returning true, so check that before you save the result as complete.
How do I generate many articles in Laravel without timeouts?
Put each generate() call in a queued job. Every request inside generate() waits up to the timeout of its provider, 45 seconds by default, and is tried twice, and an image adds a second request. Give the job a $timeout above that; the usage page has a job example.
How do I test code that uses darvis/laravel-ai-generator without calling a real AI API?
Bind a fake AiContentDriver in the test that returns a fixed ContentResult, or use Http::fake() with an answer in the shape of the provider’s API. Add Http::preventStrayRequests() so a forgotten fake fails the test. The testing page has complete examples.