# Models

**Package:** Anthropic Laravel | **Version:** 1 | **URL:** https://mozex.dev/docs/anthropic-laravel/v1/usage/models

---

List available Claude models or retrieve a specific one. Useful for model selectors, availability checks, or programmatic discovery.

## Listing models

```php
use Anthropic\Laravel\Facades\Anthropic;

$response = Anthropic::models()->list();

foreach ($response->data as $model) {
    $model->id;             // 'claude-sonnet-5-5'
    $model->displayName;    // 'Claude Sonnet 5.5'
    $model->createdAt;      // '2026-09-28T00:00:00Z'
    $model->maxInputTokens; // 1000000
    $model->maxTokens;      // 128000
}
```

Response includes pagination metadata:

```php
$response->firstId; // 'claude-haiku-5-5'
$response->lastId;  // 'claude-haiku-4-5-20251001'
$response->hasMore; // true
```

## Pagination

Default limit is 20, max is 1000. Use `after_id` for forward pagination and `before_id` for backward:

```php
$page1 = Anthropic::models()->list(['limit' => 5]);

if ($page1->hasMore) {
    $page2 = Anthropic::models()->list([
        'limit' => 5,
        'after_id' => $page1->lastId,
    ]);
}
```

`iterate()` walks every page for you and yields one model at a time, requesting each page only when the loop gets there. Wrap it in a `LazyCollection` for the collection methods:

```php
use Illuminate\Support\LazyCollection;

$sonnets = LazyCollection::make(fn () => Anthropic::models()->iterate(['limit' => 100]))
    ->where('line', 'sonnet')
    ->pluck('id')
    ->all();
```

Each pass over a `LazyCollection` runs the requests again, so end the chain with `->all()` when you use the result more than once.

The list holds active and deprecated models. Pass `lifecycle` to pick the stages, such as `['lifecycle' => ['retired']]` for the retired ones, which only show up when asked for.

## Building a model selector

`cached()` keeps every model in the cache, so you're not hitting the API on every request:

```php
$models = Anthropic::models()->cached();

// In a Blade form
<select name="model">
    @foreach ($models as $model)
        <option value="{{ $model->id }}">{{ $model->displayName }}</option>
    @endforeach
</select>
```

It's built on `Cache::flexible()`: fresh for an hour, then served for up to a day while it's fetched again after the response (`cached([600, 3600])` sets both). The cache is per connection, and per key for `Anthropic::withApiKey()`, since keys can see different models. Under `Anthropic::fake()` it's never cached. `php artisan anthropic:models` prints the same list with each model's input limit and lifecycle.

## Retrieving a single model

```php
$response = Anthropic::models()->retrieve('claude-sonnet-5-5');

$response->id;             // 'claude-sonnet-5-5'
$response->displayName;    // 'Claude Sonnet 5.5'
$response->createdAt;      // '2026-09-28T00:00:00Z'
$response->maxInputTokens; // 1000000
$response->maxTokens;      // 128000
```

`maxInputTokens`, `maxTokens` and `capabilities` can be `null`, so give them a fallback.

## Catching retirements early

Each model reports its `lifecycle` (`'active'`, `'deprecated'` or `'retired'`), its family `line` (`'sonnet'`, `'opus'` ...), and `deprecatedAt` and `retiresAt` dates. A scheduled check warns you before a model your app uses stops answering:

```php
// routes/console.php
use Anthropic\Laravel\Facades\Anthropic;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Schedule;

Schedule::call(function () {
    foreach (config('services.anthropic.models', ['claude-sonnet-5-5']) as $id) {
        $model = Anthropic::models()->retrieve($id);

        if ($model->isRetiring() || $model->isRetired()) {
            Log::warning('Claude model is being retired', [
                'model' => $model->id,
                'lifecycle' => $model->lifecycle,
                'retires_on' => $model->retirementDate()?->format('Y-m-d'),
            ]);
        }
    }
})->daily();
```

