WP Multisite – Additional subdomain on the site for API purposes

I have resovled it myself.

I have enabled sunrise in wp-config. Then add a script to sunrise.php to override HTTP_HOST.

I made it dynamic since we have many websites. When you visit api.domainxy.com it automatically shows you domainxy.com.

<?php
$re="/(?:api\.)(.*)/m";
$str = $_SERVER['HTTP_HOST'];


preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);

if ($matches && $matches[0][1] != "") {
  $_SERVER['HTTP_HOST'] = $matches[0][1];
}
?>