lmsomeco / laravel-ai-models
List and cache the currently-available models for each provider configured in the Laravel AI SDK.
Requires
- php: ^8.3
- illuminate/console: ^12.0|^13.0
- illuminate/database: ^12.0|^13.0
- illuminate/http: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
- laravel/ai: ^1.0.1
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.24
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^3.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A companion package for the Laravel AI SDK (laravel/ai)
that lists and caches the currently-available models for each provider you have
configured. It reads your credentials straight from config/ai.php and keys
everything on the SDK's own Laravel\Ai\Enums\Lab enum, so there's nothing to
configure twice.
Requirements
- PHP 8.3+
laravel/ai^1.0.1 (uselmsomeco/laravel-ai-models^1.0 forlaravel/ai0.x — see UPGRADE.md)
Install
composer require lmsomeco/laravel-ai-models php artisan vendor:publish --tag=ai-models-config # optional php artisan vendor:publish --tag=ai-models-migrations # only if using database connectors
Any provider with credentials already set in config/ai.php is picked up
automatically — no extra keys or env vars.
Usage
Artisan
php artisan ai:models # every configured provider php artisan ai:models openai # one provider (a Lab value) php artisan ai:models --refresh # bypass the cache php artisan ai:models openrouter --json
Facade / service
use Laravel\Ai\Ai; use Laravel\Ai\Enums\Lab; use LmSomeco\AiModels\Facades\AiModels; AiModels::all(); // Collection<AiModel> AiModels::provider(Lab::Anthropic); // accepts a Lab or its string value AiModels::configuredProviders(); // Collection<int, string> of provider names AiModels::refresh(); // clear all cached lists AiModels::refresh(Lab::Groq); // clear one AiModels::failures(); // providers the last all() call skipped // Any laravel/ai provider instance, including on-demand ones from Ai::build() AiModels::for(Ai::build(['driver' => 'openai', 'key' => $tenantKey])); $model = AiModels::provider(Lab::OpenAI)->firstWhere('id', 'gpt-4o'); $model->provider; // Laravel\Ai\Enums\Lab::OpenAI $model->id; // 'gpt-4o' $model->contextWindow; // int|null $model->modalities; // input modalities; [] when unknown $model->outputModalities; // output modalities; [] when unknown $model->raw; // untouched provider payload
Registry methods return Laravel collections, so model properties and modality helpers can be used directly when filtering:
$models = AiModels::all()->filter( fn ($model) => $model->outputModalities === ['text'], );
This strict form also excludes models whose output capabilities are unknown.
The ModelRegistry is resolvable from the container if you prefer DI over the
facade.
all() reports and skips a provider whose listing fails over HTTP (e.g. an
Ollama server that isn't running) instead of failing the whole call; the
skipped providers are available from failures(), and ai:models prints a
warning for each.
Provider coverage
Provider (Lab) |
Resolver | Status |
|---|---|---|
OpenAI |
OpenAiResolver |
✅ live (catalog-enriched modalities) |
OpenAICompatible |
OpenAiCompatibleResolver |
✅ live (needs a url; key optional) |
Groq |
OpenAiCompatibleResolver |
✅ live |
Mistral |
OpenAiCompatibleResolver |
✅ live |
DeepSeek |
OpenAiCompatibleResolver |
✅ live |
xAI |
OpenAiCompatibleResolver |
✅ live |
OpenRouter |
OpenRouterResolver |
✅ live (rich metadata, no key needed) |
Anthropic |
AnthropicResolver |
✅ live |
Gemini |
GeminiResolver |
✅ live (token limits, family-derived modalities) |
Cohere |
CohereResolver |
✅ live (context length, endpoint-derived modalities) |
Ollama |
OllamaResolver |
✅ live (locally pulled models; key optional) |
| Azure, ElevenLabs, Bedrock, Jina, VoyageAI, TypeSafe | — | ⏳ not yet implemented |
See docs/extending.md for per-provider notes and how to
add a resolver — contributions welcome.
Documentation
- Installation — publish tags, env vars, how credentials are read
- Usage — the
ai:modelscommand and the full facade/DI API - Database connectors — optional DB-backed provider configs, built as on-demand
laravel/aiproviders - Caching — cache keys, TTL and busting
- Extending — writing your own
ProviderResolver
Upgrading
See UPGRADE.md for upgrading from 1.x to 2.0.
License
MIT.