`isRetiring()` is true for a deprecated model, which still answers, and `isRetired()` for a retired one. A deprecated model whose date has passed is overdue (`isRetirementOverdue()`): it may stop answering at any time. `php artisan anthropic:doctor` runs the same check on your `fallback_models` (see [Diagnostics](https://mozex.dev/docs/anthropic-laravel/v1/reference/diagnostics)).

To move to a new model gradually, let [Pennant](https://laravel.com/docs/pennant) pick it per user, then finish or undo the rollout without a deploy, with `Feature::activateForEveryone('claude-sonnet-5-5')` or `deactivateForEveryone()`:

```php
use Anthropic\Laravel\Facades\Anthropic;
use App\Models\User;
use Illuminate\Support\Lottery;
use Laravel\Pennant\Feature;

// AppServiceProvider::boot()
Feature::define('claude-sonnet-5-5', fn (User $user) => Lottery::odds(1, 10)->choose());

// where you call Claude; in a queued job, name the user: Feature::for($user)->active(...)
$model = Feature::active('claude-sonnet-5-5') ? 'claude-sonnet-5-5' : 'claude-sonnet-4-6';

$response = Anthropic::messages()->create(['model' => $model, 'max_tokens' => 1024, 'messages' => [...]]);
```

Pennant stores each user's result, so a user stays on one model while you compare their answers.

## Capabilities

Each model reports what it supports through a `capabilities` object. The common fields are typed:

```php
$model = Anthropic::models()->retrieve('claude-sonnet-5-5');

$model->capabilities?->batch->supported;
$model->capabilities?->citations->supported;
$model->capabilities?->codeExecution->supported;
$model->capabilities?->imageInput->supported;
$model->capabilities?->pdfInput->supported;
$model->capabilities?->structuredOutputs->supported;
$model->capabilities?->thinking->supported;
$model->capabilities?->thinking->types->betweenTools?->supported;
$model->capabilities?->effort->xhigh?->supported;
$model->capabilities?->serverTools?->webSearch->supported;
```

Context management strategies are date-versioned and exposed as a map, so new versions Anthropic ships show up without a package update:

```php
foreach ($model->capabilities?->contextManagement->strategies ?? [] as $name => $strategy) {
    $name;                // 'clear_thinking_20251015'
    $strategy->supported; // true
}
```

A practical Laravel-flavored pattern: pick a model at runtime based on what your feature needs.

```php
use Illuminate\Support\Facades\Cache;

$model = Cache::remember('anthropic.pdf_model', now()->addDay(), function () {
    $models = Anthropic::models()->list()->data;

    foreach ($models as $model) {
        if ($model->capabilities?->pdfInput->supported) {
            return $model->id;
        }
    }

    return 'claude-sonnet-5-5';
});
```

---

For every capability field, the beta-only `allowedFallbackModels` and compaction capability, and backward pagination, see the [Models page in the PHP docs](https://mozex.dev/docs/anthropic-php/v1/usage/models) or the [Models API reference](https://platform.claude.com/docs/en/api/models/list) on the Anthropic docs.

---

## Table of Contents

- [Introduction](https://mozex.dev/docs/anthropic-laravel/v1)
- [AI Integration](https://mozex.dev/docs/anthropic-laravel/v1/ai-integration)
- [Support Us](https://mozex.dev/docs/anthropic-laravel/v1/support-us)
- [Requirements](https://mozex.dev/docs/anthropic-laravel/v1/requirements)
- [Changelog](https://mozex.dev/docs/anthropic-laravel/v1/changelog)
- [Contributing](https://mozex.dev/docs/anthropic-laravel/v1/contributing)
- [Questions & Issues](https://mozex.dev/docs/anthropic-laravel/v1/questions-and-issues)
- [About Mozex](https://mozex.dev/docs/anthropic-laravel/v1/about)

### Usage

- [Messages](https://mozex.dev/docs/anthropic-laravel/v1/usage/messages)
- [Streaming](https://mozex.dev/docs/anthropic-laravel/v1/usage/streaming)
- [Tool Use](https://mozex.dev/docs/anthropic-laravel/v1/usage/tool-use)
- [Thinking](https://mozex.dev/docs/anthropic-laravel/v1/usage/thinking)
- [Server Tools](https://mozex.dev/docs/anthropic-laravel/v1/usage/server-tools)
- [Citations](https://mozex.dev/docs/anthropic-laravel/v1/usage/citations)
- [Token Counting](https://mozex.dev/docs/anthropic-laravel/v1/usage/token-counting)
- [Models](https://mozex.dev/docs/anthropic-laravel/v1/usage/models)
- [Batches](https://mozex.dev/docs/anthropic-laravel/v1/usage/batches)
- [Completions](https://mozex.dev/docs/anthropic-laravel/v1/usage/completions)
- [Files](https://mozex.dev/docs/anthropic-laravel/v1/usage/files)
- [Raw Requests](https://mozex.dev/docs/anthropic-laravel/v1/usage/raw-requests)
- [Usage Ledger](https://mozex.dev/docs/anthropic-laravel/v1/usage/usage-ledger)
- [Token Budgets](https://mozex.dev/docs/anthropic-laravel/v1/usage/token-budgets)

### Reference

- [Configuration](https://mozex.dev/docs/anthropic-laravel/v1/reference/configuration)
- [Error Handling](https://mozex.dev/docs/anthropic-laravel/v1/reference/error-handling)
- [Meta Information](https://mozex.dev/docs/anthropic-laravel/v1/reference/meta-information)
- [Testing](https://mozex.dev/docs/anthropic-laravel/v1/reference/testing)
- [Using alongside laravel/ai](https://mozex.dev/docs/anthropic-laravel/v1/reference/laravel-ai)
- [Diagnostics](https://mozex.dev/docs/anthropic-laravel/v1/reference/diagnostics)