Here is a small tutorial on how to access the e621 API when it gets blocked by Cloudflare, as done in TWS. The code is in Java (for Android) but the basic principle should be the same for other languages.
Starting from the beginning, the API returns an HTTP status code of 403 (forbidden) or 503 (service unavailable) when Cloudflare blocks the API call. To access e621 and the API, a captcha must be completed. The simplest way is to use a WebView:
where USER_AGENT is the exact same as in all other requests to the e621 API. This is important so that Cloudflare knows that it is the same client connecting.
After completing the captcha Cloudflare redirects to e621, and the next step is to extract and store three cookies from the WebView. These are __cfduid, e621 and cf_clearance. Two of these tells Cloudflare that the captcha has been completed and the third is an identifier for e621. Together, these can be used to bypass Cloudflare and make the API working again.
CookieManager extracts the cookies:
Include the cookies and use the same user agent at all times and Cloudflare will not block the API calls to e621 :) (until you have to complete a captcha again)