How to avoid 504 when making an API call

I am using the following code to create a request from my node application to call an API.

var options = {
      host: "www.something.com",
      path: "/api/something.php",
      method: "POST"
    };

var request = https.request(options, callback);
request.write(str);
request.end();


Sometimes I am getting a response with Status Code - 504

Will increasing the timeout of the app help?

When I get a response with 504, does it mean the the gateways in between my client and the API server gave up?

Or is the problem with my client?

What happens when you manually call the page? I think 504 suggests an error in the remote page