antigravity-claude-proxy 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Badri Narayanan S
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,289 @@
1
+ # Antigravity Claude Proxy
2
+
3
+ A proxy server that exposes an **Anthropic-compatible API** backed by **Antigravity's Cloud Code**, letting you use Claude models like sonnet and opus with **Claude Code CLI**.
4
+
5
+ ## How It Works
6
+
7
+ ```
8
+ ┌──────────────────┐ ┌─────────────────────┐ ┌────────────────────────────┐
9
+ │ Claude Code │────▶│ This Proxy Server │────▶│ Antigravity Cloud Code │
10
+ │ (Anthropic │ │ (Anthropic → Google│ │ (daily-cloudcode-pa. │
11
+ │ API format) │ │ Generative AI) │ │ sandbox.googleapis.com) │
12
+ └──────────────────┘ └─────────────────────┘ └────────────────────────────┘
13
+ ```
14
+
15
+ 1. Receives requests in **Anthropic Messages API format**
16
+ 2. Uses OAuth tokens from added Google accounts (or Antigravity's local database)
17
+ 3. Transforms to **Google Generative AI format** with Cloud Code wrapping
18
+ 4. Sends to Antigravity's Cloud Code API
19
+ 5. Converts responses back to **Anthropic format** with full thinking/streaming support
20
+
21
+ ## Prerequisites
22
+
23
+ - **Node.js** 18 or later
24
+ - **Antigravity** installed (for single-account mode) OR Google account(s) for multi-account mode
25
+
26
+ ---
27
+
28
+ ## Quick Start
29
+
30
+ ### 1. Install Dependencies
31
+
32
+ ```bash
33
+ npm install
34
+ ```
35
+
36
+ ### 2. Add Account(s)
37
+
38
+ You have two options:
39
+
40
+ **Option A: Use Antigravity (Single Account)**
41
+
42
+ If you have Antigravity installed and logged in, the proxy will automatically extract your token. No additional setup needed.
43
+
44
+ **Option B: Add Google Accounts via OAuth (Recommended for Multi-Account)**
45
+
46
+ Add one or more Google accounts for load balancing:
47
+
48
+ ```bash
49
+ npm run accounts:add
50
+ ```
51
+
52
+ This opens your browser for Google OAuth. Sign in and authorize access. Repeat for multiple accounts.
53
+
54
+ Manage accounts:
55
+
56
+ ```bash
57
+ # List all accounts
58
+ npm run accounts:list
59
+
60
+ # Verify accounts are working
61
+ npm run accounts:verify
62
+
63
+ # Interactive account management
64
+ npm run accounts
65
+ ```
66
+
67
+ ### 3. Start the Proxy Server
68
+
69
+ ```bash
70
+ npm start
71
+ ```
72
+
73
+ The server runs on `http://localhost:8080` by default.
74
+
75
+ ### 4. Verify It's Working
76
+
77
+ ```bash
78
+ # Health check
79
+ curl http://localhost:8080/health
80
+
81
+ # Check account status and quota limits
82
+ curl "http://localhost:8080/account-limits?format=table"
83
+ ```
84
+
85
+ ---
86
+
87
+ ## Using with Claude Code CLI
88
+
89
+ ### Configure Claude Code
90
+
91
+ Create or edit the Claude Code settings file:
92
+
93
+ **macOS:** `~/.claude/settings.json`
94
+ **Linux:** `~/.claude/settings.json`
95
+ **Windows:** `%USERPROFILE%\.claude\settings.json`
96
+
97
+ Add this configuration:
98
+
99
+ ```json
100
+ {
101
+ "env": {
102
+ "ANTHROPIC_AUTH_TOKEN": "test",
103
+ "ANTHROPIC_BASE_URL": "http://localhost:8080",
104
+ "ANTHROPIC_MODEL": "claude-opus-4-5-thinking",
105
+ "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-4-5-thinking",
106
+ "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-4-5-thinking",
107
+ "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-sonnet-4-5",
108
+ "CLAUDE_CODE_SUBAGENT_MODEL": "claude-opus-4-5-thinking"
109
+ }
110
+ }
111
+ ```
112
+
113
+ ### Run Claude Code
114
+
115
+ ```bash
116
+ # Make sure the proxy is running first
117
+ npm start
118
+
119
+ # In another terminal, run Claude Code
120
+ claude
121
+ ```
122
+
123
+ ---
124
+
125
+ ## Available Models
126
+
127
+ | Model ID | Description |
128
+ |----------|-------------|
129
+ | `claude-sonnet-4-5-thinking` | Claude Sonnet 4.5 with extended thinking |
130
+ | `claude-opus-4-5-thinking` | Claude Opus 4.5 with extended thinking |
131
+ | `claude-sonnet-4-5` | Claude Sonnet 4.5 without thinking |
132
+
133
+ Standard Anthropic model names are automatically mapped:
134
+ - `claude-sonnet-4-5-20250514` → `claude-sonnet-4-5-thinking`
135
+ - `claude-opus-4-5-20250514` → `claude-opus-4-5-thinking`
136
+
137
+ ---
138
+
139
+ ## Multi-Account Load Balancing
140
+
141
+ When you add multiple accounts, the proxy automatically:
142
+
143
+ - **Sticky account selection**: Stays on the same account to maximize prompt cache hits
144
+ - **Smart rate limit handling**: Waits for short rate limits (≤2 min), switches accounts for longer ones
145
+ - **Automatic cooldown**: Rate-limited accounts become available after reset time expires
146
+ - **Invalid account detection**: Accounts needing re-authentication are marked and skipped
147
+ - **Prompt caching support**: Stable session IDs enable cache hits across conversation turns
148
+
149
+ Check account status anytime:
150
+
151
+ ```bash
152
+ curl "http://localhost:8080/account-limits?format=table"
153
+ ```
154
+
155
+ ---
156
+
157
+ ## API Endpoints
158
+
159
+ | Endpoint | Method | Description |
160
+ |----------|--------|-------------|
161
+ | `/health` | GET | Health check |
162
+ | `/account-limits` | GET | Account status and quota limits (add `?format=table` for ASCII table) |
163
+ | `/v1/messages` | POST | Anthropic Messages API |
164
+ | `/v1/models` | GET | List available models |
165
+ | `/refresh-token` | POST | Force token refresh |
166
+
167
+ ---
168
+
169
+ ## Testing
170
+
171
+ Run the test suite (requires server running):
172
+
173
+ ```bash
174
+ # Start server in one terminal
175
+ npm start
176
+
177
+ # Run tests in another terminal
178
+ npm test
179
+ ```
180
+
181
+ Individual tests:
182
+
183
+ ```bash
184
+ npm run test:signatures # Thinking signatures
185
+ npm run test:multiturn # Multi-turn with tools
186
+ npm run test:streaming # Streaming SSE events
187
+ npm run test:interleaved # Interleaved thinking
188
+ npm run test:images # Image processing
189
+ npm run test:caching # Prompt caching
190
+ ```
191
+
192
+ ---
193
+
194
+ ## Troubleshooting
195
+
196
+ ### "Could not extract token from Antigravity"
197
+
198
+ If using single-account mode with Antigravity:
199
+ 1. Make sure Antigravity app is installed and running
200
+ 2. Ensure you're logged in to Antigravity
201
+
202
+ Or add accounts via OAuth instead: `npm run accounts:add`
203
+
204
+ ### 401 Authentication Errors
205
+
206
+ The token might have expired. Try:
207
+ ```bash
208
+ curl -X POST http://localhost:8080/refresh-token
209
+ ```
210
+
211
+ Or re-authenticate the account:
212
+ ```bash
213
+ npm run accounts
214
+ ```
215
+
216
+ ### Rate Limiting (429)
217
+
218
+ With multiple accounts, the proxy automatically switches to the next available account. With a single account, you'll need to wait for the rate limit to reset.
219
+
220
+ ### Account Shows as "Invalid"
221
+
222
+ Re-authenticate the account:
223
+ ```bash
224
+ npm run accounts
225
+ # Choose "Re-authenticate" for the invalid account
226
+ ```
227
+
228
+ ---
229
+
230
+ ## Safety, Usage, and Risk Notices
231
+
232
+ ### Intended Use
233
+
234
+ - Personal / internal development only
235
+ - Respect internal quotas and data handling policies
236
+ - Not for production services or bypassing intended limits
237
+
238
+ ### Not Suitable For
239
+
240
+ - Production application traffic
241
+ - High-volume automated extraction
242
+ - Any use that violates Acceptable Use Policies
243
+
244
+ ### Warning (Assumption of Risk)
245
+
246
+ By using this software, you acknowledge and accept the following:
247
+
248
+ - **Terms of Service risk**: This approach may violate the Terms of Service of AI model providers (Anthropic, Google, etc.). You are solely responsible for ensuring compliance with all applicable terms and policies.
249
+
250
+ - **Account risk**: Providers may detect this usage pattern and take punitive action, including suspension, permanent ban, or loss of access to paid subscriptions.
251
+
252
+ - **No guarantees**: Providers may change APIs, authentication, or policies at any time, which can break this method without notice.
253
+
254
+ - **Assumption of risk**: You assume all legal, financial, and technical risks. The authors and contributors of this project bear no responsibility for any consequences arising from your use.
255
+
256
+ **Use at your own risk. Proceed only if you understand and accept these risks.**
257
+
258
+ ---
259
+
260
+ ## Legal
261
+
262
+ - **Not affiliated with Google or Anthropic.** This is an independent open-source project and is not endorsed by, sponsored by, or affiliated with Google LLC or Anthropic PBC.
263
+
264
+ - "Antigravity", "Gemini", "Google Cloud", and "Google" are trademarks of Google LLC.
265
+
266
+ - "Claude" and "Anthropic" are trademarks of Anthropic PBC.
267
+
268
+ - Software is provided "as is", without warranty. You are responsible for complying with all applicable Terms of Service and Acceptable Use Policies.
269
+
270
+ ---
271
+
272
+ ## Credits
273
+
274
+ This project is based on insights and code from:
275
+
276
+ - [opencode-antigravity-auth](https://github.com/NoeFabris/opencode-antigravity-auth) - Antigravity OAuth plugin for OpenCode
277
+ - [claude-code-proxy](https://github.com/1rgs/claude-code-proxy) - Anthropic API proxy using LiteLLM
278
+
279
+ ---
280
+
281
+ ## License
282
+
283
+ MIT
284
+
285
+ ---
286
+
287
+ ## Star History
288
+
289
+ [![Star History Chart](https://api.star-history.com/svg?repos=badri-s2001/antigravity_claude_server&type=date&legend=top-left)](https://www.star-history.com/#badri-s2001/antigravity_claude_server&type=date&legend=top-left)
package/bin/cli.js ADDED
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { fileURLToPath } from 'url';
4
+ import { dirname, join } from 'path';
5
+ import { readFileSync } from 'fs';
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = dirname(__filename);
9
+
10
+ // Read package.json for version
11
+ const packageJson = JSON.parse(
12
+ readFileSync(join(__dirname, '..', 'package.json'), 'utf-8')
13
+ );
14
+
15
+ const args = process.argv.slice(2);
16
+ const command = args[0];
17
+
18
+ function showHelp() {
19
+ console.log(`
20
+ antigravity-proxy v${packageJson.version}
21
+
22
+ Proxy server for using Antigravity's Claude models with Claude Code CLI.
23
+
24
+ USAGE:
25
+ antigravity-proxy <command> [options]
26
+
27
+ COMMANDS:
28
+ start Start the proxy server (default port: 8080)
29
+ accounts Manage Google accounts (interactive)
30
+ accounts add Add a new Google account via OAuth
31
+ accounts list List all configured accounts
32
+ accounts remove Remove accounts interactively
33
+ accounts verify Verify account tokens are valid
34
+ accounts clear Remove all accounts
35
+
36
+ OPTIONS:
37
+ --help, -h Show this help message
38
+ --version, -v Show version number
39
+
40
+ ENVIRONMENT:
41
+ PORT Server port (default: 8080)
42
+
43
+ EXAMPLES:
44
+ antigravity-proxy start
45
+ PORT=3000 antigravity-proxy start
46
+ antigravity-proxy accounts add
47
+ antigravity-proxy accounts list
48
+
49
+ CONFIGURATION:
50
+ Claude Code CLI (~/.claude/settings.json):
51
+ {
52
+ "env": {
53
+ "ANTHROPIC_BASE_URL": "http://localhost:8080"
54
+ }
55
+ }
56
+ `);
57
+ }
58
+
59
+ function showVersion() {
60
+ console.log(packageJson.version);
61
+ }
62
+
63
+ async function main() {
64
+ // Handle flags
65
+ if (args.includes('--help') || args.includes('-h')) {
66
+ showHelp();
67
+ process.exit(0);
68
+ }
69
+
70
+ if (args.includes('--version') || args.includes('-v')) {
71
+ showVersion();
72
+ process.exit(0);
73
+ }
74
+
75
+ // Handle commands
76
+ switch (command) {
77
+ case 'start':
78
+ case undefined:
79
+ // Default to starting the server
80
+ await import('../src/index.js');
81
+ break;
82
+
83
+ case 'accounts': {
84
+ // Pass remaining args to accounts CLI
85
+ const subCommand = args[1] || 'add';
86
+ process.argv = ['node', 'accounts-cli.js', subCommand, ...args.slice(2)];
87
+ await import('../src/accounts-cli.js');
88
+ break;
89
+ }
90
+
91
+ case 'help':
92
+ showHelp();
93
+ break;
94
+
95
+ case 'version':
96
+ showVersion();
97
+ break;
98
+
99
+ default:
100
+ console.error(`Unknown command: ${command}`);
101
+ console.error('Run "antigravity-proxy --help" for usage information.');
102
+ process.exit(1);
103
+ }
104
+ }
105
+
106
+ main().catch((err) => {
107
+ console.error('Error:', err.message);
108
+ process.exit(1);
109
+ });
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "antigravity-claude-proxy",
3
+ "version": "1.0.0",
4
+ "description": "Proxy server to use Antigravity's Claude models with Claude Code CLI",
5
+ "main": "src/index.js",
6
+ "type": "module",
7
+ "bin": {
8
+ "antigravity-proxy": "./bin/cli.js"
9
+ },
10
+ "files": [
11
+ "src",
12
+ "bin"
13
+ ],
14
+ "scripts": {
15
+ "start": "node src/index.js",
16
+ "dev": "node --watch src/index.js",
17
+ "accounts": "node src/accounts-cli.js",
18
+ "accounts:add": "node src/accounts-cli.js add",
19
+ "accounts:list": "node src/accounts-cli.js list",
20
+ "accounts:remove": "node src/accounts-cli.js remove",
21
+ "accounts:verify": "node src/accounts-cli.js verify",
22
+ "test": "node tests/run-all.cjs",
23
+ "test:signatures": "node tests/test-thinking-signatures.cjs",
24
+ "test:multiturn": "node tests/test-multiturn-thinking-tools.cjs",
25
+ "test:streaming": "node tests/test-multiturn-thinking-tools-streaming.cjs",
26
+ "test:interleaved": "node tests/test-interleaved-thinking.cjs",
27
+ "test:images": "node tests/test-images.cjs",
28
+ "test:caching": "node tests/test-caching-streaming.cjs"
29
+ },
30
+ "keywords": [
31
+ "claude",
32
+ "anthropic",
33
+ "antigravity",
34
+ "proxy",
35
+ "vertex-ai"
36
+ ],
37
+ "author": "Badri Narayanan",
38
+ "license": "MIT",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/badri-s2001/antigravity_claude_server.git"
42
+ },
43
+ "homepage": "https://github.com/badri-s2001/antigravity_claude_server#readme",
44
+ "bugs": {
45
+ "url": "https://github.com/badri-s2001/antigravity_claude_server/issues"
46
+ },
47
+ "engines": {
48
+ "node": ">=18.0.0"
49
+ },
50
+ "dependencies": {
51
+ "cors": "^2.8.5",
52
+ "express": "^4.18.2"
53
+ }
54
+ }