Because large queries can hurt site performance, WordPress caps the per_page REST parameter at 100 records. However, there are situations when you need to override this value.
I saw solutions similar to this one, but I dislike that they modify the SQL query to ignore the client’s limit. Thus, even if the client requests 10 records, these solutions will change the query to return many more rows. This definitely hurts site performance.
Luckily, the proper solution is easy. There is a hook to filter collection parameters for the posts controller.
$post_type = 'attachment';
add_filter( "rest_{$post_type}_collection_params", function( $params ) {
$params['per_page']['maximum'] = 500;
return $params;
} );
In the example above, the maximum value of per_page for media (/wp-json/wp/v2/media) is set to 500 records.
How to Increase per_page Limit in WordPress REST API