rhead | Model Discovery | Billing Integration |
|----------|------------|----------------|------------------------|-----------------|---------------------|
| Direct Anthropic API Key | 10-15 mins | Static ANTHROPIC_API_KEY | Manual rotation, shell config updates | Manual ID entry | Separate procurement & invoicing |
| Antigravity via CliGate Proxy | ~5 mins | Google OAuth + Refresh Token | Auto-refresh (<5 min expiry threshold) | Auto-discovery via loadCodeAssist | Zero new billing (Workspace included) |
Key Findings:
- OAuth refresh tokens eliminate manual key rotation, reducing auth-related downtime by ~90%.
- Automatic model discovery adapts to quota changes without CLI restarts.
- Payload translation and SSE reconstruction maintain 1:1 compatibility with Claude Code's expected Anthropic API contract.
Core Solution
The solution relies on CliGate, a local proxy that bridges Anthropic's Messages API contract with Google's Antigravity generateContent protocol. It handles account pooling, OAuth token lifecycle management, payload normalization, and streaming reconstruction.
Architecture & Implementation Flow
- Start the Proxy
npx cligate@latest start
The dashboard initializes at http://localhost:8081.
- OAuth Account Provisioning
Navigate to Accounts β Antigravity and trigger the Google sign-in flow:
β Browser opens to accounts.google.com
β You authorize Cloud Platform + Code Assist scopes
β Callback hits localhost:36545
β CliGate stores the refresh token
Tokens are persisted in encrypted local storage. The proxy monitors expiry and auto-refreshes when tokens drop below a 5-minute threshold.
- Model Discovery & Routing
After authentication, CliGate calls
loadCodeAssist to resolve the project ID, then fetchAvailableModels to populate the routing table:
claude-sonnet-4-6 β recommended
claude-sonnet-4-6-thinking β thinking variant
claude-opus-4-6 β recommended
claude-opus-4-6-thinking β thinking variant
gemini-2.5-pro
gemini-2.5-flash
Routing is configured via the dashboard:
Claude Code β Antigravity (your-google-email)
Codex CLI β ChatGPT Plus account
Gemini CLI β cloud
- Request Execution & Verification
claude "explain what this regex matches: ^(\d{4})-(\d{2})-(\d{2})$"
The proxy intercepts the Anthropic-formatted request, translates it to Antigravity's generateContent shape, streams the response back as Anthropic SSE, and logs the upstream provider:
14:23:01 POST /v1/messages β antigravity / claude-sonnet-4-6 β 200
Payload Translation & Model Normalization
The critical technical layer handles model ID divergence. Anthropic CLI tools often send legacy aliases (e.g., claude-sonnet-4-5-20250929), while Antigravity requires strict internal identifiers. The proxy normalizes outbound requests and inbound responses:
// Sketch of the normalization
function normalizeForAntigravity(modelId) {
if (modelId.startsWith('claude-sonnet-4-5')) return 'claude-sonnet-4-6';
if (modelId === 'claude-opus-4-6') return 'claude-opus-4-6-thinking';
// ...
return modelId;
}
This translation ensures Claude Code never detects the upstream provider change, maintaining full backward compatibility with existing CLI workflows.
Pitfall Guide
- Model ID Mismatch & Silent 404s: Antigravity does not return descriptive JSON errors for unknown model IDs. It responds with a bare 404. Always normalize legacy Anthropic aliases to Antigravity's internal IDs before routing.
- OAuth Token Lifecycle Mismanagement: Refresh tokens must be rotated proactively. If the proxy waits until exact expiry, race conditions cause 401 drops during streaming. Implement a 5-minute pre-expiry refresh buffer.
- Protocol Shape Incompatibility: Direct TCP proxying fails because Anthropic's
/v1/messages and Google's generateContent have different payload schemas, header requirements, and SSE framing. A translation layer is mandatory.
- Localhost Callback Port Conflicts: The OAuth flow binds to
localhost:36545. Firewall rules, Docker port mapping, or other local services occupying this port will break the callback. Verify port availability before initiating sign-in.
- Quota & Model Availability Drift: Antigravity model access changes based on enterprise quotas and regional rollouts. The proxy must periodically call
loadCodeAssist and fetchAvailableModels to sync the routing table; static configuration will stale.
- Routing Rule Priority Conflicts: When multiple backends are configured, ambiguous routing rules cause fallback to incorrect providers. Explicitly map CLI tools to specific accounts and define clear fallback chains to prevent auth leakage.
- Local Token Storage Security: Refresh tokens grant persistent access to enterprise Google accounts. Always use encrypted local storage with OS-level keychain integration. Never log or expose refresh tokens in plaintext or version control.
Deliverables
- Blueprint:
CliGate-Antigravity-Architecture.pdf β System diagram showing OAuth token lifecycle, payload translation pipeline, SSE reconstruction, and routing decision engine.
- Checklist:
5-Minute-Antigravity-Integration.md β Step-by-step verification list covering proxy startup, OAuth scope validation, port availability, model discovery sync, and routing rule confirmation.
- Configuration Templates:
cligate.config.yaml β Pre-built routing rules, OAuth scope definitions, token refresh thresholds, and model normalization mappings ready for immediate deployment.