Skip to content

Watch the quota on third-party APIs

Stripe, GitHub, Twilio return X-RateLimit-Remaining in response headers. If the backend does not track the floor, you get a sudden 429 and billing stops.

Recipe

python
# Probe a cheap idempotent endpoint, alert when remaining quota < 10%.
import os, requests

API_URL = os.environ['API_URL']        # e.g. https://api.github.com/rate_limit
TOKEN   = os.environ['API_TOKEN']
ALERT_PERCENT = int(os.environ.get('ALERT_PERCENT', 10))

r = requests.get(API_URL, headers={'Authorization': f'Bearer {TOKEN}'}, timeout=5)
limit     = int(r.headers.get('X-RateLimit-Limit',     0))
remaining = int(r.headers.get('X-RateLimit-Remaining', 0))

if limit and remaining * 100 // limit < ALERT_PERCENT:
    requests.post(os.environ['SLACK_WEBHOOK'], json={
        'text': f'API quota at {remaining}/{limit} on {API_URL}'
    }, timeout=5)

Same thing in Enterno.io

A Pioneer+ HTTP monitor can persist a header snapshot. Hit your /rate_limit endpoint every 5 minutes and Enterno raises the alert exactly when the value crosses the floor.

Set up API monitor → ← All recipes

Related recipes