I believe this is because the ARM template doesn't contain the necessary connection details for the api connection to link to the on-prem gateway. There are some hidden properties that you need to provide in the API connection ARM template.
"parameterValues": {
"authType": "[parameters('authType')]",
"gateway": {
"id": "[concat('/subscriptions/',subscription().subscriptionId,'/resourceGroups/',parameters('gatewayresourcegroup'),'/providers/Microsoft.Web/connectionGateways/',parameters('gatewayname'))]"
}
}
Once I provided those, the api connection Status went to "Connected" rather than "Error"