# Rate Limits

MoreLogin API enforces rate limits to ensure fair usage and system stability.

## Limits

| API Type | Rate Limit | Window |
|  --- | --- | --- |
| **Local API** | 120 requests | per minute |
| **Open API** | 120 requests | per minute |


## Rate Limit Response

When you exceed the rate limit, the API returns:

**HTTP Status**: `429 Too Many Requests`


```json
{
  "code": 429,
  "msg": "Rate limit exceeded",
  "data": null,
  "requestId": "..."
}
```

## Best Practices

### 1. Implement Retry with Backoff


```python
import time
import requests

def api_request_with_retry(url, payload, max_retries=3):
    for attempt in range(max_retries):
        response = requests.post(url, json=payload)
        if response.status_code == 429:
            wait_time = 2 ** attempt  # 1s, 2s, 4s
            print(f"Rate limited. Retrying in {wait_time}s...")
            time.sleep(wait_time)
            continue
        return response
    raise Exception("Max retries exceeded")
```

### 2. Batch Operations

Instead of making individual API calls, use batch endpoints when available:


```python
# Bad: 100 individual calls
for env_id in env_ids:
    requests.post(f"{BASE}/api/env/start", json={"envId": env_id})

# Good: Use batch endpoints
requests.post(f"{BASE}/api/env/updateGroup/batch", json={
    "envIds": env_ids,
    "groupId": "target-group"
})
```

### 3. Cache Responses

For data that doesn't change frequently (e.g., timezone lists, platform lists), cache the response locally:


```python
# Cache timezone/language data — it rarely changes
timezone_data = requests.post(f"{BASE}/api/env/advanced/timezone").json()
# Reuse timezone_data for subsequent profile creations
```

## Monitoring Your Usage

Keep track of your API call frequency. If you consistently approach the limit, consider:

- Spreading requests evenly across the minute
- Using webhooks (coming soon) instead of polling
- Combining multiple operations into batch calls