Your approach is very unusual and not recommended. Usually you have a local copy of the OSM database. Either the whole planet or an extract, for example a country.
Fetching this data on-the-fly is a really bad idea and you will run into lots of problems. The APIs are not really prepared to support such heavy queries. And for long distances you will have to deal with hundreds of megabytes of data. Furthermore if you want to be able to calculate routes fast then it is necessary to pre-process the raw data.
If you decide to install a local database then I recommend you to read switch2osm. There is a guide about building a tile server which you can use, just skip installing Mapnik, mod_tile, renderd etc.