Guides Get started
Handle limits and errors
Stay inside your rate limit and react to errors the right way.
-
Watch the headers
Every response tells you where you stand.
X-RateLimit-Resetis the number of seconds until your per-minute allowance refills.X-RateLimit-Limit: 120 X-RateLimit-Remaining: 7 X-RateLimit-Reset: 23 X-Quota-Remaining: 48210 -
Back off on 429
A
429means you hit the per-minute rate or your monthly quota. Wait forRetry-Afterseconds. For a used-up monthly quota that is days, so stop and alert rather than sleep. The SDKs retry short waits for you and raiseRateLimitErrorfor long ones.from trendwatching import RateLimitError try: rows = tw.innovations.list(query="ai") except RateLimitError as e: alert(f"TrendWatching quota used up, retry in {e.retry_after} seconds") -
Branch on error codes
Errors share one shape:
{"error": "code", "detail": "..."}. Codes are stable, so branch onerror:missing_api_keyandinvalid_api_key(401),subscription_inactive(403),not_found(404),invalid_tag,invalid_cursor,invalid_dateandmissing_parameter(400),rate_limit_exceededandquota_exceeded(429).