Question (received by email): I would like to use an API call where I can check the availability of an endpoint BEFORE calling it . Do you have such an API method? Or in other words: How to retrieve the OCR API StatusPage info via an api in json format, so I can check programmatically which endpoint(s) are UP or DOWN.
Answer: As you mentioned, as PRO OCR API user you have access to 3 geographically different endpoints in USA, EU and Asia. The proposed methods help to find the fastest one automatically and avoid any downtime.
Solution 1: Make a call to a GET endpoint with a timeout of e. g. 5 seconds. If you get a response back, the endpoint is up. If not, skip to the next PRO endpoint.
Solution 2: What we do in our UI.Vision RPA software with screen scraping and free Copyfish OCR software (that both use the OCR API!) is to use the first three OCR request to make a call to each of the three endpoints, and then use the fastest one of the PRO endpoints for all future OCR requests. The reason we do this is because the fastest PRO endpoint is different for each user, depending on her or his location.
While the software is making OCR conversion calls, we control the response time and should one endpoint become too slow or even timeout, the software switches to another one automatically.
To explain the source code a bit more, the endpoint switching algorithm works this way:
- Make an API call with e. g. a 30 second timeout
- All works ok: Log response time (to compare later with other endpoints, to find the fastest one)
- No response after 30 seconds: Mark the endpoint as down, and use another endpoint for the OCR conversion.
- After a certain time e. g. one hour, reset all performance values, so that slow or down endpoints have a chance again.
With this algorithm and the three OCR.space PRO endpoints we had a 100% uptime in the last three+ years with more than 100,000 users.
Of course, other methods to switch between endpoints can work equally well. The import part is that your code automatically switches to another endpoint if one is down or too slow.