Overview
Antigravity implements intelligent rate limiting with automatic error detection, exponential backoff, and account rotation.Rate Limit Detection
The system automatically detects and handles various rate limit scenarios:Limit Types
Daily/monthly API quota exhaustedHTTP Status: 429
Response Reason:
Location:
Response Reason:
QUOTA_EXHAUSTEDLocation:
rate_limit.rs:8-9Requests per minute (RPM) or tokens per minute (TPM) limit exceededHTTP Status: 429
Response Reason:
Location:
Response Reason:
RATE_LIMIT_EXCEEDEDLocation:
rate_limit.rs:11-12Model temporarily at capacityHTTP Status: 429
Response Reason:
Location:
Response Reason:
MODEL_CAPACITY_EXHAUSTEDLocation:
rate_limit.rs:13-14Upstream server errors (5xx)HTTP Status: 500, 503, 529, 404
Default Lockout: 8 seconds (5s for 404)
Location:
Default Lockout: 8 seconds (5s for 404)
Location:
rate_limit.rs:15-16Backoff Configuration
Circuit Breaker
Enable intelligent circuit breaker with exponential backoff
Exponential backoff steps in seconds for quota exhaustionOn repeated failures, the lockout time increases progressively:
- 1st failure: 30 seconds
- 2nd failure: 60 seconds (1 minute)
- 3rd failure: 120 seconds (2 minutes)
- 4th failure: 300 seconds (5 minutes)
- 5th+ failure: 600 seconds (10 minutes)
rate_limit.rs:254-267Configuration Example
- 1st failure: 60s (1 min)
- 2nd failure: 300s (5 min)
- 3rd failure: 1800s (30 min)
- 4th+ failure: 7200s (2 hours)
Smart Recovery
Automatic Retry Detection
The system automatically parses retry-after information from API responses:- Retry-After Header: Standard HTTP header (in seconds)
- JSON Response: Google-specific
quotaResetDelayfield - Text Patterns: Various error message formats
rate_limit.rs:420-500
Time Format Support
Supports multiple time duration formats:- ISO 8601:
2026-01-08T17:00:00Z - Duration:
2h1m1s,1h30m,42s,510.790ms - Seconds:
60,120
rate_limit.rs:375-418
Failure Count Expiry
Time in seconds after which failure count resets to 0If an account has no failures for 1 hour, the backoff counter resets.Location:
rate_limit.rs:42Account Scheduling
Sticky Session Configuration
Account selection strategyOptions:
Balance: Distribute load evenly across accountsSticky: Pin sessions to specific accounts
Maximum time to wait for rate-limited accountIf all accounts are rate-limited and the shortest wait time exceeds this value, the system triggers optimistic reset.Location:
rate_limit.rs:70-76Optimistic Reset
When all accounts are rate-limited with short wait times, the system may clear all rate limit records to resolve timing race conditions: Trigger Conditions:- All available accounts are rate-limited
- Shortest remaining wait time <
max_wait_seconds
rate_limit.rs:557-561
Model-Level Rate Limiting
Supports fine-grained rate limiting per model:Associate rate limit with specific modelWhen specified, lockout only affects the specific model, allowing other models on the same account to continue.Location:
rate_limit.rs:35-38Example: Model Isolation
rate_limit.rs:60-67, 115-148
Rate Limit Management API
Check Rate Limit Status
Mark Successful Request
rate_limit.rs:94-108
Clear Rate Limits
rate_limit.rs:549-561
Advanced Features
Precise Quota Reset
Instead of exponential backoff, you can set exact lockout times:rate_limit.rs:110-173
Safety Buffer
Minimum lockout time of 2 seconds to prevent excessive retries:rate_limit.rs:224-226
Monitoring
Rate limit events are logged with details:Best Practices
- Enable circuit breaker for production environments
- Set conservative backoff steps for critical applications
- Monitor rate limit logs to identify problematic patterns
- Use multiple accounts to improve availability
- Consider model-level isolation for high-value models