Captcha API Endpoint

As you know, showing a captcha to every user is not a very efficient way to improve user experience. As an alternative, I had an idea. What if I count the number of incorrect login attempts in my application, and when that number reaches, for example, 5, I send a request through the Cloudflare API and show a captcha to the IP address that made the incorrect login attempt? If there is already an API method that does this, please let me know. I would appreciate it.