Search by

lmsomeco / laravel-ai-models

npeltoniemi

List and cache the currently-available models for each provider configured in the Laravel AI SDK.

Package info

github.com/lmandcreative/laravel-ai-models

pkg:composer/lmsomeco/laravel-ai-models

Statistics

Installs: 75

Dependents: 0

Suggesters: 0

Stars: 5

Open Issues: 0

v2.0.0 2026-10-29 10:30 UTC

This package is auto-updated.

Last update: 2026-10-29 10:33:07 UTC


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 (use lmsomeco/laravel-ai-models ^1.0 for laravel/ai 0.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:models command and the full facade/DI API
  • Database connectors — optional DB-backed provider configs, built as on-demand laravel/ai providers
  • 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.