# Models

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

---

The Models resource lets you list all available Claude models and get details about a specific one. This is useful for building model selectors, checking availability, or programmatically discovering new models.

## Listing models

```php
$response = $client->models()->list();

foreach ($response->data as $model) {
    $model->id;          // 'claude-sonnet-4-6'
    $model->type;        // 'model'
    $model->createdAt;   // '2025-05-14T00:00:00Z'
    $model->displayName; // 'Claude Sonnet 4.6'
}
```

The response includes pagination metadata:

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

## Pagination

The Models API uses cursor-based pagination. Use `limit` to control page size (defaults to 20, max 1000) and `after_id` to fetch the next page:

```php
// First page
$page1 = $client->models()->list(['limit' => 5]);

// Next page (if more exist)
if ($page1->hasMore) {
    $page2 = $client->models()->list([
        'limit' => 5,
        'after_id' => $page1->lastId,
    ]);
}
```

You can also paginate backward using `before_id` with `firstId`:

```php
$previousPage = $client->models()->list([
    'limit' => 5,
    'before_id' => $page2->firstId,
]);
```

To fetch all models:

```php
$allModels = [];

$response = $client->models()->list(['limit' => 20]);
$allModels = array_merge($allModels, $response->data);

while ($response->hasMore) {
    $response = $client->models()->list([
        'limit' => 20,
        'after_id' => $response->lastId,
    ]);
    $allModels = array_merge($allModels, $response->data);
}
```

## Retrieving a single model

Get details about a specific model by its ID:

```php
$response = $client->models()->retrieve('claude-sonnet-4-6');

$response->id;          // 'claude-sonnet-4-6'
$response->type;        // 'model'
$response->createdAt;   // '2025-05-14T00:00:00Z'
$response->displayName; // 'Claude Sonnet 4.6'
```

This returns a `RetrieveResponse` with the same fields as each item in the list.

---

For available model IDs and capabilities, see the [Models API reference](https://platform.claude.com/docs/en/api/models/list) and [Models overview](https://platform.claude.com/docs/en/about-claude/models/overview) on the Anthropic docs.

---

## Table of Contents

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

### Usage

- [Messages](https://mozex.dev/docs/anthropic-php/v1/usage/messages)
- [Streaming](https://mozex.dev/docs/anthropic-php/v1/usage/streaming)
- [Tool Use](https://mozex.dev/docs/anthropic-php/v1/usage/tool-use)
- [Thinking](https://mozex.dev/docs/anthropic-php/v1/usage/thinking)
- [Server Tools](https://mozex.dev/docs/anthropic-php/v1/usage/server-tools)
- [Citations](https://mozex.dev/docs/anthropic-php/v1/usage/citations)
- [Token Counting](https://mozex.dev/docs/anthropic-php/v1/usage/token-counting)
- [Models](https://mozex.dev/docs/anthropic-php/v1/usage/models)
- [Batches](https://mozex.dev/docs/anthropic-php/v1/usage/batches)
- [Completions](https://mozex.dev/docs/anthropic-php/v1/usage/completions)

### Reference

- [Configuration](https://mozex.dev/docs/anthropic-php/v1/reference/configuration)
- [Error Handling](https://mozex.dev/docs/anthropic-php/v1/reference/error-handling)
- [Meta Information](https://mozex.dev/docs/anthropic-php/v1/reference/meta-information)
- [Testing](https://mozex.dev/docs/anthropic-php/v1/reference/testing)