Title: PromptBuilder::getConfiguredModel
Published: May 20, 2026

---

# PromptBuilder::getConfiguredModel( WordPressAiClientProvidersModelsEnumsCapabilityEnum $capability ): WordPressAiClientProvidersModelsContractsModelInterface

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/getconfiguredmodel/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/getconfiguredmodel/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/getconfiguredmodel/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/getconfiguredmodel/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/getconfiguredmodel/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/getconfiguredmodel/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/getconfiguredmodel/?output_format=md#wp--skip-link--target)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Gets the model to use for generation.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/getconfiguredmodel/?output_format=md#description)󠁿

If a model has been explicitly set, validates it meets requirements and returns 
it.
Otherwise, finds a suitable model based on the prompt requirements.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/getconfiguredmodel/?output_format=md#parameters)󠁿

 `$capability`WordPressAiClientProvidersModelsEnumsCapabilityEnumrequired

The capability the model will be using.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/getconfiguredmodel/?output_format=md#return)󠁿

 WordPressAiClientProvidersModelsContractsModelInterface The model to use.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/getconfiguredmodel/?output_format=md#source)󠁿

    ```php
    private function getConfiguredModel(CapabilityEnum $capability): ModelInterface
    {
        $requirements = ModelRequirements::fromPromptData($capability, $this->messages, $this->modelConfig);
        if ($this->model !== null) {
            // Explicit model was provided via usingModel(); just update config and bind dependencies.
            $model = $this->model;
            $model->setConfig($this->modelConfig);
            $this->registry->bindModelDependencies($model);
            $this->bindModelRequestOptions($model);
            return $model;
        }
        // Retrieve the candidate models map which satisfies the requirements.
        $candidateMap = $this->getCandidateModelsMap($requirements);
        if (empty($candidateMap)) {
            $message = sprintf('No models found that support %s for this prompt.', $capability->value);
            if ($this->providerIdOrClassName !== null) {
                $message = sprintf('No models found for provider "%s" that support %s for this prompt.', $this->providerIdOrClassName, $capability->value);
            }
            throw new InvalidArgumentException($message);
        }
        // Check if any preferred models match the candidates, in priority order.
        if (!empty($this->modelPreferenceKeys)) {
            // Find preferences that match available candidates, preserving preference order.
            $matchingPreferences = array_intersect_key(array_flip($this->modelPreferenceKeys), $candidateMap);
            if (!empty($matchingPreferences)) {
                // Get the first matching preference key
                $firstMatchKey = key($matchingPreferences);
                [$providerId, $modelId] = $candidateMap[$firstMatchKey];
                $model = $this->registry->getProviderModel($providerId, $modelId, $this->modelConfig);
                $this->bindModelRequestOptions($model);
                return $model;
            }
        }
        // No preference matched; fall back to the first candidate discovered.
        [$providerId, $modelId] = reset($candidateMap);
        $model = $this->registry->getProviderModel($providerId, $modelId, $this->modelConfig);
        $this->bindModelRequestOptions($model);
        return $model;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/php-ai-client/src/builders/promptbuilder.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/php-ai-client/src/Builders/PromptBuilder.php#L1148)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/php-ai-client/src/Builders/PromptBuilder.php#L1148-L1186)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/getconfiguredmodel/?output_format=md#related)󠁿

| Uses | Description | 
| [ModelRequirements::fromPromptData()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-models-dto-modelrequirements/frompromptdata/)`wp-includes/php-ai-client/src/Providers/Models/DTO/ModelRequirements.php` |

Creates ModelRequirements from prompt data and model configuration.

  | 
| [PromptBuilder::getCandidateModelsMap()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/getcandidatemodelsmap/)`wp-includes/php-ai-client/src/Builders/PromptBuilder.php` |

Builds a map of candidate models that satisfy the requirements for efficient lookup.

  | 
| [PromptBuilder::bindModelRequestOptions()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/bindmodelrequestoptions/)`wp-includes/php-ai-client/src/Builders/PromptBuilder.php` |

Binds configured request options to the model if present and supported.

  |

| Used by | Description | 
| [PromptBuilder::generateResult()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/generateresult/)`wp-includes/php-ai-client/src/Builders/PromptBuilder.php` |

Generates a result from the prompt.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/getconfiguredmodel/?output_format=md#changelog)󠁿

| Version | Description | 
| [0.1.0](https://developer.wordpress.org/reference/since/0.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwordpress-aiclient-builders-promptbuilder%2Fgetconfiguredmodel%2F)
before being able to contribute a note or feedback.