Skip to content

Fix OpenRouter via laravel/ai default provider (revises #216) - #220

Closed
paulocastellano wants to merge 1 commit into
mainfrom
cursor/fix-openrouter-ai-provider-031b
Closed

Fix OpenRouter via laravel/ai default provider (revises #216)#220
paulocastellano wants to merge 1 commit into
mainfrom
cursor/fix-openrouter-ai-provider-031b

Conversation

@paulocastellano

Copy link
Copy Markdown
Contributor

Supersedes / revises #216.

Why

#216 added 'openrouter' => Lab::OpenRouter to every agent provider() match. That works on the surface, but:

  1. laravel/ai already supports OpenRouter as a first-class driver (Lab::OpenRouter, createOpenrouterDriver, config/ai.php provider entry). When an agent omits provider(), Promptable falls back to config('ai.default').
  2. The duplicated matches were the real bug: anything other than openai/anthropic was forced to Gemini, so AI_TEXT_PROVIDER=openrouter never reached OpenRouter.
  3. add openrouter to eligible ai providers #216’s BrandAnalyzerRunner check used config('services.openrouter.api_key'), which does not exist — so brand autofill would still treat OpenRouter as unavailable.

As noted in #216, the better fix is to stop hardcoding provider maps in every agent.

What changed

  • Removed provider() from all AI agents so they use config('ai.default') (supports openrouter, openai, anthropic, gemini, etc.).
  • Added App\Support\AiConfiguration::isTextProviderConfigured() reading ai.providers.{default}.key.
  • Wired BrandAnalyzerRunner::isAvailable() and shared aiEnabled through that helper.
  • Documented OPENROUTER_API_KEY / openrouter in .env.example.
  • Tests for OpenRouter availability and that agents no longer override provider().

Setup for OpenRouter

AI_TEXT_PROVIDER=openrouter
AI_TEXT_MODEL=openai/gpt-4o-mini
OPENROUTER_API_KEY=sk-or-v1-...

Closes #216 once merged (or we can close #216 manually in favor of this).

Open in Web Open in Cursor 

PR #216 patched Lab::OpenRouter into every agent match, but laravel/ai
already resolves config('ai.default') — including openrouter — when agents
omit provider(). Those matches also forced unknown providers to Gemini and
BrandAnalyzerRunner checked a non-existent services.openrouter key.

Remove the duplicated provider() overrides, gate availability on
ai.providers.*.key, and document OPENROUTER_API_KEY.

Co-authored-by: Paulo Castellano <hello@paulocastellano.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants