A rate limit caps how many requests you can make in a period of time. Go over it and the API answers 429 Too Many Requests. The fix is to slow down and retry after a pause that grows each time.
01What a rate limit is
An API serves many clients from shared servers. A rate limit stops any one of them from using it all: each API key, or each IP address, may make a set number of requests per second, minute or month.
Limits keep the service fast and fair for everyone, protect it from runaway loops and usually grow with the plan you pay for.
02Per-minute vs monthly limits
Most APIs have two kinds of limit, and they answer different questions.
A short-window limit, per second or per minute, is about speed. It smooths out bursts so one client cannot flood the servers. Wait a moment and you have room again.
A quota, often per month, is about volume. It caps the total you can use in the period. Waiting a minute does not help; you need a bigger plan or extra credit.
Zapi has both. Per-minute limits are counted in requests: 100 a minute on Free, 2,000 on Pro, 5,000 on Ultra and 15,000 on Max. The monthly quota is counted in Zap: 600 on Free, 25,000 on Pro, 200,000 on Ultra and 1,000,000 on Max.
03What a 429 means
HTTP status 429 Too Many Requests means you went over a limit. Nothing is wrong with the request itself; it simply came too soon.
Many APIs add a Retry-After header that says how long to wait, usually in seconds. If it is there, use it. If not, wait and try again, a little longer each time.
On Zapi, going over the per-minute limit returns 429, and a request refused for limits costs 0 Zap.
04Retry with backoff
Retrying straight away usually fails again, and many clients retrying at once can keep a busy server busy. Exponential backoff fixes both: wait 1 second, then 2, then 4, and add a little randomness (jitter) so clients do not retry in step.
Retry only what can succeed later: 429 and server errors (5xx). Other 4xx errors mean the request itself is wrong, so fix it instead. Stop after a few tries.
import os import random import time import requests URL = "https://api.zapi.ink/v1/finance:antam/harga" HEADERS = {"x-api-key": os.environ["ZAPI_KEY"]} def get_with_retry(url, tries=5): for attempt in range(tries): r = requests.get(url, headers=HEADERS, timeout=30) retry = r.status_code == 429 or r.status_code >= 500 if not retry or attempt == tries - 1: r.raise_for_status() # raise if it still failed return r.json() # Retry-After if the API sends it, else 1 s, 2 s, 4 s ... after = r.headers.get("Retry-After", "") wait = int(after) if after.isdigit() else 2**attempt time.sleep(wait + random.random()) # jitter body = get_with_retry(URL) print(body["data"])
On Zapi this pattern is also cheap. Requests refused for limits and our server errors (5xx) cost 0 Zap, while other 4xx errors cost 1, one more reason not to retry them.
05Staying under the limit
The best 429 is the one you never get. Pace your requests instead of sending them all at once, and cap how many run in parallel.
Cache results that do not change often, so you do not ask twice for the same answer. For large jobs on Zapi, submit one bulk job instead of thousands of separate calls; it draws on your monthly quota only, never on top-up Zap.
Log every 429 you get. A few are normal; a steady stream means your pace or your plan needs to change.