The most efficient algorithm for finding the highest valid number for an API
Assuming $1$ is always a valid ID, you can solve your problem in about $2 \log v$ queries where $v$ is the maximum value by using exponential search and binary search.
Query the API using powers of two ($2,4,8,\dots$) until you find the smallest power of two $x$ such that $x &gt; v$. Clearly $x \le 2v$.
This requires up to $1+\lceil \log_2(v) \rceil$ queries.
Then use binary search in the range $[v-1, 2v)$ to find the exact value for $v$. This requires at most $\lceil \log_2(1+v) \rceil$ queries.