AI Provider Setup
All AI calls go through one service -- AiService. Point it at OpenAI or Anthropic and everything works: content generation, SEO analysis, accessibility checks, image comparison, the chat assistant.
Supported providers
| Provider | Key | Env prefix |
|---|---|---|
| OpenAI | openai |
OPENAI_ |
| Anthropic Claude | anthropic |
ANTHROPIC_ |
Both handle text, chat, vision, and tool calls.
Quick start
OpenAI
TEXTSTEM_AI_PROVIDER=openai
OPENAI_API_KEY=sk-...
OPENAI_MODEL=gpt-4o-mini
Anthropic
TEXTSTEM_AI_PROVIDER=anthropic
ANTHROPIC_API_KEY=sk-ant-...
ANTHROPIC_MODEL=claude-haiku-4-5-20251001
TEXTSTEM_AI_PROVIDER decides which one runs. If you have keys for both, only the active provider is used.
Configuration
Active provider
TEXTSTEM_AI_PROVIDER=openai # 'openai' or 'anthropic' (default: openai)
TEXTSTEM_AI_MODEL= # blank = use the provider's default
TEXTSTEM_AI_MODEL overrides the model for everything. Leave it blank and it falls back to OPENAI_MODEL or ANTHROPIC_MODEL.
TEXTSTEM_AI_PROVIDER defaults to openai. Only when it is empty (or names a provider that isn't registered) is the provider picked from the model name: gpt-, o1 and o3 models go to OpenAI, claude- models to Anthropic, and anything else to the first registered provider.
OpenAI
OPENAI_API_KEY=sk-...
OPENAI_MODEL=gpt-4o-mini
OPENAI_USE_QUEUE=true # default: true
Get a key at platform.openai.com.
OPENAI_ENABLED no longer turns anything on or off. To turn AI off, use the master switch in Settings > AI Configuration (see When AI features appear).
Anthropic
ANTHROPIC_API_KEY=sk-ant-...
ANTHROPIC_MODEL=claude-haiku-4-5-20251001
Get a key at console.anthropic.com.
When AI features appear
An AI button, option or check appears, and an AI job runs, only when AI is available. AI is available when both of these are true:
- AI enabled, the master switch in Settings > AI Configuration, is on. It is on until someone turns it off.
- The selected provider (
TEXTSTEM_AI_PROVIDER) has an API key. For OpenAI that isOPENAI_API_KEY. For Anthropic it isANTHROPIC_API_KEY. A key for the other provider doesn't count.
In code, this is AiService::isAvailable(). Ask it through the container (app(AiService::class)->isAvailable()) so tests can fake it.
When AI isn't available:
- AI buttons and options are hidden: Generate description, Generate keywords, Suggest tags, the chat assistant, and the AI options and fixes in Tools > Deployment Checks.
- Checks that can work without AI run their built-in part only. This covers the page analyser, the accessibility and SEO checks and the placeholder-text check.
- Where a screen says why AI is off, it gives one of two reasons. Either AI is switched off in AI settings, or the selected provider has no API key (and it names the
.envsetting).AiService::unavailableReason()gives this message.
Some features also have their own switch. The feature appears only when its switch is on and AI is available:
| Switch | Turns on |
|---|---|
textstemapp.openai.generate_description |
Generate description on pages and images |
SEO_USE_AI |
The AI part of SEO analysis |
| Alt text on image upload and the other automatic actions in AI settings | That automatic action |
textstemapp.images.comparison_driver=openai |
AI image duplicate checks |
The textstemapp.openai.* feature switches (generate_description, use_queue and the others) apply to whichever provider is selected. They keep the openai name so existing config and .env files still work.
No feature needs a particular provider. OpenAI and Anthropic both handle text, vision (alt text and image comparison) and the chat assistant's tools.
What uses AI
With a provider configured:
- Content generation -- article body, descriptions, teasers, tags
- Alt text -- generated when you upload an image, or with Generate description on an image's edit page. Images are decoded with the driver in
textstemapp.glide.driver(GD if Imagick isn't installed). Images over 40 megapixels or 30 MB, SVGs and formats the driver can't read are skipped with a message - Summary and keywords -- Generate description and Generate keywords under a page's or post's Summary and Keywords read the saved page's rendered text, or the post's title and content, and put the result in the field. Nothing is saved until you save the page or post, so you can edit it first. They run straight away, whatever
OPENAI_USE_QUEUEsays. If there's no text yet, the AI isn't set up, doesn't answer or returns nothing, a message says so and the field is left as it was - Structured data -- Generate JSON-LD in a page's Structured data panel reads the saved page's title, address, summary and rendered text, with the organisation details in
config/structured-data.php, and puts Schema.org JSON-LD in the field. It replaces what the field held, but nothing is saved until you save the page, so you can check it first. It runs straight away, whateverOPENAI_USE_QUEUEsays. If there's no text yet, the AI isn't set up, doesn't answer, or replies with something that isn't JSON-LD (an object with@typeor@graph, or a list of objects with@type), a message says so and the field is left as it was. The organisation defaults to the app's name; publish the config withphp artisan vendor:publish --tag=structured-datato fill in the rest - Tag suggestions -- Suggest tags in the Tags panel of a post, page or asset reads the post's title and content, the page's rendered text or the asset's description, and puts up to 10 tags it doesn't already have in the new-tag box for you to accept with Enter. It runs straight away, whatever
OPENAI_USE_QUEUEsays. If there's no text yet, the AI isn't set up or doesn't answer, or it suggests nothing new, a message says so and the box is left as it was - Deployment Checks fixes -- in Tools > Deployment Checks, after a scan, a super admin can fill in missing page descriptions and missing image alt text. With
OPENAI_USE_QUEUEon, they're queued and the tool says how many; with it off, they're written straight away and the tool says how many were written. Pages that have any description by then (one the scan flagged as too short is kept), pages with no text, and pages the person may not change (a live page needs a publisher) are skipped and counted, and a page or image the AI fails on doesn't stop the rest - SEO analysis -- scored and annotated (see
SEO_USE_AI) - Accessibility analysis -- WCAG 2.1 checks against the live page HTML
- Image duplicates -- vision comparison on upload (requires
textstemapp.images.comparison_driver=openai; defaults to fingerprint matching). Despite the driver's name, it uses whichever provider is selected - Chat assistant -- admin panel chat that can read and write content
Disable anything you don't need -- see the SEO and accessibility docs.
Queue
Jobs run through the queue by default. You need a worker running. Buttons where you wait for the answer always run straight away instead: Generate description on an image, page or post, Generate keywords, Generate JSON-LD and Suggest tags. Start a worker with:
php artisan queue:work
Create post on a content suggestion is queued too: the editor waits on a page that opens the post when its article arrives. If the job fails, the page says so and offers the post without the article. If nothing arrives for two minutes, it says the queue worker may not be running and keeps checking. The failure is passed through the cache, so the web server and the worker must share a cache store (any store but array).
To run synchronously (development only):
OPENAI_USE_QUEUE=false
ACCESSIBILITY_USE_QUEUE=false
SEO_USE_QUEUE=false
Usage tracking
Every call is logged to ai_token_usage -- provider, model, feature, token counts, cost. Find it in the admin panel under Tools > OpenAI Usage, or query it directly. Despite its name, the tool shows calls to every provider.
Custom providers
Implement Medialight\Textstem\Orchestration\Providers\LlmProvider (key(), complete(), chat(), supportsModel(), defaultModel() and isConfigured()) and register it:
use Medialight\Textstem\Orchestration\Providers\LlmProviderRegistry;
$this->app->resolving(LlmProviderRegistry::class, function (LlmProviderRegistry $registry) {
$registry->register(new MyCustomProvider());
});
Set TEXTSTEM_AI_PROVIDER to whatever key() returns.