-
-
Notifications
You must be signed in to change notification settings - Fork 540
feat: add HTTP/HTTPS proxy support for all API traffic #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aaronsewall
wants to merge
11
commits into
NoeFabris:dev
Choose a base branch
from
aaronsewall:proxy
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+479
−39
Open
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8f2fa57
feat: add HTTP/HTTPS proxy support for all API traffic
aaronsewall af579b4
fix: persist and hydrate proxyUrl in AccountManager
aaronsewall 9543bc4
Update README.md
aaronsewall bad0b49
fix: narrow fetchWithProxy signature to string | URL
aaronsewall 5d27f5d
Merge origin/dev into proxy
aaronsewall b79032b
Merge branch 'dev' into proxy
aaronsewall a6c21d1
Update docs/PROXY.md
aaronsewall 26d7baf
Merge branch 'dev' into proxy
aaronsewall 561fb1e
fix(proxy): address code review feedback on proxy handling
aaronsewall da718b2
merge origin/dev into proxy; ensure all account-bound HTTP calls use …
aaronsewall 3aa8fbf
fix(docs): add language identifiers to fenced code blocks in PROXY.md
aaronsewall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -238,6 +238,44 @@ For details on load balancing, dual quota pools, and account storage, see [docs/ | |
|
|
||
| --- | ||
|
|
||
| ## Proxy Configuration | ||
|
|
||
| Use HTTP/HTTPS proxies for all API traffic (OAuth, token refresh, API calls). Useful for corporate environments or anti-detection setups. | ||
|
|
||
| ### Quick Start | ||
|
|
||
| ```bash | ||
| # Login with proxy - automatically saves to account | ||
| ANTIGRAVITY_LOGIN_PROXY=http://proxy.example.com:8080 opencode auth login | ||
|
|
||
| # All future API calls from this account use the proxy | ||
| opencode run "Hello" --model=google/antigravity-claude-sonnet-4-5 | ||
| ``` | ||
|
|
||
| ### How It Works | ||
|
|
||
| 1. **OAuth Login**: Set `ANTIGRAVITY_LOGIN_PROXY` during `opencode auth login` | ||
| 2. **Auto-Save**: Proxy URL is saved to `~/.config/opencode/antigravity-accounts.json` | ||
| 3. **All Traffic**: All API calls (token refresh, project discovery, API requests) use the proxy | ||
|
|
||
| ### Supported Formats | ||
|
|
||
| - `http://proxy.example.com:8080` - Unauthenticated | ||
| - `http://user:[email protected]:8080` - Authenticated | ||
| - `https://proxy.example.com:443` - TLS proxy | ||
|
|
||
| **Note**: SOCKS5 proxies are NOT supported. Use HTTP/HTTPS only. | ||
|
|
||
| ### Security Warning | ||
|
|
||
| ⚠️ Proxy credentials are stored in **plaintext** in `antigravity-accounts.json` (same as OAuth tokens). Use filesystem permissions to protect this file. | ||
|
|
||
| ### Advanced: Manual Configuration | ||
|
|
||
| See [EXAMPLE_PROXY_CONFIG.md](EXAMPLE_PROXY_CONFIG.md) for manual JSON editing and troubleshooting. | ||
|
|
||
| --- | ||
|
|
||
| ## Troubleshoot | ||
|
|
||
| > **Quick Reset**: Most issues can be resolved by deleting `~/.config/opencode/antigravity-accounts.json` and running `opencode auth login` again. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| # Proxy Configuration Example | ||
|
|
||
| ## OAuth Login Proxy (Recommended) | ||
|
|
||
| **New in v1.3.4**: Use the `ANTIGRAVITY_LOGIN_PROXY` environment variable to configure proxy during account login. The proxy URL will be saved to the account automatically. | ||
|
|
||
| ```bash | ||
| # Login with proxy | ||
| ANTIGRAVITY_LOGIN_PROXY=http://proxy.example.com:8080 opencode auth login | ||
|
|
||
| # Login with authenticated proxy | ||
| ANTIGRAVITY_LOGIN_PROXY=http://user:[email protected]:8080 opencode auth login | ||
| ``` | ||
|
|
||
| The proxy URL is saved to `~/.config/opencode/antigravity-accounts.json` and used for: | ||
| - All OAuth token refreshes | ||
| - Project discovery API calls | ||
| - Gemini/Claude API requests | ||
| - Google Search tool requests | ||
| - Quota check requests | ||
|
|
||
| **Benefits:** | ||
| - No manual JSON editing required | ||
| - Proxy is automatically associated with the account | ||
| - All future API calls from this account use the configured proxy | ||
|
|
||
| ## Manual Proxy Configuration (Alternative) | ||
|
|
||
| Alternatively, you can manually edit your `~/.config/opencode/antigravity-accounts.json` file and add `proxyUrl` fields to each account: | ||
|
|
||
| ```json | ||
| { | ||
| "version": 3, | ||
| "accounts": [ | ||
| { | ||
| "email": "[email protected]", | ||
| "refreshToken": "1//0abc...", | ||
| "projectId": "my-project-1", | ||
| "proxyUrl": "http://user1:[email protected]:8080", | ||
| "addedAt": 1704067200000, | ||
| "lastUsed": 1704153600000 | ||
| }, | ||
| { | ||
| "email": "[email protected]", | ||
| "refreshToken": "1//0def...", | ||
| "projectId": "my-project-2", | ||
| "proxyUrl": "http://user2:[email protected]:8080", | ||
| "addedAt": 1704067300000, | ||
| "lastUsed": 1704153700000 | ||
| }, | ||
| { | ||
| "email": "[email protected]", | ||
| "refreshToken": "1//0ghi...", | ||
| "projectId": "my-project-3", | ||
| "proxyUrl": "https://proxy3.example.com:443", | ||
| "addedAt": 1704067400000, | ||
| "lastUsed": 1704153800000 | ||
| } | ||
| ], | ||
| "activeIndex": 0, | ||
| "activeIndexByFamily": { | ||
| "claude": 0, | ||
| "gemini": 1 | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Supported Proxy Formats | ||
|
|
||
| - **HTTP**: `http://[user:pass@]host:port` | ||
| - **HTTPS**: `https://[user:pass@]host:port` | ||
|
|
||
| **Note**: SOCKS5 proxies are NOT currently supported. Use HTTP/HTTPS proxies only. | ||
|
|
||
| ## Anti-Detection Features | ||
|
|
||
| 1. **Hard Fail**: If proxy fails, request fails immediately - NO direct fallback | ||
| 2. **All Traffic**: Token refresh, project discovery, and API calls all use same proxy | ||
| 3. **Per-Account Isolation**: Each account uses its own proxy → unique IP per account | ||
| 4. **Connection Pooling**: Proxy connections are cached and reused for performance | ||
|
|
||
| ## Important Notes | ||
|
|
||
| - **Credentials**: Proxy passwords stored in plaintext (same security level as OAuth tokens) | ||
| - **Backward Compatible**: Accounts without `proxyUrl` work unchanged (direct connection) | ||
| - **Restart Required**: Changes to `antigravity-accounts.json` require OpenCode restart | ||
| - **Error Handling**: Failed proxy connections mark account "cooling down" for 30 seconds | ||
|
|
||
| ## Testing Your Proxies | ||
|
|
||
| Before adding proxies to all accounts, test one account first: | ||
|
|
||
| ```bash | ||
| # Test proxy during login | ||
| ANTIGRAVITY_LOGIN_PROXY=http://localhost:8080 opencode auth login | ||
|
|
||
| # Watch your proxy logs - you should see: | ||
| # - POST https://oauth2.googleapis.com/token | ||
| # - GET https://www.googleapis.com/oauth2/v1/userinfo | ||
| # - POST to Antigravity loadCodeAssist endpoints | ||
|
|
||
| # Make a test request | ||
| opencode run "Hello" --model=google/antigravity-claude-sonnet-4-5 | ||
aaronsewall marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Proxy logs should show API traffic | ||
| ``` | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Proxy Connection Failed | ||
|
|
||
| ``` | ||
| Error: Failed to create proxy agent for http://proxy:8080: connect ECONNREFUSED | ||
| ``` | ||
|
|
||
| **Solutions:** | ||
| - Check proxy URL format: `http://host:port` (not `https://` unless TLS-enabled proxy) | ||
| - Test proxy with curl: `curl -x http://proxy:8080 https://google.com` | ||
| - Ensure proxy is running and accessible | ||
| - Check firewall rules | ||
|
|
||
| ### Invalid Proxy URL Format | ||
|
|
||
| ``` | ||
| Error: Invalid proxy URL format: http://***:***@:invalid | ||
| ``` | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| **Solutions:** | ||
| - Ensure URL format is correct: `http://user:pass@host:port` | ||
| - Host must be valid hostname or IP address | ||
| - Port must be numeric | ||
|
|
||
| ### Account Cooldown After Proxy Failures | ||
|
|
||
| If proxy fails 5 times consecutively, the account enters a 30-second cooldown to prevent cascading failures. | ||
|
|
||
| **Solutions:** | ||
| - Fix proxy configuration | ||
| - Wait 30 seconds for cooldown to expire | ||
| - Check proxy logs for error details | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.