Rate Limits
Learn about Chekov's rate limiting policies and how to handle them in your tests.
Rate Limit Tiers
Free Tier
- 100 API calls per month
- 5 concurrent requests
- 2 requests per second
Pro Tier
- 10,000 API calls per month
- 20 concurrent requests
- 10 requests per second
Enterprise Tier
- Custom API call limits
- Unlimited concurrent requests
- Custom rate limits
Rate Limit Headers
Chekov includes rate limit information in the response headers:
1X-RateLimit-Limit: 1002X-RateLimit-Remaining: 953X-RateLimit-Reset: 1640995200
Handling Rate Limits
When you exceed your rate limit, Chekov will throw a RateLimitError. Here's how to handle it:
1import { ai, RateLimitError } from '@chekov/core';23test('handle rate limits', async ({ page }) => {4try {5await ai('Click the submit button', { page });6} catch (error) {7if (error instanceof RateLimitError) {8console.log('Rate limit exceeded:', error.message);9console.log('Reset time:', error.resetTime);1011// Wait until rate limit resets12const waitTime = error.resetTime - Date.now();13if (waitTime > 0) {14await new Promise(resolve => setTimeout(resolve, waitTime));15}1617// Retry the action18await ai('Click the submit button', { page });19} else {20throw error;21}22}23});
Best Practices
Optimizing API Usage
Follow these practices to make the most of your rate limits:
1test('optimize api usage', async ({ page }) => {2// Group related actions3await ai([4'Type "user@example.com" in the email field',5'Type "password123" in the password field'6], {7page,8parallelism: 2 // Counts as a single API call9});1011// Use built-in Playwright commands when possible12const submitButton = page.getByRole('button', { name: 'Submit' });13if (await submitButton.isVisible()) {14await submitButton.click();15} else {16// Fall back to AI if element can't be found17await ai('Click the submit button', { page });18}19});
Implementing Retries
Add retry logic for handling temporary rate limit issues:
1async function withRetry(action: () => Promise<void>, maxRetries = 3) {2for (let i = 0; i < maxRetries; i++) {3try {4await action();5return;6} catch (error) {7if (error instanceof RateLimitError) {8if (i === maxRetries - 1) throw error;910const waitTime = Math.min(11error.resetTime - Date.now(),121000 * Math.pow(2, i) // Exponential backoff13);1415await new Promise(resolve => setTimeout(resolve, waitTime));16continue;17}18throw error;19}20}21}
Pro Tips
- Use parallel actions to reduce API calls
- Cache successful element queries
- Implement exponential backoff for retries
- Monitor your usage with rate limit headers
