With the mwai_ai_query filter, you can pick the model for each request, right before it is sent. The idea is to use a stronger (and more expensive) model only when it is really needed, and a faster, cheaper one for everything else. Modern models handle images natively, so you no longer need a separate vision model. In this example, the stronger model is used when the visitor sends an image, and the cheaper one for plain text messages.
add_filter( 'mwai_ai_query', function ( $query ) {
// Only chatbot and form requests (embeddings have their own filter)
if ( !( $query instanceof Meow_MWAI_Query_Text ) ) {
return $query;
}
// Did the visitor attach an image?
$hasImage = false;
foreach ( $query->getAttachments() as $file ) {
if ( $file->is_image() ) {
$hasImage = true;
break;
}
}
// Stronger model for images, cheaper one for text
$query->set_model( $hasImage ? 'gpt-5.5' : 'gpt-5.4-mini' );
// Log the chosen model for debugging
error_log( 'AI Engine model: ' . $query->model );
return $query;
} );
The model you pick must be available in the environment used by the chatbot or the form. If the chatbot runs on Anthropic, for example, switch between two Claude models instead.