You need to read the Prometheus
HTTP API documentation, then get it to work using curl, before you write your Python version.
Your first problem is that you are querying the '/metrics' endpoint of prometheus. That only gives you metrics about prometheus itself - internal information about the performance of its time series database for example. There is a separate endpoint for querying metrics data which is stored in the database.
To check for "unreachable instances", I suggest you start with a simple query like up==0. Do this using an
instant query. Example:
You can then make this query more sophisticated to meet your requirements, and when you're happy with it, convert into Python.
Your second problem is that you are putting nonsense in your queries like "$unreachbale_instance" [sic] and "$interval". I am guessing you've been doing stuff like this in Grafana? But Grafana substitutes these placeholders with real values *before* sending the query to Prometheus' API. If prometheus sees these $ values then it will treat them literally as those strings, and in particular "$interval" is not a valid value for a
range vector selector. To see what syntax is allowed in a query, read the
query documentation, and test your queries out in the Prometheus web interface.
I note that you have calculated a suitable value and stored it in a python variable:
duration = '[' + str(last_day.day) + 'd]'
... but you have not actually used this value in your query anywhere.