The following rule gives the correct output url in htaccess tester.
RewriteEngine On RewriteRule ^api/(.*)\/(.*) api/$1.php?id=$2 [QSA,L]