How do I avoid exceeding the API query limit?

The API should not be queried in real-time. A better practice is to query asynchronously (e.g. using a nightly cron job) and then store resultsets in your own local data store where you can query at will. This solves the problem of over-taxing the API and also improves the performance of your own applications by letting users query local data rather than remote data.