By default, the AI Services plugin uses a timeout of 15 seconds for API requests. Provider-specific implementations may sometimes override this default, for example using a higher value for heavier tasks such as image generation.

To modify the API request timeout for a specific process, you can include a timeout key in the optional $request_options parameter, either when retrieving the model object, or for the specific model method invocation:

$service = ai_services()->get_available_service( $service_args );

// This sets the timeout for all interactions using this `$model` instance to 30 seconds.
$model = $service->get_model( $model_params, array( 'timeout' => 30 ) );

// This sets the timeout for only this one call to 60 seconds.
$candidates = $model->generate_text( $content, array( 'timeout' => 60 ) );

Alternatively to these specific adjustments, you can override the API request timeout centrally for any usage of the AI Services plugin via the ai_services_request_timeout filter. This filter is run for every single AI API request that AI Services makes.

Here is an example, consistently setting the timeout to 30 seconds for every AI API request:

add_filter(
	'ai_services_request_timeout',
	function () {
		return 30;
	}
);