Implements a new provider that uses Google's Antigravity unified gateway API to access Claude, Gemini, and other models through a single OAuth2-authenticated endpoint. Features: - OAuth2 token management with automatic refresh - Multi-account rotation for rate limit distribution - Support for Claude Opus/Sonnet 4.5 (with/without thinking) - Support for Gemini 2.5/3 models (Pro/Flash variants) - Thinking mode support with configurable tokens - Image processing support - Dual quota pool tracking (antigravity vs gemini-cli) - Gemini-style API request format Authentication: - Reads from ANTIGRAVITY_REFRESH_TOKEN env var (priority) - Falls back to ~/.config/opencode/antigravity-accounts.json - Automatic token refresh with retry logic - Rate limit tracking per account and quota pool Files added: - providers/antigravity.py - Main provider implementation - providers/antigravity_auth.py - OAuth token manager - providers/registries/antigravity.py - Model registry - conf/antigravity_models.json - Model definitions (11 models) - docs/antigravity_provider.md - Setup and usage docs - tests/test_antigravity_provider.py - Unit tests (14 pass) Integration: - Added to provider priority order after ZEN - Registered in server.py with auto-detection - ToS warning logged on first use
5.8 KiB
Antigravity Provider
The Antigravity provider enables access to Claude, Gemini, and other models through Google's unified gateway API. This provides an alternative way to access high-quality models using Google OAuth2 authentication instead of individual API keys.
Important Warning
Terms of Service Risk: Using the Antigravity provider may violate Google's Terms of Service. Users have reported account bans when using this approach.
High-Risk Scenarios:
- Fresh Google accounts have a very high chance of getting banned
- New accounts with Pro/Ultra subscriptions are frequently flagged
By using this provider, you acknowledge and accept all associated risks.
Available Models
Antigravity Quota Pool
These models use the Antigravity unified gateway quota:
| Model ID | Description | Thinking Support |
|---|---|---|
claude-opus-4-5-thinking |
Claude Opus 4.5 with extended thinking | Yes (up to 32K tokens) |
claude-sonnet-4-5-thinking |
Claude Sonnet 4.5 with extended thinking | Yes (up to 32K tokens) |
claude-sonnet-4-5 |
Claude Sonnet 4.5 standard | No |
gemini-3-pro-high |
Gemini 3 Pro with high thinking budget | Yes (up to 65K tokens) |
gemini-3-pro-low |
Gemini 3 Pro with low thinking budget | Yes (up to 16K tokens) |
gemini-3-flash |
Gemini 3 Flash | Yes (up to 32K tokens) |
gpt-oss-120b-medium |
GPT-OSS 120B | No |
Gemini CLI Quota Pool
These models use a separate Gemini CLI quota:
| Model ID | Description | Thinking Support |
|---|---|---|
gemini-3-flash-preview |
Gemini 3 Flash Preview | Yes |
gemini-3-pro-preview |
Gemini 3 Pro Preview | Yes |
gemini-2.5-pro |
Gemini 2.5 Pro | Yes |
gemini-2.5-flash |
Gemini 2.5 Flash | Yes |
Setup
Option 1: OpenCode Integration (Recommended)
If you use OpenCode with the opencode-antigravity-auth plugin, your accounts are automatically detected from:
~/.config/opencode/antigravity-accounts.json
No additional configuration is needed. The PAL MCP server will automatically discover and use these accounts.
Option 2: Manual Refresh Token
Set the refresh token directly via environment variable:
export ANTIGRAVITY_REFRESH_TOKEN="your_oauth_refresh_token"
export ANTIGRAVITY_PROJECT_ID="your_gcp_project_id" # Optional
Option 3: Custom Accounts File
Create ~/.config/opencode/antigravity-accounts.json manually:
{
"version": 3,
"accounts": [
{
"email": "your.email@gmail.com",
"refreshToken": "1//your_refresh_token_here",
"projectId": "your-gcp-project-id",
"enabled": true
}
],
"activeIndex": 0
}
Environment Variables
| Variable | Required | Description |
|---|---|---|
ANTIGRAVITY_REFRESH_TOKEN |
No* | OAuth2 refresh token (overrides accounts file) |
ANTIGRAVITY_PROJECT_ID |
No | Google Cloud project ID (defaults to rising-fact-p41fc) |
ANTIGRAVITY_BASE_URL |
No | API endpoint (defaults to production cloudcode-pa.googleapis.com) |
*Either ANTIGRAVITY_REFRESH_TOKEN or a valid accounts file at ~/.config/opencode/antigravity-accounts.json is required.
Features
Multi-Account Rotation
When multiple accounts are configured, the provider automatically:
- Rotates between accounts when one is rate-limited
- Tracks per-model rate limits separately
- Preserves account preferences for cache efficiency
Extended Thinking
For models that support thinking (Claude and Gemini 3), you can control the thinking budget:
# Thinking modes: minimal, low, medium, high, max
response = provider.generate_content(
prompt="Explain quantum computing",
model_name="claude-opus-4-5-thinking",
thinking_mode="high" # Uses 67% of max thinking budget
)
| Mode | Budget Percentage |
|---|---|
| minimal | 0.5% |
| low | 8% |
| medium | 33% (default) |
| high | 67% |
| max | 100% |
Image Support
Models with vision capability support image inputs:
response = provider.generate_content(
prompt="What's in this image?",
model_name="gemini-3-flash",
images=["/path/to/image.png"]
)
Troubleshooting
"No Antigravity accounts configured"
Ensure either:
ANTIGRAVITY_REFRESH_TOKENenvironment variable is set, or~/.config/opencode/antigravity-accounts.jsonexists with valid accounts
"All Antigravity accounts are rate limited"
The provider has exhausted all available accounts. Either:
- Wait for rate limits to reset (usually 60 seconds to a few minutes)
- Add more accounts to the accounts file
"Token refresh failed"
Your refresh token may have expired. Re-authenticate:
- If using OpenCode:
opencode auth login - If manual: Obtain a new refresh token via OAuth2 flow
403 Permission Denied
Your Google Cloud project may not have the required APIs enabled:
- Go to Google Cloud Console
- Enable the Gemini for Google Cloud API (
cloudaicompanion.googleapis.com)
API Format
The Antigravity API uses Gemini-style request format internally:
{
"project": "your-project-id",
"model": "claude-opus-4-5-thinking",
"request": {
"contents": [
{"role": "user", "parts": [{"text": "Your prompt"}]}
],
"generationConfig": {
"temperature": 0.7,
"maxOutputTokens": 8192,
"thinkingConfig": {
"thinkingBudget": 8000,
"includeThoughts": true
}
}
}
}
This transformation is handled automatically by the provider.
Related Resources
- opencode-antigravity-auth - OpenCode plugin for Antigravity authentication
- Antigravity API Specification - Detailed API documentation