Rate Limits
APIs limit how many requests you can make per second, per minute, or per day. Agents must respect these limits to avoid being blocked.
6 min•By Priygop Team•Updated 2026
Rate Limit Management
- Read the API documentation to understand the rate limits before building your agent
- Log the number of API calls the agent makes per minute and per hour
- If an agent hits a rate limit, wait for the Retry-After time the API specifies
- Avoid polling APIs in tight loops — add delays between requests
- Cache API results when the data does not change between steps
- If rate limits are consistently hit, request higher limits or redesign the workflow
Simple Rate Limiter
Simple Rate Limiter
import time
from collections import deque
class RateLimiter:
"""
Limit API calls to max_calls per time_window_seconds.
Blocks the agent if the limit is reached.
"""
def __init__(self, max_calls: int, time_window_seconds: float):
self.max_calls = max_calls
self.window = time_window_seconds
self.timestamps = deque()
def wait_if_needed(self):
"""Call before each API request."""
now = time.time()
# Remove timestamps outside the current window
while self.timestamps and self.timestamps[0] < now - self.window:
self.timestamps.popleft()
if len(self.timestamps) >= self.max_calls:
# Too many calls — wait until oldest is outside window
sleep_time = self.window - (now - self.timestamps[0])
print(f"Rate limit reached. Waiting {sleep_time:.1f}s...")
time.sleep(sleep_time)
self.timestamps.append(time.time())
# Allow 10 calls per minute
limiter = RateLimiter(max_calls=10, time_window_seconds=60)
def safe_api_call(url: str) -> str:
limiter.wait_if_needed()
# make your API call here
return f"Result from {url}"
# The agent uses this function and never hits rate limits
for i in range(3):
result = safe_api_call(f"https://api.example.com/item/{i}")
print(result)Key Takeaways
- APIs limit how many requests you can make per second, per minute, or per day.
- Read the API documentation to understand the rate limits before building your agent
- Log the number of API calls the agent makes per minute and per hour
- If an agent hits a rate limit, wait for the Retry-After time the API specifies