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:

1
X-RateLimit-Limit: 100
2
X-RateLimit-Remaining: 95
3
X-RateLimit-Reset: 1640995200

Handling Rate Limits

When you exceed your rate limit, Chekov will throw a RateLimitError. Here's how to handle it:

1
import { ai, RateLimitError } from '@chekov/core';
2
3
test('handle rate limits', async ({ page }) => {
4
try {
5
await ai('Click the submit button', { page });
6
} catch (error) {
7
if (error instanceof RateLimitError) {
8
console.log('Rate limit exceeded:', error.message);
9
console.log('Reset time:', error.resetTime);
10
11
// Wait until rate limit resets
12
const waitTime = error.resetTime - Date.now();
13
if (waitTime > 0) {
14
await new Promise(resolve => setTimeout(resolve, waitTime));
15
}
16
17
// Retry the action
18
await ai('Click the submit button', { page });
19
} else {
20
throw error;
21
}
22
}
23
});

Best Practices

Optimizing API Usage

Follow these practices to make the most of your rate limits:

1
test('optimize api usage', async ({ page }) => {
2
// Group related actions
3
await ai([
4
'Type "user@example.com" in the email field',
5
'Type "password123" in the password field'
6
], {
7
page,
8
parallelism: 2 // Counts as a single API call
9
});
10
11
// Use built-in Playwright commands when possible
12
const submitButton = page.getByRole('button', { name: 'Submit' });
13
if (await submitButton.isVisible()) {
14
await submitButton.click();
15
} else {
16
// Fall back to AI if element can't be found
17
await ai('Click the submit button', { page });
18
}
19
});

Implementing Retries

Add retry logic for handling temporary rate limit issues:

1
async function withRetry(action: () => Promise<void>, maxRetries = 3) {
2
for (let i = 0; i < maxRetries; i++) {
3
try {
4
await action();
5
return;
6
} catch (error) {
7
if (error instanceof RateLimitError) {
8
if (i === maxRetries - 1) throw error;
9
10
const waitTime = Math.min(
11
error.resetTime - Date.now(),
12
1000 * Math.pow(2, i) // Exponential backoff
13
);
14
15
await new Promise(resolve => setTimeout(resolve, waitTime));
16
continue;
17
}
18
throw 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

Next Steps