My suggestion, as it seems you are in control of the internal API, setup an API call that can respond fast. Perhaps call it "ping" or whatever -- then in your app try sending a call to the internal server name/ip:port with a pretty low timeout. If you get the expected response, then route API calls to the internal server. If you don't, route API calls to the external server. At that point you may not really care what your local IP is -- only which server you should route the API calls to for the next period of time. But if you do care, just have the internal "ping" command return the IP address of the caller. It should be available to the host server in its socket.
Even if you aren't in control of the APIs used by the internal server, try sending it a bogus command with bad or unauthorized syntax but use a short timeout and see if it times out or gets back a 4xx or 5xx status code or whatever.
Then your app can also auto-transfer to the external server if the internal server is down for any reason.