copilot-api-plus 1.0.54 → 1.0.56
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/README.en.md +839 -0
- package/README.md +2 -0
- package/dist/{auth-BrdL89xk.js → auth-DIDShcrD.js} +10 -5
- package/dist/{auth-BrdL89xk.js.map → auth-DIDShcrD.js.map} +1 -1
- package/dist/{auth-CWGl6kMf.js → auth-D_mymhYC.js} +10 -5
- package/dist/{auth-CWGl6kMf.js.map → auth-D_mymhYC.js.map} +1 -1
- package/dist/auth-DreFwlx2.js +3 -0
- package/dist/auth-g7psLP1B.js +3 -0
- package/dist/{error-CTmiDu8a.js → error-CvvAyU1E.js} +7 -5
- package/dist/error-CvvAyU1E.js.map +1 -0
- package/dist/error-Djpro28X.js +2 -0
- package/dist/{get-models-uEbEgq0L.js → get-models-DhYpjJVG.js} +11 -7
- package/dist/get-models-DhYpjJVG.js.map +1 -0
- package/dist/get-models-PKzVxQmq.js +4 -0
- package/dist/{get-models-DJfPj_Rg.js → get-models-onnSXkNI.js} +8 -4
- package/dist/{get-models-DJfPj_Rg.js.map → get-models-onnSXkNI.js.map} +1 -1
- package/dist/get-user-CGhBmkXO.js +3 -0
- package/dist/{get-user-DOjM9pn9.js → get-user-DOv07Myc.js} +14 -16
- package/dist/get-user-DOv07Myc.js.map +1 -0
- package/dist/main.js +512 -505
- package/dist/main.js.map +1 -1
- package/dist/{paths-CVYLp61D.js → paths-BdbyVdad.js} +4 -6
- package/dist/{paths-CVYLp61D.js.map → paths-BdbyVdad.js.map} +1 -1
- package/dist/{state-CcLGr8VN.js → state-CRpaW-qc.js} +3 -3
- package/dist/state-CRpaW-qc.js.map +1 -0
- package/dist/token-CoKq3Guw.js +5 -0
- package/dist/{token-CnocHC_C.js → token-D8U-wBLK.js} +7 -14
- package/dist/token-D8U-wBLK.js.map +1 -0
- package/package.json +2 -3
- package/dist/auth-BizgZEf2.js +0 -4
- package/dist/auth-pRwfByMF.js +0 -4
- package/dist/error-CBKWgD6B.js +0 -3
- package/dist/error-CTmiDu8a.js.map +0 -1
- package/dist/get-models-COPf69Aa.js +0 -5
- package/dist/get-models-uEbEgq0L.js.map +0 -1
- package/dist/get-user-D1SF4af1.js +0 -5
- package/dist/get-user-DOjM9pn9.js.map +0 -1
- package/dist/state-CcLGr8VN.js.map +0 -1
- package/dist/token-2K-Nf49r.js +0 -7
- package/dist/token-CnocHC_C.js.map +0 -1
package/README.en.md
ADDED
|
@@ -0,0 +1,839 @@
|
|
|
1
|
+
# Copilot API Plus
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/copilot-api-plus)
|
|
4
|
+
[](https://github.com/imbuxiangnan-cyber/copilot-api-plus/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
English | [简体中文](README.md)
|
|
7
|
+
|
|
8
|
+
> A proxy that converts GitHub Copilot, OpenCode Zen, and Google Antigravity into OpenAI & Anthropic compatible APIs. Works with Claude Code, opencode, and more.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 📋 Table of Contents
|
|
13
|
+
|
|
14
|
+
- [Features](#-features)
|
|
15
|
+
- [Quick Start](#-quick-start)
|
|
16
|
+
- [Usage Guide](#-usage-guide)
|
|
17
|
+
- [GitHub Copilot Mode](#1-github-copilot-mode-default)
|
|
18
|
+
- [OpenCode Zen Mode](#2-opencode-zen-mode)
|
|
19
|
+
- [Google Antigravity Mode](#3-google-antigravity-mode)
|
|
20
|
+
- [Proxy Configuration](#-proxy-configuration)
|
|
21
|
+
- [Claude Code Integration](#-claude-code-integration)
|
|
22
|
+
- [opencode Integration](#-opencode-integration)
|
|
23
|
+
- [API Endpoints](#-api-endpoints)
|
|
24
|
+
- [API Key Authentication](#-api-key-authentication)
|
|
25
|
+
- [Technical Details](#-technical-details)
|
|
26
|
+
- [CLI Reference](#️-cli-reference)
|
|
27
|
+
- [Docker Deployment](#-docker-deployment)
|
|
28
|
+
- [FAQ](#-faq)
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## ✨ Features
|
|
33
|
+
|
|
34
|
+
| Feature | Description |
|
|
35
|
+
|---------|-------------|
|
|
36
|
+
| 🔌 **Multiple Backends** | Choose from GitHub Copilot, OpenCode Zen, or Google Antigravity |
|
|
37
|
+
| 🤖 **Dual Protocol** | Supports both OpenAI Chat Completions API and Anthropic Messages API |
|
|
38
|
+
| 💻 **Claude Code Integration** | One-command Claude Code setup (`--claude-code`) |
|
|
39
|
+
| 📊 **Usage Monitoring** | Real-time API usage dashboard |
|
|
40
|
+
| 🔄 **Auto Authentication** | Automatic token refresh, no manual intervention needed |
|
|
41
|
+
| ⚡ **Rate Limiting** | Built-in request rate control to avoid hitting limits |
|
|
42
|
+
| 🌐 **Proxy Support** | HTTP/HTTPS proxy with persistent configuration |
|
|
43
|
+
| 🐳 **Docker Support** | Full Docker deployment solution |
|
|
44
|
+
| 🔑 **API Key Auth** | Optional API key authentication for public deployments |
|
|
45
|
+
| ✂️ **Context Passthrough** | Full context passthrough to upstream API; clients (e.g. Claude Code) manage compression |
|
|
46
|
+
| 🔍 **Smart Model Matching** | Handles model name format differences (date suffixes, dash/dot versions, etc.) |
|
|
47
|
+
| 🔁 **Antigravity Failover** | Dual-endpoint auto-switching with per-model-family rate tracking and exponential backoff |
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## 🚀 Quick Start
|
|
52
|
+
|
|
53
|
+
### Installation
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# Global install
|
|
57
|
+
npm install -g copilot-api-plus
|
|
58
|
+
|
|
59
|
+
# Or run directly with npx (recommended)
|
|
60
|
+
npx copilot-api-plus@latest start
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Basic Usage
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# Start server (defaults to GitHub Copilot)
|
|
67
|
+
npx copilot-api-plus@latest start
|
|
68
|
+
|
|
69
|
+
# Use OpenCode Zen
|
|
70
|
+
npx copilot-api-plus@latest start --zen
|
|
71
|
+
|
|
72
|
+
# Use Google Antigravity
|
|
73
|
+
npx copilot-api-plus@latest start --antigravity
|
|
74
|
+
|
|
75
|
+
# Use with Claude Code
|
|
76
|
+
npx copilot-api-plus@latest start --claude-code
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The server listens on `http://localhost:4141` by default.
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 📖 Usage Guide
|
|
84
|
+
|
|
85
|
+
### 1. GitHub Copilot Mode (Default)
|
|
86
|
+
|
|
87
|
+
Access AI models using your GitHub Copilot subscription.
|
|
88
|
+
|
|
89
|
+
#### Prerequisites
|
|
90
|
+
- GitHub account
|
|
91
|
+
- Active Copilot subscription (Individual / Business / Enterprise)
|
|
92
|
+
|
|
93
|
+
#### Getting Started
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npx copilot-api-plus@latest start
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**First run** will guide you through GitHub OAuth authentication:
|
|
100
|
+
|
|
101
|
+
1. A device code appears in the terminal, e.g.: `XXXX-XXXX`
|
|
102
|
+
2. Open your browser and visit: https://github.com/login/device
|
|
103
|
+
3. Enter the device code and authorize
|
|
104
|
+
4. Return to the terminal and wait for authentication to complete
|
|
105
|
+
|
|
106
|
+
Once authenticated, the token is saved locally. No re-authentication needed on subsequent runs.
|
|
107
|
+
|
|
108
|
+
#### Business / Enterprise Accounts
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# Business plan
|
|
112
|
+
npx copilot-api-plus@latest start --account-type business
|
|
113
|
+
|
|
114
|
+
# Enterprise plan
|
|
115
|
+
npx copilot-api-plus@latest start --account-type enterprise
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### Available Models
|
|
119
|
+
|
|
120
|
+
| Model | ID | Context Length |
|
|
121
|
+
|-------|-----|---------------|
|
|
122
|
+
| Claude Sonnet 4 | `claude-sonnet-4` | 200K |
|
|
123
|
+
| Claude Sonnet 4.5 | `claude-sonnet-4.5` | 200K |
|
|
124
|
+
| GPT-4.1 | `gpt-4.1` | 1M |
|
|
125
|
+
| o4-mini | `o4-mini` | 200K |
|
|
126
|
+
| Gemini 2.5 Pro | `gemini-2.5-pro` | 1M |
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
### 2. OpenCode Zen Mode
|
|
131
|
+
|
|
132
|
+
Use [OpenCode Zen](https://opencode.ai/zen)'s multi-model API service, supporting GPT-5, Claude, Gemini, and other top coding models.
|
|
133
|
+
|
|
134
|
+
#### Prerequisites
|
|
135
|
+
1. Visit https://opencode.ai/zen
|
|
136
|
+
2. Register and create an API Key
|
|
137
|
+
|
|
138
|
+
#### Getting Started
|
|
139
|
+
|
|
140
|
+
**Option 1: Interactive setup**
|
|
141
|
+
```bash
|
|
142
|
+
npx copilot-api-plus@latest start --zen
|
|
143
|
+
```
|
|
144
|
+
First run will prompt for an API Key, which is saved for future use.
|
|
145
|
+
|
|
146
|
+
**Option 2: Provide API Key directly**
|
|
147
|
+
```bash
|
|
148
|
+
npx copilot-api-plus@latest start --zen --zen-api-key YOUR_API_KEY
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
#### Available Models
|
|
152
|
+
|
|
153
|
+
| Model | ID | Description |
|
|
154
|
+
|-------|-----|-------------|
|
|
155
|
+
| GPT-5.2 | `gpt-5.2` | OpenAI latest |
|
|
156
|
+
| GPT-5.1 Codex Max | `gpt-5.1-codex-max` | Code-optimized |
|
|
157
|
+
| GPT-5.1 Codex | `gpt-5.1-codex` | Code-focused |
|
|
158
|
+
| GPT-5 Codex | `gpt-5-codex` | OpenAI Responses API |
|
|
159
|
+
| Claude Opus 4.5 | `claude-opus-4-5` | Anthropic Claude (200K) |
|
|
160
|
+
| Claude Sonnet 4.5 | `claude-sonnet-4-5` | Anthropic Claude (200K) |
|
|
161
|
+
| Claude Sonnet 4 | `claude-sonnet-4` | Anthropic Claude |
|
|
162
|
+
| Gemini 3 Pro | `gemini-3-pro` | Google Gemini |
|
|
163
|
+
| Qwen3 Coder | `qwen3-coder` | Alibaba Qwen |
|
|
164
|
+
| Kimi K2 | `kimi-k2` | Moonshot |
|
|
165
|
+
| Grok Code Fast 1 | `grok-code-fast-1` | xAI |
|
|
166
|
+
|
|
167
|
+
More models at [opencode.ai/zen](https://opencode.ai/zen)
|
|
168
|
+
|
|
169
|
+
#### API Endpoints
|
|
170
|
+
|
|
171
|
+
Zen mode supports the following endpoints:
|
|
172
|
+
|
|
173
|
+
| Endpoint | Description |
|
|
174
|
+
|----------|-------------|
|
|
175
|
+
| `/v1/chat/completions` | OpenAI-compatible Chat API |
|
|
176
|
+
| `/v1/messages` | Anthropic-compatible Messages API |
|
|
177
|
+
| `/v1/responses` | OpenAI Responses API (GPT-5 series) |
|
|
178
|
+
| `/v1/models` | List available models |
|
|
179
|
+
|
|
180
|
+
Dedicated endpoints (accessible without `--zen` flag):
|
|
181
|
+
- `/zen/v1/chat/completions`
|
|
182
|
+
- `/zen/v1/messages`
|
|
183
|
+
- `/zen/v1/responses`
|
|
184
|
+
- `/zen/v1/models`
|
|
185
|
+
|
|
186
|
+
#### Manage API Key
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# View/change API Key (clearing it will prompt for a new one on next start)
|
|
190
|
+
npx copilot-api-plus@latest logout --zen
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
### 3. Google Antigravity Mode
|
|
196
|
+
|
|
197
|
+
Use Google Antigravity API service, supporting Gemini and Claude models.
|
|
198
|
+
|
|
199
|
+
#### Prerequisites
|
|
200
|
+
- Google account
|
|
201
|
+
|
|
202
|
+
#### Authentication Methods
|
|
203
|
+
|
|
204
|
+
**Option 1: API Key (Recommended - Simplest)**
|
|
205
|
+
|
|
206
|
+
1. Get an API Key at https://aistudio.google.com/apikey
|
|
207
|
+
2. Start with environment variable:
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
# Linux/macOS
|
|
211
|
+
GEMINI_API_KEY=your_api_key npx copilot-api-plus@latest start --antigravity
|
|
212
|
+
|
|
213
|
+
# Windows PowerShell
|
|
214
|
+
$env:GEMINI_API_KEY = "your_api_key"
|
|
215
|
+
npx copilot-api-plus@latest start --antigravity
|
|
216
|
+
|
|
217
|
+
# Windows CMD
|
|
218
|
+
set GEMINI_API_KEY=your_api_key
|
|
219
|
+
npx copilot-api-plus@latest start --antigravity
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**Option 2: OAuth Web Login (Recommended)**
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
npx copilot-api-plus@latest start --antigravity
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
First run will prompt you to choose a login method:
|
|
229
|
+
- **Web (Recommended)**: Opens browser for Google login, automatically captures the callback
|
|
230
|
+
- **Manual**: Manually copy the callback URL to the terminal
|
|
231
|
+
|
|
232
|
+
**Option 3: Custom OAuth Credentials**
|
|
233
|
+
|
|
234
|
+
If you encounter an `invalid_client` error, create your own OAuth app:
|
|
235
|
+
|
|
236
|
+
1. Visit https://console.cloud.google.com/apis/credentials
|
|
237
|
+
2. Create an OAuth 2.0 Client ID (select "Desktop application" type)
|
|
238
|
+
3. Add redirect URI: `http://localhost:8046/callback`
|
|
239
|
+
4. Use environment variables or CLI arguments:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
# Environment variables
|
|
243
|
+
ANTIGRAVITY_CLIENT_ID=your_client_id ANTIGRAVITY_CLIENT_SECRET=your_secret \
|
|
244
|
+
npx copilot-api-plus@latest start --antigravity
|
|
245
|
+
|
|
246
|
+
# CLI arguments
|
|
247
|
+
npx copilot-api-plus@latest start --antigravity \
|
|
248
|
+
--antigravity-client-id your_client_id \
|
|
249
|
+
--antigravity-client-secret your_secret
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
#### Available Models
|
|
253
|
+
|
|
254
|
+
| Model | ID | Description |
|
|
255
|
+
|-------|-----|-------------|
|
|
256
|
+
| Gemini 2.5 Pro | `gemini-2.5-pro-exp-03-25` | Google Gemini |
|
|
257
|
+
| Gemini 2.5 Pro Preview | `gemini-2.5-pro-preview-05-06` | Google Gemini |
|
|
258
|
+
| Gemini 2.0 Flash | `gemini-2.0-flash-exp` | Fast responses |
|
|
259
|
+
| Gemini 2.0 Flash Thinking | `gemini-2.0-flash-thinking-exp` | Chain-of-thought |
|
|
260
|
+
| Claude Opus 4.5 | `claude-opus-4-5` | Anthropic Claude |
|
|
261
|
+
| Claude Sonnet 4.5 | `claude-sonnet-4-5` | Anthropic Claude |
|
|
262
|
+
|
|
263
|
+
#### Features
|
|
264
|
+
- ✅ Automatic token refresh
|
|
265
|
+
- ✅ Multi-account support with auto-rotation
|
|
266
|
+
- ✅ Auto-switch on quota exhaustion
|
|
267
|
+
- ✅ Thinking model support (chain-of-thought output)
|
|
268
|
+
|
|
269
|
+
#### Multi-Account Management
|
|
270
|
+
|
|
271
|
+
Add multiple Google accounts; the system auto-switches when quota is exhausted:
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
# Add new account
|
|
275
|
+
npx copilot-api-plus@latest antigravity add
|
|
276
|
+
|
|
277
|
+
# List all accounts
|
|
278
|
+
npx copilot-api-plus@latest antigravity list
|
|
279
|
+
|
|
280
|
+
# Remove account by index
|
|
281
|
+
npx copilot-api-plus@latest antigravity remove 0
|
|
282
|
+
|
|
283
|
+
# Clear all accounts
|
|
284
|
+
npx copilot-api-plus@latest antigravity clear
|
|
285
|
+
# Or use logout
|
|
286
|
+
npx copilot-api-plus@latest logout --antigravity
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## 🌐 Proxy Configuration
|
|
292
|
+
|
|
293
|
+
Two ways to configure a proxy:
|
|
294
|
+
|
|
295
|
+
### Option 1: Persistent Configuration (Recommended)
|
|
296
|
+
|
|
297
|
+
Configure once, automatically used on every startup.
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
# Interactive setup
|
|
301
|
+
npx copilot-api-plus@latest proxy --set
|
|
302
|
+
|
|
303
|
+
# Or set directly
|
|
304
|
+
npx copilot-api-plus@latest proxy --http-proxy http://127.0.0.1:7890
|
|
305
|
+
|
|
306
|
+
# Set both HTTP and HTTPS proxy
|
|
307
|
+
npx copilot-api-plus@latest proxy --http-proxy http://127.0.0.1:7890 --https-proxy http://127.0.0.1:7890
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
#### Proxy Management Commands
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
# View current proxy settings
|
|
314
|
+
npx copilot-api-plus@latest proxy
|
|
315
|
+
|
|
316
|
+
# Enable proxy
|
|
317
|
+
npx copilot-api-plus@latest proxy --enable
|
|
318
|
+
|
|
319
|
+
# Disable proxy (keeps settings)
|
|
320
|
+
npx copilot-api-plus@latest proxy --disable
|
|
321
|
+
|
|
322
|
+
# Clear proxy settings
|
|
323
|
+
npx copilot-api-plus@latest proxy --clear
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
#### Example: Configure Clash Proxy
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
# Clash default port 7890
|
|
330
|
+
npx copilot-api-plus@latest proxy --http-proxy http://127.0.0.1:7890
|
|
331
|
+
|
|
332
|
+
# Verify configuration
|
|
333
|
+
npx copilot-api-plus@latest proxy
|
|
334
|
+
# Output:
|
|
335
|
+
# Current proxy configuration:
|
|
336
|
+
# Status: ✅ Enabled
|
|
337
|
+
# HTTP_PROXY: http://127.0.0.1:7890
|
|
338
|
+
# HTTPS_PROXY: http://127.0.0.1:7890
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### Option 2: Environment Variables (Temporary)
|
|
342
|
+
|
|
343
|
+
Only effective for the current session:
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
# Linux/macOS
|
|
347
|
+
export HTTP_PROXY=http://127.0.0.1:7890
|
|
348
|
+
export HTTPS_PROXY=http://127.0.0.1:7890
|
|
349
|
+
npx copilot-api-plus@latest start --proxy-env
|
|
350
|
+
|
|
351
|
+
# Windows PowerShell
|
|
352
|
+
$env:HTTP_PROXY = "http://127.0.0.1:7890"
|
|
353
|
+
$env:HTTPS_PROXY = "http://127.0.0.1:7890"
|
|
354
|
+
npx copilot-api-plus@latest start --proxy-env
|
|
355
|
+
|
|
356
|
+
# Windows CMD
|
|
357
|
+
set HTTP_PROXY=http://127.0.0.1:7890
|
|
358
|
+
set HTTPS_PROXY=http://127.0.0.1:7890
|
|
359
|
+
npx copilot-api-plus@latest start --proxy-env
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
### Proxy Priority
|
|
363
|
+
|
|
364
|
+
1. `--proxy-env` flag (reads from environment variables)
|
|
365
|
+
2. Persistent configuration (set via `proxy --set`)
|
|
366
|
+
3. No proxy
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
## 💻 Claude Code Integration
|
|
371
|
+
|
|
372
|
+
[Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview) is Anthropic's AI coding assistant.
|
|
373
|
+
|
|
374
|
+
### Auto Configuration (Recommended)
|
|
375
|
+
|
|
376
|
+
```bash
|
|
377
|
+
# Using GitHub Copilot as backend
|
|
378
|
+
npx copilot-api-plus@latest start --claude-code
|
|
379
|
+
|
|
380
|
+
# Using OpenCode Zen as backend
|
|
381
|
+
npx copilot-api-plus@latest start --zen --claude-code
|
|
382
|
+
|
|
383
|
+
# Using Google Antigravity as backend
|
|
384
|
+
npx copilot-api-plus@latest start --antigravity --claude-code
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
After running:
|
|
388
|
+
1. Select main model (for code generation)
|
|
389
|
+
2. Select fast model (for background tasks)
|
|
390
|
+
3. The launch command is automatically copied to clipboard
|
|
391
|
+
4. **Open a new terminal**, paste and run to start Claude Code
|
|
392
|
+
|
|
393
|
+
### Manual Configuration
|
|
394
|
+
|
|
395
|
+
Create `.claude/settings.json` in your project root:
|
|
396
|
+
|
|
397
|
+
```json
|
|
398
|
+
{
|
|
399
|
+
"env": {
|
|
400
|
+
"ANTHROPIC_BASE_URL": "http://localhost:4141",
|
|
401
|
+
"ANTHROPIC_AUTH_TOKEN": "dummy",
|
|
402
|
+
"ANTHROPIC_MODEL": "claude-sonnet-4",
|
|
403
|
+
"ANTHROPIC_SMALL_FAST_MODEL": "gpt-4.1",
|
|
404
|
+
"DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1"
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
Then start the copilot-api-plus server and run `claude` in that project directory.
|
|
410
|
+
|
|
411
|
+
---
|
|
412
|
+
|
|
413
|
+
## 🔧 opencode Integration
|
|
414
|
+
|
|
415
|
+
[opencode](https://github.com/sst/opencode) is a modern AI coding assistant.
|
|
416
|
+
|
|
417
|
+
### Setup
|
|
418
|
+
|
|
419
|
+
1. Create `opencode.json` in your project root:
|
|
420
|
+
|
|
421
|
+
```json
|
|
422
|
+
{
|
|
423
|
+
"$schema": "https://opencode.ai/config.json",
|
|
424
|
+
"provider": {
|
|
425
|
+
"copilot-api-plus": {
|
|
426
|
+
"api": "openai-compatible",
|
|
427
|
+
"name": "Copilot API Plus",
|
|
428
|
+
"options": {
|
|
429
|
+
"baseURL": "http://127.0.0.1:4141/v1"
|
|
430
|
+
},
|
|
431
|
+
"models": {
|
|
432
|
+
"claude-sonnet-4": {
|
|
433
|
+
"name": "Claude Sonnet 4",
|
|
434
|
+
"id": "claude-sonnet-4",
|
|
435
|
+
"max_tokens": 64000,
|
|
436
|
+
"profile": "coder",
|
|
437
|
+
"limit": { "context": 200000 }
|
|
438
|
+
},
|
|
439
|
+
"gpt-4.1": {
|
|
440
|
+
"name": "GPT-4.1",
|
|
441
|
+
"id": "gpt-4.1",
|
|
442
|
+
"max_tokens": 32768,
|
|
443
|
+
"profile": "coder",
|
|
444
|
+
"limit": { "context": 1047576 }
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
2. Start copilot-api-plus:
|
|
453
|
+
```bash
|
|
454
|
+
npx copilot-api-plus@latest start
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
3. Run opencode in the same directory:
|
|
458
|
+
```bash
|
|
459
|
+
npx opencode@latest
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
4. Select `copilot-api-plus` as the provider
|
|
463
|
+
|
|
464
|
+
### Shortcut: Environment Variables
|
|
465
|
+
|
|
466
|
+
```bash
|
|
467
|
+
# Set environment variables
|
|
468
|
+
export OPENAI_BASE_URL=http://127.0.0.1:4141/v1
|
|
469
|
+
export OPENAI_API_KEY=dummy
|
|
470
|
+
|
|
471
|
+
# Run opencode
|
|
472
|
+
npx opencode@latest
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
---
|
|
476
|
+
|
|
477
|
+
## 📡 API Endpoints
|
|
478
|
+
|
|
479
|
+
The server listens on `http://localhost:4141` by default.
|
|
480
|
+
|
|
481
|
+
### OpenAI-Compatible Endpoints
|
|
482
|
+
|
|
483
|
+
| Endpoint | Method | Description |
|
|
484
|
+
|----------|--------|-------------|
|
|
485
|
+
| `/v1/chat/completions` | POST | Chat completions (streaming supported) |
|
|
486
|
+
| `/v1/models` | GET | Model list |
|
|
487
|
+
| `/v1/embeddings` | POST | Text embeddings (Copilot only) |
|
|
488
|
+
|
|
489
|
+
### Anthropic-Compatible Endpoints
|
|
490
|
+
|
|
491
|
+
| Endpoint | Method | Description |
|
|
492
|
+
|----------|--------|-------------|
|
|
493
|
+
| `/v1/messages` | POST | Messages API (streaming supported) |
|
|
494
|
+
| `/v1/messages/count_tokens` | POST | Token counting |
|
|
495
|
+
|
|
496
|
+
### Dedicated Endpoints
|
|
497
|
+
|
|
498
|
+
Each backend has its own dedicated routes, accessible regardless of the default backend:
|
|
499
|
+
|
|
500
|
+
| Route Prefix | Description |
|
|
501
|
+
|--------------|-------------|
|
|
502
|
+
| `/copilot/v1/*` | GitHub Copilot |
|
|
503
|
+
| `/zen/v1/*` | OpenCode Zen |
|
|
504
|
+
| `/antigravity/v1/*` | Google Antigravity |
|
|
505
|
+
|
|
506
|
+
### Monitoring Endpoints
|
|
507
|
+
|
|
508
|
+
| Endpoint | Method | Description |
|
|
509
|
+
|----------|--------|-------------|
|
|
510
|
+
| `/usage` | GET | Usage statistics (Copilot only) |
|
|
511
|
+
| `/token` | GET | Current token info |
|
|
512
|
+
|
|
513
|
+
### Examples
|
|
514
|
+
|
|
515
|
+
```bash
|
|
516
|
+
# OpenAI format
|
|
517
|
+
curl http://localhost:4141/v1/chat/completions \
|
|
518
|
+
-H "Content-Type: application/json" \
|
|
519
|
+
-d '{
|
|
520
|
+
"model": "claude-sonnet-4",
|
|
521
|
+
"messages": [{"role": "user", "content": "Hello!"}]
|
|
522
|
+
}'
|
|
523
|
+
|
|
524
|
+
# Anthropic format
|
|
525
|
+
curl http://localhost:4141/v1/messages \
|
|
526
|
+
-H "Content-Type: application/json" \
|
|
527
|
+
-H "x-api-key: dummy" \
|
|
528
|
+
-d '{
|
|
529
|
+
"model": "claude-sonnet-4",
|
|
530
|
+
"max_tokens": 1024,
|
|
531
|
+
"messages": [{"role": "user", "content": "Hello!"}]
|
|
532
|
+
}'
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
---
|
|
536
|
+
|
|
537
|
+
## 🔑 API Key Authentication
|
|
538
|
+
|
|
539
|
+
To protect your service when exposed publicly, enable API key authentication:
|
|
540
|
+
|
|
541
|
+
```bash
|
|
542
|
+
# Single key
|
|
543
|
+
npx copilot-api-plus@latest start --api-key my-secret-key
|
|
544
|
+
|
|
545
|
+
# Multiple keys
|
|
546
|
+
npx copilot-api-plus@latest start --api-key key1 --api-key key2
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
Once enabled, all requests must include an API key:
|
|
550
|
+
|
|
551
|
+
```bash
|
|
552
|
+
# OpenAI format - via Authorization header
|
|
553
|
+
curl http://localhost:4141/v1/chat/completions \
|
|
554
|
+
-H "Authorization: Bearer my-secret-key" \
|
|
555
|
+
-H "Content-Type: application/json" \
|
|
556
|
+
-d '{"model": "claude-sonnet-4", "messages": [{"role": "user", "content": "Hello"}]}'
|
|
557
|
+
|
|
558
|
+
# Anthropic format - via x-api-key header
|
|
559
|
+
curl http://localhost:4141/v1/messages \
|
|
560
|
+
-H "x-api-key: my-secret-key" \
|
|
561
|
+
-H "Content-Type: application/json" \
|
|
562
|
+
-d '{"model": "claude-sonnet-4", "max_tokens": 1024, "messages": [{"role": "user", "content": "Hello"}]}'
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
When using with Claude Code, set `ANTHROPIC_AUTH_TOKEN` to your API key.
|
|
566
|
+
|
|
567
|
+
---
|
|
568
|
+
|
|
569
|
+
## 🔧 Technical Details
|
|
570
|
+
|
|
571
|
+
### Context Management
|
|
572
|
+
|
|
573
|
+
The proxy does not truncate context. All messages are passed through to the upstream API as-is. Context compression is handled by the client:
|
|
574
|
+
|
|
575
|
+
- **Claude Code**: Uses `/count_tokens` to get the current token count, and automatically triggers `/compact` when approaching the limit
|
|
576
|
+
- **Other clients**: If the upstream API returns 400 (token limit exceeded), the client handles retry logic
|
|
577
|
+
|
|
578
|
+
### Smart Model Name Matching
|
|
579
|
+
|
|
580
|
+
Anthropic-format model names (e.g. `claude-opus-4-6`) may differ from Copilot's model list IDs. The proxy uses multi-strategy matching:
|
|
581
|
+
|
|
582
|
+
| Strategy | Example |
|
|
583
|
+
|----------|---------|
|
|
584
|
+
| Exact match | `claude-opus-4-6` → `claude-opus-4-6` |
|
|
585
|
+
| Strip date suffix | `claude-opus-4-6-20251101` → `claude-opus-4-6` |
|
|
586
|
+
| Dash → Dot | `claude-opus-4-5` → `claude-opus-4.5` |
|
|
587
|
+
| Dot → Dash | `claude-opus-4.5` → `claude-opus-4-5` |
|
|
588
|
+
|
|
589
|
+
For Anthropic endpoints (`/v1/messages`), `translateModelName` also handles legacy format conversion (e.g. `claude-3-5-sonnet` → `claude-sonnet-4.5`) before applying the above strategies.
|
|
590
|
+
|
|
591
|
+
### Antigravity Endpoint Failover
|
|
592
|
+
|
|
593
|
+
Google Antigravity mode has built-in reliability features:
|
|
594
|
+
|
|
595
|
+
- **Dual-endpoint auto-switching**: Daily sandbox and production endpoints; automatically switches on failure
|
|
596
|
+
- **Per-model-family rate tracking**: Separate rate limit tracking for Gemini and Claude model families
|
|
597
|
+
- **Exponential backoff retry**: Auto-retry on 429/503 errors; short intervals stay on the same endpoint, longer intervals switch endpoints
|
|
598
|
+
|
|
599
|
+
### Request Logging
|
|
600
|
+
|
|
601
|
+
Each API request outputs a log line with model name, status code, and duration:
|
|
602
|
+
|
|
603
|
+
```log
|
|
604
|
+
[claude-opus-4-6] 13:13:39 <-- POST /v1/messages?beta=true
|
|
605
|
+
[claude-opus-4-6] 13:13:59 --> POST /v1/messages?beta=true 200 20.1s
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
### Network Retry
|
|
609
|
+
|
|
610
|
+
Built-in retry for transient network errors (TLS disconnect, connection reset, etc.):
|
|
611
|
+
|
|
612
|
+
- Up to 2 retries (3 total attempts)
|
|
613
|
+
- Backoff intervals: 1s, 2s
|
|
614
|
+
- Only retries network-layer errors; HTTP error codes (e.g. 400/500) are not retried
|
|
615
|
+
|
|
616
|
+
---
|
|
617
|
+
|
|
618
|
+
## ⚙️ CLI Reference
|
|
619
|
+
|
|
620
|
+
### Commands
|
|
621
|
+
|
|
622
|
+
| Command | Description |
|
|
623
|
+
|---------|-------------|
|
|
624
|
+
| `start` | Start the API server |
|
|
625
|
+
| `auth` | Run GitHub authentication only |
|
|
626
|
+
| `logout` | Clear saved credentials |
|
|
627
|
+
| `proxy` | Configure proxy settings |
|
|
628
|
+
| `antigravity` | Manage Google Antigravity accounts |
|
|
629
|
+
| `check-usage` | View Copilot usage |
|
|
630
|
+
| `debug` | Show debug information |
|
|
631
|
+
|
|
632
|
+
### start Options
|
|
633
|
+
|
|
634
|
+
| Option | Alias | Default | Description |
|
|
635
|
+
|--------|-------|---------|-------------|
|
|
636
|
+
| `--port` | `-p` | 4141 | Listen port |
|
|
637
|
+
| `--verbose` | `-v` | false | Verbose logging |
|
|
638
|
+
| `--account-type` | `-a` | individual | Account type (individual/business/enterprise) |
|
|
639
|
+
| `--claude-code` | `-c` | false | Generate Claude Code launch command |
|
|
640
|
+
| `--zen` | `-z` | false | Enable OpenCode Zen mode |
|
|
641
|
+
| `--zen-api-key` | - | - | Zen API Key |
|
|
642
|
+
| `--antigravity` | - | false | Enable Google Antigravity mode |
|
|
643
|
+
| `--antigravity-client-id` | - | - | Antigravity OAuth Client ID |
|
|
644
|
+
| `--antigravity-client-secret` | - | - | Antigravity OAuth Client Secret |
|
|
645
|
+
| `--rate-limit` | `-r` | - | Request interval (seconds) |
|
|
646
|
+
| `--wait` | `-w` | false | Wait instead of error when rate limited |
|
|
647
|
+
| `--manual` | - | false | Manually approve each request |
|
|
648
|
+
| `--github-token` | `-g` | - | Provide GitHub Token directly |
|
|
649
|
+
| `--show-token` | - | false | Show token info |
|
|
650
|
+
| `--proxy-env` | - | false | Read proxy from environment variables |
|
|
651
|
+
| `--api-key` | - | - | API key auth (can be specified multiple times) |
|
|
652
|
+
|
|
653
|
+
### proxy Options
|
|
654
|
+
|
|
655
|
+
| Option | Description |
|
|
656
|
+
|--------|-------------|
|
|
657
|
+
| `--set` | Interactive proxy setup |
|
|
658
|
+
| `--enable` | Enable saved proxy |
|
|
659
|
+
| `--disable` | Disable proxy (keeps settings) |
|
|
660
|
+
| `--clear` | Clear proxy settings |
|
|
661
|
+
| `--show` | Show current settings |
|
|
662
|
+
| `--http-proxy` | HTTP proxy URL |
|
|
663
|
+
| `--https-proxy` | HTTPS proxy URL |
|
|
664
|
+
| `--no-proxy` | Hosts to bypass proxy |
|
|
665
|
+
|
|
666
|
+
### logout Options
|
|
667
|
+
|
|
668
|
+
| Option | Alias | Description |
|
|
669
|
+
|--------|-------|-------------|
|
|
670
|
+
| `--github` | `-g` | Clear GitHub Copilot credentials only |
|
|
671
|
+
| `--zen` | `-z` | Clear Zen credentials only |
|
|
672
|
+
| `--antigravity` | - | Clear Antigravity credentials only |
|
|
673
|
+
| `--all` | `-a` | Clear all credentials |
|
|
674
|
+
|
|
675
|
+
> **Tip**: Running `logout` without arguments shows an interactive menu.
|
|
676
|
+
|
|
677
|
+
### antigravity Subcommands
|
|
678
|
+
|
|
679
|
+
| Subcommand | Description |
|
|
680
|
+
|------------|-------------|
|
|
681
|
+
| `add` | Add a new Antigravity account (OAuth login) |
|
|
682
|
+
| `list` | List all configured accounts and their status |
|
|
683
|
+
| `remove <index>` | Remove account by index |
|
|
684
|
+
| `clear` | Clear all Antigravity accounts (requires confirmation) |
|
|
685
|
+
|
|
686
|
+
```bash
|
|
687
|
+
# Examples
|
|
688
|
+
npx copilot-api-plus@latest antigravity add # Add account
|
|
689
|
+
npx copilot-api-plus@latest antigravity list # List accounts
|
|
690
|
+
npx copilot-api-plus@latest antigravity remove 0 # Remove account at index 0
|
|
691
|
+
npx copilot-api-plus@latest antigravity clear # Clear all accounts
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
---
|
|
695
|
+
|
|
696
|
+
## 🐳 Docker Deployment
|
|
697
|
+
|
|
698
|
+
### Quick Start
|
|
699
|
+
|
|
700
|
+
```bash
|
|
701
|
+
# Using pre-built image
|
|
702
|
+
docker run -p 4141:4141 \
|
|
703
|
+
-v ./copilot-data:/root/.local/share/copilot-api-plus \
|
|
704
|
+
ghcr.io/imbuxiangnan-cyber/copilot-api-plus
|
|
705
|
+
```
|
|
706
|
+
|
|
707
|
+
### Build from Source
|
|
708
|
+
|
|
709
|
+
```bash
|
|
710
|
+
# Build image
|
|
711
|
+
docker build -t copilot-api-plus .
|
|
712
|
+
|
|
713
|
+
# Run container
|
|
714
|
+
docker run -p 4141:4141 \
|
|
715
|
+
-v ./copilot-data:/root/.local/share/copilot-api-plus \
|
|
716
|
+
copilot-api-plus
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
### Docker Compose
|
|
720
|
+
|
|
721
|
+
```yaml
|
|
722
|
+
version: "3.8"
|
|
723
|
+
services:
|
|
724
|
+
copilot-api-plus:
|
|
725
|
+
build: .
|
|
726
|
+
ports:
|
|
727
|
+
- "4141:4141"
|
|
728
|
+
volumes:
|
|
729
|
+
- ./copilot-data:/root/.local/share/copilot-api-plus
|
|
730
|
+
environment:
|
|
731
|
+
- GH_TOKEN=your_github_token # Optional
|
|
732
|
+
restart: unless-stopped
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
### Using a Proxy
|
|
736
|
+
|
|
737
|
+
```bash
|
|
738
|
+
docker run -p 4141:4141 \
|
|
739
|
+
-e HTTP_PROXY=http://host.docker.internal:7890 \
|
|
740
|
+
-e HTTPS_PROXY=http://host.docker.internal:7890 \
|
|
741
|
+
-v ./copilot-data:/root/.local/share/copilot-api-plus \
|
|
742
|
+
copilot-api-plus start --proxy-env
|
|
743
|
+
```
|
|
744
|
+
|
|
745
|
+
---
|
|
746
|
+
|
|
747
|
+
## ❓ FAQ
|
|
748
|
+
|
|
749
|
+
### Data Storage Location
|
|
750
|
+
|
|
751
|
+
All data is stored in `~/.local/share/copilot-api-plus/`:
|
|
752
|
+
|
|
753
|
+
| File | Description |
|
|
754
|
+
|------|-------------|
|
|
755
|
+
| `github_token` | GitHub Token |
|
|
756
|
+
| `zen-auth.json` | Zen API Key |
|
|
757
|
+
| `antigravity-accounts.json` | Antigravity accounts |
|
|
758
|
+
| `config.json` | Proxy and other settings |
|
|
759
|
+
|
|
760
|
+
### Switching Accounts
|
|
761
|
+
|
|
762
|
+
```bash
|
|
763
|
+
# Interactive credential selection
|
|
764
|
+
npx copilot-api-plus@latest logout
|
|
765
|
+
|
|
766
|
+
# Clear GitHub Copilot credentials only
|
|
767
|
+
npx copilot-api-plus@latest logout --github
|
|
768
|
+
# Or shorthand
|
|
769
|
+
npx copilot-api-plus@latest logout -g
|
|
770
|
+
|
|
771
|
+
# Clear Zen credentials
|
|
772
|
+
npx copilot-api-plus@latest logout --zen
|
|
773
|
+
|
|
774
|
+
# Clear Antigravity credentials
|
|
775
|
+
npx copilot-api-plus@latest logout --antigravity
|
|
776
|
+
|
|
777
|
+
# Clear all credentials
|
|
778
|
+
npx copilot-api-plus@latest logout --all
|
|
779
|
+
```
|
|
780
|
+
|
|
781
|
+
### View Usage
|
|
782
|
+
|
|
783
|
+
```bash
|
|
784
|
+
# CLI (Copilot only)
|
|
785
|
+
npx copilot-api-plus@latest check-usage
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
After starting the server, you can also access the web dashboard:
|
|
789
|
+
```
|
|
790
|
+
https://imbuxiangnan-cyber.github.io/copilot-api-plus?endpoint=http://localhost:4141/usage
|
|
791
|
+
```
|
|
792
|
+
|
|
793
|
+
### Debugging
|
|
794
|
+
|
|
795
|
+
```bash
|
|
796
|
+
# Show debug info
|
|
797
|
+
npx copilot-api-plus@latest debug
|
|
798
|
+
|
|
799
|
+
# JSON output
|
|
800
|
+
npx copilot-api-plus@latest debug --json
|
|
801
|
+
|
|
802
|
+
# Enable verbose logging
|
|
803
|
+
npx copilot-api-plus@latest start --verbose
|
|
804
|
+
```
|
|
805
|
+
|
|
806
|
+
### Rate Limiting
|
|
807
|
+
|
|
808
|
+
To avoid triggering GitHub's abuse detection:
|
|
809
|
+
|
|
810
|
+
```bash
|
|
811
|
+
# Set 30-second request interval
|
|
812
|
+
npx copilot-api-plus@latest start --rate-limit 30
|
|
813
|
+
|
|
814
|
+
# Wait instead of error when rate limited
|
|
815
|
+
npx copilot-api-plus@latest start --rate-limit 30 --wait
|
|
816
|
+
|
|
817
|
+
# Manually approve each request
|
|
818
|
+
npx copilot-api-plus@latest start --manual
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
---
|
|
822
|
+
|
|
823
|
+
## ⚠️ Disclaimer
|
|
824
|
+
|
|
825
|
+
> [!WARNING]
|
|
826
|
+
> This is a reverse-engineered proxy for the GitHub Copilot API. **Not officially supported by GitHub** and may stop working at any time. Use at your own risk.
|
|
827
|
+
|
|
828
|
+
> [!WARNING]
|
|
829
|
+
> **GitHub Safety Notice**: Excessive automated or scripted use of Copilot may trigger GitHub's abuse detection systems, resulting in Copilot access suspension. Please use responsibly.
|
|
830
|
+
>
|
|
831
|
+
> Related policies:
|
|
832
|
+
> - [GitHub Acceptable Use Policies](https://docs.github.com/site-policy/acceptable-use-policies/github-acceptable-use-policies)
|
|
833
|
+
> - [GitHub Copilot Terms](https://docs.github.com/site-policy/github-terms/github-terms-for-additional-products-and-features#github-copilot)
|
|
834
|
+
|
|
835
|
+
---
|
|
836
|
+
|
|
837
|
+
## 📄 License
|
|
838
|
+
|
|
839
|
+
MIT License
|