How to fix "Http failure response for (unknown url): 0 Unknown Error" for google bot

When I test my site in the Google Search Console, I see that the content is not being indexed because googlebot is not able to get any data from my api. The site works properly in the browser, but when called from googlebot, the api request gives this error:

{"headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"status":0,"statusText":"Unknown Error","url":null,"ok":false,"name":"HttpErrorResponse","message":"Http failure response for (unknown url): 0 Unknown Error","error":{"isTrusted":true}}

I cannot find where the problem lies as the site works properly in the browser without giving any error.

Sadly I am not able to reproduce the problem myself. Only googlebot seems to have a problem with the response (or lack of) coming from the server.

Any idea what could be wrong here?

EDIT: If I place the API under the same URL as the frontend, googlebot doesn't have any problem anymore. Something missing in a config somewhere maybe?