copilot-api-plus 1.0.9 → 1.0.10

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.md CHANGED
@@ -1,759 +1,656 @@
1
1
  # Copilot API Plus
2
2
 
3
-
4
-
5
3
  > **Fork of [ericc-ch/copilot-api](https://github.com/ericc-ch/copilot-api)** with bug fixes and improvements.
6
4
 
7
- > [!WARNING]
8
- > This is a reverse-engineered proxy of GitHub Copilot API. It is not supported by GitHub, and may break unexpectedly. Use at your own risk.
9
-
10
- > [!WARNING]
11
- > **GitHub Security Notice:**
12
- > Excessive automated or scripted use of Copilot (including rapid or bulk requests, such as via automated tools) may trigger GitHub's abuse-detection systems.
13
- > You may receive a warning from GitHub Security, and further anomalous activity could result in temporary suspension of your Copilot access.
14
- >
15
- > GitHub prohibits use of their servers for excessive automated bulk activity or any activity that places undue burden on their infrastructure.
16
- >
17
- > Please review:
18
- >
19
- > - [GitHub Acceptable Use Policies](https://docs.github.com/site-policy/acceptable-use-policies/github-acceptable-use-policies#4-spam-and-inauthentic-activity-on-github)
20
- > - [GitHub Copilot Terms](https://docs.github.com/site-policy/github-terms/github-terms-for-additional-products-and-features#github-copilot)
21
- >
22
- > Use this proxy responsibly to avoid account restrictions.
5
+ GitHub Copilot、OpenCode Zen、Google Antigravity 等 AI 服务转换为 **OpenAI** 和 **Anthropic** 兼容 API,支持与 [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview)、[opencode](https://github.com/sst/opencode) 等工具无缝集成。
23
6
 
24
7
  ---
25
8
 
26
- ## What's Different from Original?
27
-
28
- This fork includes the following bug fixes and improvements:
29
-
30
- - ✅ **Auto Re-authentication**: Automatically detects invalid/expired GitHub tokens and re-authenticates
31
- - **Logout Command**: New `logout` command to clear stored tokens and switch accounts
32
- - **Better Error Handling**: Token refresh failures no longer crash the server
33
- - **OAuth Timeout**: Device code polling now has proper timeout handling
34
- - ✅ **Token Validation**: Validates provided GitHub tokens before use
35
- - **API Key Auth**: API key authentication middleware is now properly enabled
9
+ ## 📋 目录
10
+
11
+ - [功能特点](#-功能特点)
12
+ - [快速开始](#-快速开始)
13
+ - [详细使用指南](#-详细使用指南)
14
+ - [GitHub Copilot 模式](#1-github-copilot-模式默认)
15
+ - [OpenCode Zen 模式](#2-opencode-zen-模式)
16
+ - [Google Antigravity 模式](#3-google-antigravity-模式)
17
+ - [代理配置](#-代理配置)
18
+ - [Claude Code 集成](#-claude-code-集成)
19
+ - [opencode 集成](#-opencode-集成)
20
+ - [API 端点](#-api-端点)
21
+ - [命令行参考](#-命令行参考)
22
+ - [Docker 部署](#-docker-部署)
23
+ - [常见问题](#-常见问题)
36
24
 
37
25
  ---
38
26
 
39
- ## Project Overview
40
-
41
- A reverse-engineered proxy for the GitHub Copilot API that exposes it as an OpenAI and Anthropic compatible service. This allows you to use GitHub Copilot with any tool that supports the OpenAI Chat Completions API or the Anthropic Messages API, including to power [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview).
27
+ ## 功能特点
42
28
 
43
- ## Features
29
+ | 功能 | 说明 |
30
+ |------|------|
31
+ | 🔌 **多后端支持** | GitHub Copilot、OpenCode Zen、Google Antigravity 三种后端可选 |
32
+ | 🤖 **双协议兼容** | 同时支持 OpenAI Chat Completions API 和 Anthropic Messages API |
33
+ | 💻 **Claude Code 集成** | 一键生成 Claude Code 启动命令 (`--claude-code`) |
34
+ | 📊 **使用量监控** | Web 仪表盘实时查看 API 使用情况 |
35
+ | 🔄 **自动认证** | Token 过期自动刷新,无需手动干预 |
36
+ | ⚡ **速率限制** | 内置请求频率控制,避免触发限制 |
37
+ | 🌐 **代理支持** | 支持 HTTP/HTTPS 代理,配置持久化 |
38
+ | 🐳 **Docker 支持** | 提供完整的 Docker 部署方案 |
44
39
 
45
- - **OpenAI & Anthropic Compatibility**: Exposes GitHub Copilot as an OpenAI-compatible (`/v1/chat/completions`, `/v1/models`, `/v1/embeddings`) and Anthropic-compatible (`/v1/messages`) API.
46
- - **Claude Code Integration**: Easily configure and launch [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview) to use Copilot as its backend with a simple command-line flag (`--claude-code`).
47
- - **Usage Dashboard**: A web-based dashboard to monitor your Copilot API usage, view quotas, and see detailed statistics.
48
- - **Rate Limit Control**: Manage API usage with rate-limiting options (`--rate-limit`) and a waiting mechanism (`--wait`) to prevent errors from rapid requests.
49
- - **Manual Request Approval**: Manually approve or deny each API request for fine-grained control over usage (`--manual`).
50
- - **Token Visibility**: Option to display GitHub and Copilot tokens during authentication and refresh for debugging (`--show-token`).
51
- - **Flexible Authentication**: Authenticate interactively or provide a GitHub token directly, suitable for CI/CD environments.
52
- - **Support for Different Account Types**: Works with individual, business, and enterprise GitHub Copilot plans.
53
-
54
- ## Prerequisites
40
+ ---
55
41
 
56
- - Bun (>= 1.2.x)
57
- - GitHub account with Copilot subscription (individual, business, or enterprise)
42
+ ## 🚀 快速开始
58
43
 
59
- ## Installation
44
+ ### 安装
60
45
 
61
- To install dependencies, run:
46
+ ```bash
47
+ # 全局安装
48
+ npm install -g copilot-api-plus
62
49
 
63
- ```sh
64
- bun install
50
+ # 或使用 npx 直接运行(推荐)
51
+ npx copilot-api-plus@latest start
65
52
  ```
66
53
 
67
- ## Using with Docker
54
+ ### 基本用法
68
55
 
69
- Build image
70
-
71
- ```sh
72
- docker build -t copilot-api-plus .
73
- ```
74
-
75
- Run the container
56
+ ```bash
57
+ # 启动服务器(默认使用 GitHub Copilot)
58
+ npx copilot-api-plus@latest start
76
59
 
77
- ```sh
78
- # Create a directory on your host to persist the GitHub token and related data
79
- mkdir -p ./copilot-data
60
+ # 使用 OpenCode Zen
61
+ npx copilot-api-plus@latest start --zen
80
62
 
81
- # Run the container with a bind mount to persist the token
82
- # This ensures your authentication survives container restarts
63
+ # 使用 Google Antigravity
64
+ npx copilot-api-plus@latest start --antigravity
83
65
 
84
- docker run -p 4141:4141 -v $(pwd)/copilot-data:/root/.local/share/copilot-api-plus copilot-api-plus
66
+ # Claude Code 配合
67
+ npx copilot-api-plus@latest start --claude-code
85
68
  ```
86
69
 
87
- > **Note:**
88
- > The GitHub token and related data will be stored in `copilot-data` on your host. This is mapped to `/root/.local/share/copilot-api-plus` inside the container, ensuring persistence across restarts.
70
+ 服务器启动后,默认监听 `http://localhost:4141`。
89
71
 
90
- ### Docker with Environment Variables
72
+ ---
91
73
 
92
- You can pass the GitHub token directly to the container using environment variables:
74
+ ## 📖 详细使用指南
93
75
 
94
- ```sh
95
- # Build with GitHub token
96
- docker build --build-arg GH_TOKEN=your_github_token_here -t copilot-api-plus .
76
+ ### 1. GitHub Copilot 模式(默认)
97
77
 
98
- # Run with GitHub token
99
- docker run -p 4141:4141 -e GH_TOKEN=your_github_token_here copilot-api-plus
78
+ 使用你的 GitHub Copilot 订阅访问 AI 模型。
100
79
 
101
- # Run with additional options
102
- docker run -p 4141:4141 -e GH_TOKEN=your_token copilot-api-plus start --verbose --port 4141
103
- ```
80
+ #### 前置要求
81
+ - GitHub 账户
82
+ - 有效的 Copilot 订阅(Individual / Business / Enterprise)
104
83
 
105
- ### Docker Compose Example
84
+ #### 启动步骤
106
85
 
107
- ```yaml
108
- version: "3.8"
109
- services:
110
- copilot-api-plus:
111
- build: .
112
- ports:
113
- - "4141:4141"
114
- environment:
115
- - GH_TOKEN=your_github_token_here
116
- restart: unless-stopped
86
+ ```bash
87
+ npx copilot-api-plus@latest start
117
88
  ```
118
89
 
119
- The Docker image includes:
90
+ **首次运行**会引导你完成 GitHub OAuth 认证:
120
91
 
121
- - Multi-stage build for optimized image size
122
- - Non-root user for enhanced security
123
- - Health check for container monitoring
124
- - Pinned base image version for reproducible builds
92
+ 1. 终端显示设备码,例如:`XXXX-XXXX`
93
+ 2. 打开浏览器访问:https://github.com/login/device
94
+ 3. 输入设备码,点击授权
95
+ 4. 返回终端,等待认证完成
125
96
 
126
- ## Using with npx
97
+ 认证成功后,Token 会保存到本地,下次启动无需重新认证。
127
98
 
128
- You can run the project directly using npx:
99
+ #### 企业/商业账户
129
100
 
130
- ```sh
131
- npx copilot-api-plus@latest start
132
- ```
133
-
134
- With options:
101
+ ```bash
102
+ # Business 计划
103
+ npx copilot-api-plus@latest start --account-type business
135
104
 
136
- ```sh
137
- npx copilot-api-plus@latest start --port 8080
105
+ # Enterprise 计划
106
+ npx copilot-api-plus@latest start --account-type enterprise
138
107
  ```
139
108
 
140
- For authentication only:
109
+ #### 可用模型
141
110
 
142
- ```sh
143
- npx copilot-api-plus@latest auth
144
- ```
111
+ | 模型 | ID | 上下文长度 |
112
+ |------|-----|-----------|
113
+ | Claude Sonnet 4 | `claude-sonnet-4` | 200K |
114
+ | Claude Sonnet 4.5 | `claude-sonnet-4.5` | 200K |
115
+ | GPT-4.1 | `gpt-4.1` | 1M |
116
+ | o4-mini | `o4-mini` | 200K |
117
+ | Gemini 2.5 Pro | `gemini-2.5-pro` | 1M |
145
118
 
146
- ## Command Structure
119
+ ---
147
120
 
148
- Copilot API Plus uses a subcommand structure with these main commands:
121
+ ### 2. OpenCode Zen 模式
149
122
 
150
- - `start`: Start the Copilot API server. This command will also handle authentication if needed.
151
- - `auth`: Run GitHub authentication flow without starting the server. This is typically used if you need to generate a token for use with the `--github-token` option, especially in non-interactive environments.
152
- - `check-usage`: Show your current GitHub Copilot usage and quota information directly in the terminal (no server required).
153
- - `debug`: Display diagnostic information including version, runtime details, file paths, and authentication status. Useful for troubleshooting and support.
154
- - `logout`: Clear stored GitHub token and logout. Use this to switch accounts or re-authenticate.
123
+ 使用 [OpenCode Zen](https://opencode.ai/zen) 的多模型 API 服务。
155
124
 
156
- ## Command Line Options
125
+ #### 前置要求
126
+ 1. 访问 https://opencode.ai/zen
127
+ 2. 注册账号并创建 API Key
157
128
 
158
- ### Start Command Options
129
+ #### 启动步骤
159
130
 
160
- The following command line options are available for the `start` command:
131
+ **方式一:交互式设置**
132
+ ```bash
133
+ npx copilot-api-plus@latest start --zen
134
+ ```
135
+ 首次运行会提示输入 API Key,保存后下次自动使用。
161
136
 
162
- | Option | Description | Default | Alias |
163
- | -------------- | ----------------------------------------------------------------------------- | ---------- | ----- |
164
- | --port | Port to listen on | 4141 | -p |
165
- | --verbose | Enable verbose logging | false | -v |
166
- | --account-type | Account type to use (individual, business, enterprise) | individual | -a |
167
- | --manual | Enable manual request approval | false | none |
168
- | --rate-limit | Rate limit in seconds between requests | none | -r |
169
- | --wait | Wait instead of error when rate limit is hit | false | -w |
170
- | --github-token | Provide GitHub token directly (must be generated using the `auth` subcommand) | none | -g |
171
- | --claude-code | Generate a command to launch Claude Code with Copilot API config | false | -c |
172
- | --show-token | Show GitHub and Copilot tokens on fetch and refresh | false | none |
173
- | --proxy-env | Initialize proxy from environment variables | false | none |
174
- | --zen | Enable OpenCode Zen mode (proxy to Zen instead of GitHub Copilot) | false | -z |
175
- | --zen-api-key | OpenCode Zen API key (get from https://opencode.ai/zen) | none | none |
176
- | --antigravity | Enable Google Antigravity mode (proxy to Antigravity) | false | none |
137
+ **方式二:直接指定 API Key**
138
+ ```bash
139
+ npx copilot-api-plus@latest start --zen --zen-api-key YOUR_API_KEY
140
+ ```
177
141
 
178
- ### Auth Command Options
142
+ #### 可用模型
179
143
 
180
- | Option | Description | Default | Alias |
181
- | ------------ | ------------------------- | ------- | ----- |
182
- | --verbose | Enable verbose logging | false | -v |
183
- | --show-token | Show GitHub token on auth | false | none |
144
+ | 模型 | ID | 说明 |
145
+ |------|-----|------|
146
+ | Claude Sonnet 4.5 | `claude-sonnet-4-5` | Anthropic Claude (200K) |
147
+ | Claude Opus 4.5 | `claude-opus-4-5` | Anthropic Claude (200K) |
148
+ | GPT-5 Codex | `gpt-5-codex` | OpenAI Responses API |
149
+ | Gemini 3 Pro | `gemini-3-pro` | Google Gemini |
150
+ | Qwen3 Coder 480B | `qwen3-coder` | Alibaba Qwen |
151
+ | Kimi K2 | `kimi-k2` | Moonshot |
152
+ | Grok Code Fast 1 | `grok-code` | xAI |
184
153
 
185
- ### Debug Command Options
154
+ 更多模型请访问 [opencode.ai/zen](https://opencode.ai/zen)
186
155
 
187
- | Option | Description | Default | Alias |
188
- | ------ | ------------------------- | ------- | ----- |
189
- | --json | Output debug info as JSON | false | none |
156
+ #### 管理 API Key
190
157
 
191
- ## Proxy Configuration
158
+ ```bash
159
+ # 查看/更换 API Key(清除后重新启动会提示输入)
160
+ npx copilot-api-plus@latest logout --zen
161
+ ```
192
162
 
193
- If you are behind a corporate firewall or need to route traffic through a proxy server, you can configure the proxy using environment variables.
163
+ ---
194
164
 
195
- ### Using the `--proxy-env` Flag
165
+ ### 3. Google Antigravity 模式
196
166
 
197
- Start the server with the `--proxy-env` flag to automatically read proxy settings from environment variables:
167
+ 使用 Google Antigravity API 服务,支持 Gemini Claude 模型。
198
168
 
199
- ```sh
200
- # Set proxy environment variables first
201
- export HTTP_PROXY=http://your-proxy-server:8080
202
- export HTTPS_PROXY=http://your-proxy-server:8080
169
+ #### 前置要求
170
+ - Google 账户
203
171
 
204
- # Start with proxy support
205
- npx copilot-api-plus@latest start --proxy-env
172
+ #### 启动步骤
173
+
174
+ ```bash
175
+ npx copilot-api-plus@latest start --antigravity
206
176
  ```
207
177
 
208
- On Windows (PowerShell):
178
+ **首次运行**会引导你完成 Google OAuth 认证:
209
179
 
210
- ```powershell
211
- $env:HTTP_PROXY = "http://your-proxy-server:8080"
212
- $env:HTTPS_PROXY = "http://your-proxy-server:8080"
213
- npx copilot-api-plus@latest start --proxy-env
214
- ```
180
+ 1. 终端显示 Google 授权 URL
181
+ 2. 在浏览器中打开该 URL
182
+ 3. 使用 Google 账号登录并授权
183
+ 4. 授权成功后,浏览器会跳转到一个 `localhost:8046/callback?code=...` 的页面
184
+ 5. **复制浏览器地址栏中的完整 URL**
185
+ 6. 粘贴到终端,按回车完成认证
215
186
 
216
- On Windows (CMD):
187
+ #### 可用模型
217
188
 
218
- ```cmd
219
- set HTTP_PROXY=http://your-proxy-server:8080
220
- set HTTPS_PROXY=http://your-proxy-server:8080
221
- npx copilot-api-plus@latest start --proxy-env
222
- ```
189
+ | 模型 | ID | 说明 |
190
+ |------|-----|------|
191
+ | Gemini 2.5 Pro | `gemini-2.5-pro-exp-03-25` | Google Gemini |
192
+ | Gemini 2.5 Pro Preview | `gemini-2.5-pro-preview-05-06` | Google Gemini |
193
+ | Gemini 2.0 Flash | `gemini-2.0-flash-exp` | 快速响应 |
194
+ | Gemini 2.0 Flash Thinking | `gemini-2.0-flash-thinking-exp` | 支持思考链 |
195
+ | Claude Opus 4.5 | `claude-opus-4-5` | Anthropic Claude |
196
+ | Claude Sonnet 4.5 | `claude-sonnet-4-5` | Anthropic Claude |
223
197
 
224
- ### Supported Proxy Environment Variables
198
+ #### 特性
199
+ - ✅ 自动 Token 刷新
200
+ - ✅ 多账户支持,自动轮换
201
+ - ✅ 配额用尽自动切换账户
202
+ - ✅ 支持 Thinking 模型(思考链输出)
225
203
 
226
- | Variable | Description |
227
- | ------------- | ----------------------------------------- |
228
- | `HTTP_PROXY` | Proxy URL for HTTP connections |
229
- | `HTTPS_PROXY` | Proxy URL for HTTPS connections |
230
- | `http_proxy` | Alternative (lowercase) for HTTP proxy |
231
- | `https_proxy` | Alternative (lowercase) for HTTPS proxy |
232
- | `NO_PROXY` | Comma-separated list of hosts to bypass |
233
- | `no_proxy` | Alternative (lowercase) for no-proxy list |
204
+ #### 多账户管理
234
205
 
235
- ### Proxy Authentication
206
+ 可以添加多个 Google 账户,系统会在配额用尽时自动切换:
236
207
 
237
- If your proxy requires authentication, include the credentials in the URL:
208
+ ```bash
209
+ # 添加新账户:重新运行启动命令,选择添加账户
210
+ npx copilot-api-plus@latest start --antigravity
238
211
 
239
- ```sh
240
- export HTTPS_PROXY=http://username:password@your-proxy-server:8080
212
+ # 清除所有账户
213
+ npx copilot-api-plus@latest logout --antigravity
241
214
  ```
242
215
 
243
- ### Docker with Proxy
216
+ ---
244
217
 
245
- When running in Docker, pass the proxy environment variables:
218
+ ## 🌐 代理配置
246
219
 
247
- ```sh
248
- docker run -p 4141:4141 \
249
- -e HTTP_PROXY=http://your-proxy:8080 \
250
- -e HTTPS_PROXY=http://your-proxy:8080 \
251
- copilot-api-plus start --proxy-env
252
- ```
253
-
254
- ## API Endpoints
220
+ 如果你需要通过代理访问网络,有两种配置方式:
255
221
 
256
- The server exposes several endpoints to interact with the Copilot API. It provides OpenAI-compatible endpoints and now also includes support for Anthropic-compatible endpoints, allowing for greater flexibility with different tools and services.
222
+ ### 方式一:持久化配置(推荐)
257
223
 
258
- ### OpenAI Compatible Endpoints
224
+ 配置一次,永久生效,下次启动自动使用。
259
225
 
260
- These endpoints mimic the OpenAI API structure.
226
+ ```bash
227
+ # 交互式配置
228
+ npx copilot-api-plus@latest proxy --set
261
229
 
262
- | Endpoint | Method | Description |
263
- | --------------------------- | ------ | --------------------------------------------------------- |
264
- | `POST /v1/chat/completions` | `POST` | Creates a model response for the given chat conversation. |
265
- | `GET /v1/models` | `GET` | Lists the currently available models. |
266
- | `POST /v1/embeddings` | `POST` | Creates an embedding vector representing the input text. |
230
+ # 或直接设置
231
+ npx copilot-api-plus@latest proxy --http-proxy http://127.0.0.1:7890
267
232
 
268
- ### Anthropic Compatible Endpoints
233
+ # 同时设置 HTTP 和 HTTPS 代理
234
+ npx copilot-api-plus@latest proxy --http-proxy http://127.0.0.1:7890 --https-proxy http://127.0.0.1:7890
235
+ ```
269
236
 
270
- These endpoints are designed to be compatible with the Anthropic Messages API.
237
+ #### 代理管理命令
271
238
 
272
- | Endpoint | Method | Description |
273
- | -------------------------------- | ------ | ------------------------------------------------------------ |
274
- | `POST /v1/messages` | `POST` | Creates a model response for a given conversation. |
275
- | `POST /v1/messages/count_tokens` | `POST` | Calculates the number of tokens for a given set of messages. |
239
+ ```bash
240
+ # 查看当前代理配置
241
+ npx copilot-api-plus@latest proxy
276
242
 
277
- ### Usage Monitoring Endpoints
243
+ # 启用代理
244
+ npx copilot-api-plus@latest proxy --enable
278
245
 
279
- New endpoints for monitoring your Copilot usage and quotas.
246
+ # 禁用代理(保留设置)
247
+ npx copilot-api-plus@latest proxy --disable
280
248
 
281
- | Endpoint | Method | Description |
282
- | ------------ | ------ | ------------------------------------------------------------ |
283
- | `GET /usage` | `GET` | Get detailed Copilot usage statistics and quota information. |
284
- | `GET /token` | `GET` | Get the current Copilot token being used by the API. |
249
+ # 清除代理配置
250
+ npx copilot-api-plus@latest proxy --clear
251
+ ```
285
252
 
286
- ## Example Usage
253
+ #### 示例:配置 Clash 代理
287
254
 
288
- Using with npx:
255
+ ```bash
256
+ # Clash 默认端口 7890
257
+ npx copilot-api-plus@latest proxy --http-proxy http://127.0.0.1:7890
289
258
 
290
- ```sh
291
- # Basic usage with start command
292
- npx copilot-api-plus@latest start
259
+ # 验证配置
260
+ npx copilot-api-plus@latest proxy
261
+ # 输出:
262
+ # Current proxy configuration:
263
+ # Status: ✅ Enabled
264
+ # HTTP_PROXY: http://127.0.0.1:7890
265
+ # HTTPS_PROXY: http://127.0.0.1:7890
266
+ ```
293
267
 
294
- # Run on custom port with verbose logging
295
- npx copilot-api-plus@latest start --port 8080 --verbose
268
+ ### 方式二:环境变量(临时)
296
269
 
297
- # Use with a business plan GitHub account
298
- npx copilot-api-plus@latest start --account-type business
270
+ 仅当次启动生效:
299
271
 
300
- # Use with an enterprise plan GitHub account
301
- npx copilot-api-plus@latest start --account-type enterprise
272
+ ```bash
273
+ # Linux/macOS
274
+ export HTTP_PROXY=http://127.0.0.1:7890
275
+ export HTTPS_PROXY=http://127.0.0.1:7890
276
+ npx copilot-api-plus@latest start --proxy-env
302
277
 
303
- # Enable manual approval for each request
304
- npx copilot-api-plus@latest start --manual
278
+ # Windows PowerShell
279
+ $env:HTTP_PROXY = "http://127.0.0.1:7890"
280
+ $env:HTTPS_PROXY = "http://127.0.0.1:7890"
281
+ npx copilot-api-plus@latest start --proxy-env
305
282
 
306
- # Set rate limit to 30 seconds between requests
307
- npx copilot-api-plus@latest start --rate-limit 30
283
+ # Windows CMD
284
+ set HTTP_PROXY=http://127.0.0.1:7890
285
+ set HTTPS_PROXY=http://127.0.0.1:7890
286
+ npx copilot-api-plus@latest start --proxy-env
287
+ ```
308
288
 
309
- # Wait instead of error when rate limit is hit
310
- npx copilot-api-plus@latest start --rate-limit 30 --wait
289
+ ### 代理配置优先级
311
290
 
312
- # Provide GitHub token directly
313
- npx copilot-api-plus@latest start --github-token ghp_YOUR_TOKEN_HERE
291
+ 1. `--proxy-env` 参数(从环境变量读取)
292
+ 2. 持久化配置(`proxy --set` 设置的)
293
+ 3. 无代理
314
294
 
315
- # Run only the auth flow
316
- npx copilot-api-plus@latest auth
295
+ ---
317
296
 
318
- # Run auth flow with verbose logging
319
- npx copilot-api-plus@latest auth --verbose
297
+ ## 💻 Claude Code 集成
320
298
 
321
- # Show your Copilot usage/quota in the terminal (no server needed)
322
- npx copilot-api-plus@latest check-usage
299
+ [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview) Anthropic AI 编程助手。
323
300
 
324
- # Display debug information for troubleshooting
325
- npx copilot-api-plus@latest debug
301
+ ### 自动配置(推荐)
326
302
 
327
- # Display debug information in JSON format
328
- npx copilot-api-plus@latest debug --json
303
+ ```bash
304
+ # 使用 GitHub Copilot 作为后端
305
+ npx copilot-api-plus@latest start --claude-code
329
306
 
330
- # Logout and clear stored tokens (to switch accounts)
331
- npx copilot-api-plus@latest logout
307
+ # 使用 OpenCode Zen 作为后端
308
+ npx copilot-api-plus@latest start --zen --claude-code
332
309
 
333
- # Initialize proxy from environment variables (HTTP_PROXY, HTTPS_PROXY, etc.)
334
- npx copilot-api-plus@latest start --proxy-env
310
+ # 使用 Google Antigravity 作为后端
311
+ npx copilot-api-plus@latest start --antigravity --claude-code
335
312
  ```
336
313
 
337
- ## Using the Usage Viewer
314
+ 运行后:
315
+ 1. 选择主模型(用于代码生成)
316
+ 2. 选择快速模型(用于后台任务)
317
+ 3. 启动命令会自动复制到剪贴板
318
+ 4. **打开新终端**,粘贴并运行命令启动 Claude Code
338
319
 
339
- After starting the server, a URL to the Copilot Usage Dashboard will be displayed in your console. This dashboard is a web interface for monitoring your API usage.
320
+ ### 手动配置
340
321
 
341
- 1. Start the server. For example, using npx:
342
- ```sh
343
- npx copilot-api-plus@latest start
344
- ```
345
- 2. The server will output a URL to the usage viewer. Copy and paste this URL into your browser. It will look something like this:
346
- `https://imbuxiangnan-cyber.github.io/copilot-api-plus?endpoint=http://localhost:4141/usage`
347
- - If you use the `start.bat` script on Windows, this page will open automatically.
322
+ 在项目根目录创建 `.claude/settings.json`:
348
323
 
349
- The dashboard provides a user-friendly interface to view your Copilot usage data:
324
+ ```json
325
+ {
326
+ "env": {
327
+ "ANTHROPIC_BASE_URL": "http://localhost:4141",
328
+ "ANTHROPIC_AUTH_TOKEN": "dummy",
329
+ "ANTHROPIC_MODEL": "claude-sonnet-4",
330
+ "ANTHROPIC_SMALL_FAST_MODEL": "gpt-4.1",
331
+ "DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1"
332
+ }
333
+ }
334
+ ```
350
335
 
351
- - **API Endpoint URL**: The dashboard is pre-configured to fetch data from your local server endpoint via the URL query parameter. You can change this URL to point to any other compatible API endpoint.
352
- - **Fetch Data**: Click the "Fetch" button to load or refresh the usage data. The dashboard will automatically fetch data on load.
353
- - **Usage Quotas**: View a summary of your usage quotas for different services like Chat and Completions, displayed with progress bars for a quick overview.
354
- - **Detailed Information**: See the full JSON response from the API for a detailed breakdown of all available usage statistics.
355
- - **URL-based Configuration**: You can also specify the API endpoint directly in the URL using a query parameter. This is useful for bookmarks or sharing links. For example:
356
- `https://imbuxiangnan-cyber.github.io/copilot-api-plus?endpoint=http://your-api-server/usage`
336
+ 然后启动 copilot-api-plus 服务器后,在该项目目录运行 `claude` 命令。
357
337
 
358
- ## Using with OpenCode Zen
338
+ ---
359
339
 
340
+ ## 🔧 opencode 集成
360
341
 
361
- ### OpenCode Zen 使用指南
342
+ [opencode](https://github.com/sst/opencode) 是一个现代 AI 编程助手。
362
343
 
363
- OpenCode Zen 是由 opencode.ai 提供的多模型 API 服务,支持 Claude、GPT-5、Gemini、Qwen 等主流大模型,适合代码生成、AI 助手等场景。Copilot API Plus 支持将 Zen 转换为 OpenAI/Anthropic 兼容 API,方便与 Claude Code、opencode 等工具无缝集成。
344
+ ### 配置步骤
364
345
 
365
- #### 1. 获取 Zen API Key
366
- 1. 访问 [https://opencode.ai/zen](https://opencode.ai/zen)
367
- 2. 注册并登录,进入“API Keys”页面,创建你的 API Key
346
+ 1. 在项目根目录创建 `opencode.json`:
368
347
 
369
- #### 2. 启动 Zen 模式
370
- 首次运行会自动提示输入 API Key,并保存到本地。也可直接指定:
371
- ```sh
372
- npx copilot-api-plus@latest start --zen --zen-api-key <你的APIKey>
373
- ```
374
- 或交互式:
375
- ```sh
376
- npx copilot-api-plus@latest start --zen
348
+ ```json
349
+ {
350
+ "$schema": "https://opencode.ai/config.json",
351
+ "provider": {
352
+ "copilot-api-plus": {
353
+ "api": "openai-compatible",
354
+ "name": "Copilot API Plus",
355
+ "options": {
356
+ "baseURL": "http://127.0.0.1:4141/v1"
357
+ },
358
+ "models": {
359
+ "claude-sonnet-4": {
360
+ "name": "Claude Sonnet 4",
361
+ "id": "claude-sonnet-4",
362
+ "max_tokens": 64000,
363
+ "profile": "coder",
364
+ "limit": { "context": 200000 }
365
+ },
366
+ "gpt-4.1": {
367
+ "name": "GPT-4.1",
368
+ "id": "gpt-4.1",
369
+ "max_tokens": 32768,
370
+ "profile": "coder",
371
+ "limit": { "context": 1047576 }
372
+ }
373
+ }
374
+ }
375
+ }
376
+ }
377
377
  ```
378
378
 
379
- #### 3. Claude Code 配合
380
- Zen 支持多种 Claude 模型,推荐用法:
381
- ```sh
382
- npx copilot-api-plus@latest start --zen --claude-code
383
- ```
384
- 会自动生成 Claude Code 启动命令,支持模型选择。
385
-
386
- #### 4. 支持的模型(部分示例)
387
- | 名称 | ID | 说明 |
388
- |---------------------|----------------------|---------------------------|
389
- | Claude Sonnet 4.5 | claude-sonnet-4-5 | Anthropic Claude 200K |
390
- | Claude Opus 4.5 | claude-opus-4-5 | Anthropic Claude 200K |
391
- | GPT-5 Codex | gpt-5-codex | OpenAI Responses API |
392
- | Gemini 3 Pro | gemini-3-pro | Google Gemini |
393
- | Qwen3 Coder 480B | qwen3-coder | Alibaba Qwen |
394
- | Kimi K2 | kimi-k2 | Moonshot |
395
- | Grok Code Fast 1 | grok-code | xAI |
396
- 更多模型请见 [Zen 官网](https://opencode.ai/zen)。
397
-
398
- #### 5. API 路径
399
- Zen 模式下,所有 OpenAI/Anthropic 兼容路径均可用:
400
- - `POST /v1/chat/completions` (OpenAI 格式)
401
- - `POST /v1/messages` (Anthropic 格式)
402
- - `GET /v1/models` (模型列表)
403
- Zen 专属路径(始终可用):
404
- - `POST /zen/v1/chat/completions`
405
- - `POST /zen/v1/messages`
406
- - `GET /zen/v1/models`
407
-
408
- #### 6. 常见问题
409
- - **API Key 存储位置**:`~/.local/share/copilot-api-plus/zen-auth.json`
410
- - **切换/清除 API Key**:
411
- - 只清除 Zen:`npx copilot-api-plus@latest logout --zen`
412
- - 全部清除:`npx copilot-api-plus@latest logout --all`
413
- - **模型选择**:启动时会自动显示可用模型列表
414
- - **与 opencode 配合**:在 `opencode.json` 里设置 `baseURL` 为 `http://127.0.0.1:4141/v1`,或用环境变量 `OPENAI_BASE_URL`
415
-
416
- #### 7. 使用技巧
417
- - 推荐用 `--claude-code` 生成 Claude Code 启动命令
418
- - 支持所有 Zen 公开模型,按需选择
419
- - 支持 Docker 部署,API Key 持久化
420
-
421
- 如需详细配置示例、opencode 配置、更多高级用法,请继续阅读下方文档。
422
-
423
- ### Why Use Zen Mode?
424
-
425
- - **Access to many models**: Claude Sonnet 4.5, Claude Opus 4.5, GPT-5 Codex, Gemini 3 Pro, Qwen3 Coder, and more
426
- - **Transparent pricing**: Pay per request with zero markups
427
- - **Tested & verified**: All models are tested by the OpenCode team for coding tasks
428
- - **Single API key**: One key for all Zen models
429
-
430
- ### Getting Started with Zen
431
-
432
- 1. **Get your API key**: Go to [opencode.ai/zen](https://opencode.ai/zen), sign up, and create an API key.
433
-
434
- 2. **Start the server in Zen mode**:
435
- ```sh
436
- npx copilot-api-plus@latest start --zen
437
- ```
438
-
439
- You will be prompted to enter your Zen API key on first run. The key will be saved for future use.
440
-
441
- 3. **Or provide the API key directly**:
442
- ```sh
443
- npx copilot-api-plus@latest start --zen --zen-api-key your_api_key_here
444
- ```
445
-
446
- ### Using Zen with Claude Code
447
-
448
- Start the server with both `--zen` and `--claude-code` flags:
449
-
450
- ```sh
451
- npx copilot-api-plus@latest start --zen --claude-code
379
+ 2. 启动 copilot-api-plus:
380
+ ```bash
381
+ npx copilot-api-plus@latest start
452
382
  ```
453
383
 
454
- This will:
455
- 1. Connect to OpenCode Zen instead of GitHub Copilot
456
- 2. Show you available Zen models to choose from
457
- 3. Generate a command to launch Claude Code with the selected model
458
-
459
- ### Available Zen Models
460
-
461
- When using Zen mode, you can access models like:
462
-
463
- | Model | ID | Description |
464
- | ------------------ | ----------------- | ------------------------------ |
465
- | Claude Sonnet 4.5 | claude-sonnet-4-5 | Anthropic Claude (200K context)|
466
- | Claude Opus 4.5 | claude-opus-4-5 | Anthropic Claude (200K context)|
467
- | GPT 5 Codex | gpt-5-codex | OpenAI (Responses API) |
468
- | Gemini 3 Pro | gemini-3-pro | Google Gemini |
469
- | Qwen3 Coder 480B | qwen3-coder | Alibaba Qwen |
470
- | Kimi K2 | kimi-k2 | Moonshot |
471
- | Grok Code Fast 1 | grok-code | xAI |
384
+ 3. 在同一目录运行 opencode:
385
+ ```bash
386
+ npx opencode@latest
387
+ ```
472
388
 
473
- For the full list, visit [opencode.ai/zen](https://opencode.ai/zen).
389
+ 4. 选择 `copilot-api-plus` 作为 provider
474
390
 
475
- ### Zen API Endpoints
391
+ ### 快捷方式:使用环境变量
476
392
 
477
- The server exposes the same endpoints in Zen mode:
393
+ ```bash
394
+ # 设置环境变量
395
+ export OPENAI_BASE_URL=http://127.0.0.1:4141/v1
396
+ export OPENAI_API_KEY=dummy
478
397
 
479
- | Endpoint | Description |
480
- | --------------------------- | ------------------------------------ |
481
- | `POST /v1/chat/completions` | OpenAI-compatible chat completions |
482
- | `POST /v1/messages` | Anthropic-compatible messages |
483
- | `GET /v1/models` | List available Zen models |
398
+ # 运行 opencode
399
+ npx opencode@latest
400
+ ```
484
401
 
485
- You can also access dedicated Zen routes (always available):
402
+ ---
486
403
 
487
- | Endpoint | Description |
488
- | -------------------------------- | ------------------------ |
489
- | `POST /zen/v1/chat/completions` | Zen chat completions |
490
- | `POST /zen/v1/messages` | Zen messages |
491
- | `GET /zen/v1/models` | Zen models |
404
+ ## 📡 API 端点
492
405
 
493
- ## Using with Google Antigravity
406
+ 服务器启动后,默认监听 `http://localhost:4141`。
494
407
 
495
- ### Google Antigravity 使用指南
408
+ ### OpenAI 兼容端点
496
409
 
497
- Google Antigravity Google 内部的 AI API 服务,支持 Gemini、Claude 等模型。Copilot API Plus 支持将 Antigravity 转换为 OpenAI 兼容 API。
410
+ | 端点 | 方法 | 说明 |
411
+ |------|------|------|
412
+ | `/v1/chat/completions` | POST | 聊天补全(支持流式) |
413
+ | `/v1/models` | GET | 模型列表 |
414
+ | `/v1/embeddings` | POST | 文本嵌入(仅 Copilot) |
498
415
 
499
- > **注意**:Antigravity 需要 Google 账户授权,基于 OAuth 认证。
416
+ ### Anthropic 兼容端点
500
417
 
501
- #### 1. 启动 Antigravity 模式
418
+ | 端点 | 方法 | 说明 |
419
+ |------|------|------|
420
+ | `/v1/messages` | POST | 消息 API(支持流式) |
421
+ | `/v1/messages/count_tokens` | POST | Token 计数 |
502
422
 
503
- 首次运行会引导你完成 Google OAuth 认证:
423
+ ### 专用端点
504
424
 
505
- ```sh
506
- npx copilot-api-plus@latest start --antigravity
507
- ```
425
+ 各后端都有独立的专用路由,即使切换默认后端也能访问:
508
426
 
509
- 按照提示:
510
- 1. 打开生成的 Google 授权 URL
511
- 2. 完成 Google 登录
512
- 3. 复制回调 URL 粘贴到终端
427
+ | 路由前缀 | 说明 |
428
+ |----------|------|
429
+ | `/copilot/v1/*` | GitHub Copilot 专用 |
430
+ | `/zen/v1/*` | OpenCode Zen 专用 |
431
+ | `/antigravity/v1/*` | Google Antigravity 专用 |
513
432
 
514
- #### 2. 支持的模型
433
+ ### 监控端点
515
434
 
516
- | 模型 | ID | 说明 |
517
- | --------------------------------- | ------------------------------------- | --------------- |
518
- | Gemini 2.5 Pro | gemini-2.5-pro-exp-03-25 | Google Gemini |
519
- | Gemini 2.5 Pro Preview | gemini-2.5-pro-preview-05-06 | Google Gemini |
520
- | Gemini 2.0 Flash | gemini-2.0-flash-exp | Google Gemini |
521
- | Gemini 2.0 Flash Thinking | gemini-2.0-flash-thinking-exp | 支持思考链 |
522
- | Gemini 2.0 Pro | gemini-2.0-pro-exp-02-05 | Google Gemini |
523
- | Claude Opus 4.5 | claude-opus-4-5 | Anthropic Claude|
524
- | Claude Sonnet 4.5 | claude-sonnet-4-5 | Anthropic Claude|
435
+ | 端点 | 方法 | 说明 |
436
+ |------|------|------|
437
+ | `/usage` | GET | 使用量统计(仅 Copilot) |
438
+ | `/token` | GET | 当前 Token 信息 |
525
439
 
526
- 启动时会自动显示可用模型列表。
440
+ ### 调用示例
527
441
 
528
- #### 3. 与 Claude Code 配合
442
+ ```bash
443
+ # OpenAI 格式
444
+ curl http://localhost:4141/v1/chat/completions \
445
+ -H "Content-Type: application/json" \
446
+ -d '{
447
+ "model": "claude-sonnet-4",
448
+ "messages": [{"role": "user", "content": "Hello!"}]
449
+ }'
529
450
 
530
- ```sh
531
- npx copilot-api-plus@latest start --antigravity --claude-code
451
+ # Anthropic 格式
452
+ curl http://localhost:4141/v1/messages \
453
+ -H "Content-Type: application/json" \
454
+ -H "x-api-key: dummy" \
455
+ -d '{
456
+ "model": "claude-sonnet-4",
457
+ "max_tokens": 1024,
458
+ "messages": [{"role": "user", "content": "Hello!"}]
459
+ }'
532
460
  ```
533
461
 
534
- 会自动生成 Claude Code 启动命令。
535
-
536
- #### 4. API 路径
537
-
538
- Antigravity 模式下:
539
-
540
- | 路径 | 说明 |
541
- | --------------------------------- | ---------------------------- |
542
- | `POST /v1/chat/completions` | OpenAI 兼容聊天补全 |
543
- | `POST /v1/messages` | Anthropic 兼容消息 API |
544
- | `GET /v1/models` | 模型列表 |
462
+ ---
545
463
 
546
- Antigravity 专属路径(始终可用):
464
+ ## ⚙️ 命令行参考
465
+
466
+ ### 命令列表
467
+
468
+ | 命令 | 说明 |
469
+ |------|------|
470
+ | `start` | 启动 API 服务器 |
471
+ | `auth` | 仅执行 GitHub 认证流程 |
472
+ | `logout` | 清除已保存的凭证 |
473
+ | `proxy` | 配置代理设置 |
474
+ | `check-usage` | 查看 Copilot 使用量 |
475
+ | `debug` | 显示调试信息 |
476
+
477
+ ### start 命令参数
478
+
479
+ | 参数 | 别名 | 默认值 | 说明 |
480
+ |------|------|--------|------|
481
+ | `--port` | `-p` | 4141 | 监听端口 |
482
+ | `--verbose` | `-v` | false | 详细日志 |
483
+ | `--account-type` | `-a` | individual | 账户类型 (individual/business/enterprise) |
484
+ | `--claude-code` | `-c` | false | 生成 Claude Code 启动命令 |
485
+ | `--zen` | `-z` | false | 启用 OpenCode Zen 模式 |
486
+ | `--zen-api-key` | - | - | Zen API Key |
487
+ | `--antigravity` | - | false | 启用 Google Antigravity 模式 |
488
+ | `--rate-limit` | `-r` | - | 请求间隔(秒) |
489
+ | `--wait` | `-w` | false | 达到限制时等待而非报错 |
490
+ | `--manual` | - | false | 手动审批每个请求 |
491
+ | `--github-token` | `-g` | - | 直接提供 GitHub Token |
492
+ | `--show-token` | - | false | 显示 Token 信息 |
493
+ | `--proxy-env` | - | false | 从环境变量读取代理 |
494
+
495
+ ### proxy 命令参数
496
+
497
+ | 参数 | 说明 |
498
+ |------|------|
499
+ | `--set` | 交互式配置代理 |
500
+ | `--enable` | 启用已保存的代理 |
501
+ | `--disable` | 禁用代理(保留设置) |
502
+ | `--clear` | 清除代理配置 |
503
+ | `--show` | 显示当前配置 |
504
+ | `--http-proxy` | HTTP 代理 URL |
505
+ | `--https-proxy` | HTTPS 代理 URL |
506
+ | `--no-proxy` | 不走代理的主机列表 |
507
+
508
+ ### logout 命令参数
509
+
510
+ | 参数 | 说明 |
511
+ |------|------|
512
+ | `--zen` | 仅清除 Zen 凭证 |
513
+ | `--antigravity` | 仅清除 Antigravity 凭证 |
514
+ | `--all` | 清除所有凭证 |
547
515
 
548
- | 路径 | 说明 |
549
- | ----------------------------------------- | ------------------ |
550
- | `POST /antigravity/v1/chat/completions` | Antigravity 聊天 |
551
- | `POST /antigravity/v1/messages` | Antigravity 消息 |
552
- | `GET /antigravity/v1/models` | Antigravity 模型 |
516
+ ---
553
517
 
554
- #### 5. 账户管理
518
+ ## 🐳 Docker 部署
555
519
 
556
- - **账户存储位置**:`~/.local/share/copilot-api-plus/antigravity-accounts.json`
557
- - **清除账户**:
558
- ```sh
559
- npx copilot-api-plus@latest logout --antigravity
560
- ```
561
- - **支持多账户**:可添加多个 Google 账户,自动轮换
520
+ ### 快速启动
562
521
 
563
- #### 6. 特性
522
+ ```bash
523
+ # 使用预构建镜像
524
+ docker run -p 4141:4141 \
525
+ -v ./copilot-data:/root/.local/share/copilot-api-plus \
526
+ ghcr.io/imbuxiangnan-cyber/copilot-api-plus
527
+ ```
564
528
 
565
- - 自动 Token 刷新
566
- - 多账户支持与自动轮换
567
- - 配额用尽自动切换账户
568
- - 支持 Thinking 模型(思考链输出)
529
+ ### 自行构建
569
530
 
570
- ## Using with Claude Code
531
+ ```bash
532
+ # 构建镜像
533
+ docker build -t copilot-api-plus .
571
534
 
572
- This proxy can be used to power [Claude Code](https://docs.anthropic.com/en/claude-code), an experimental conversational AI assistant for developers from Anthropic.
535
+ # 运行容器
536
+ docker run -p 4141:4141 \
537
+ -v ./copilot-data:/root/.local/share/copilot-api-plus \
538
+ copilot-api-plus
539
+ ```
573
540
 
574
- There are two ways to configure Claude Code to use this proxy:
541
+ ### Docker Compose
575
542
 
576
- ### Interactive Setup with `--claude-code` flag
543
+ ```yaml
544
+ version: "3.8"
545
+ services:
546
+ copilot-api-plus:
547
+ build: .
548
+ ports:
549
+ - "4141:4141"
550
+ volumes:
551
+ - ./copilot-data:/root/.local/share/copilot-api-plus
552
+ environment:
553
+ - GH_TOKEN=your_github_token # 可选
554
+ restart: unless-stopped
555
+ ```
577
556
 
578
- To get started, run the `start` command with the `--claude-code` flag:
557
+ ### 使用代理
579
558
 
580
- ```sh
581
- npx copilot-api-plus@latest start --claude-code
559
+ ```bash
560
+ docker run -p 4141:4141 \
561
+ -e HTTP_PROXY=http://host.docker.internal:7890 \
562
+ -e HTTPS_PROXY=http://host.docker.internal:7890 \
563
+ -v ./copilot-data:/root/.local/share/copilot-api-plus \
564
+ copilot-api-plus start --proxy-env
582
565
  ```
583
566
 
584
- You will be prompted to select a primary model and a "small, fast" model for background tasks. After selecting the models, a command will be copied to your clipboard. This command sets the necessary environment variables for Claude Code to use the proxy.
585
-
586
- Paste and run this command in a new terminal to launch Claude Code.
567
+ ---
587
568
 
588
- ### Manual Configuration with `settings.json`
569
+ ## 常见问题
589
570
 
590
- Alternatively, you can configure Claude Code by creating a `.claude/settings.json` file in your project's root directory. This file should contain the environment variables needed by Claude Code. This way you don't need to run the interactive setup every time.
571
+ ### 数据存储位置
591
572
 
592
- Here is an example `.claude/settings.json` file:
573
+ 所有数据存储在 `~/.local/share/copilot-api-plus/` 目录下:
593
574
 
594
- ```json
595
- {
596
- "env": {
597
- "ANTHROPIC_BASE_URL": "http://localhost:4141",
598
- "ANTHROPIC_AUTH_TOKEN": "dummy",
599
- "ANTHROPIC_MODEL": "gpt-4.1",
600
- "ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-4.1",
601
- "ANTHROPIC_SMALL_FAST_MODEL": "gpt-4.1",
602
- "ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-4.1",
603
- "DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1",
604
- "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
605
- },
606
- "permissions": {
607
- "deny": [
608
- "WebSearch"
609
- ]
610
- }
611
- }
612
- ```
575
+ | 文件 | 说明 |
576
+ |------|------|
577
+ | `github_token` | GitHub Token |
578
+ | `zen-auth.json` | Zen API Key |
579
+ | `antigravity-accounts.json` | Antigravity 账户 |
580
+ | `config.json` | 代理等配置 |
613
581
 
614
- You can find more options here: [Claude Code settings](https://docs.anthropic.com/en/docs/claude-code/settings#environment-variables)
582
+ ### 切换账户
615
583
 
616
- You can also read more about IDE integration here: [Add Claude Code to your IDE](https://docs.anthropic.com/en/docs/claude-code/ide-integrations)
584
+ ```bash
585
+ # 清除 GitHub 凭证
586
+ npx copilot-api-plus@latest logout
617
587
 
618
- ## Using with opencode
588
+ # 清除 Zen 凭证
589
+ npx copilot-api-plus@latest logout --zen
619
590
 
620
- [opencode](https://github.com/sst/opencode) is a modern AI coding assistant that supports multiple providers. You can use copilot-api-plus as a custom provider for opencode.
591
+ # 清除 Antigravity 凭证
592
+ npx copilot-api-plus@latest logout --antigravity
621
593
 
622
- ### Configuration
594
+ # 清除所有凭证
595
+ npx copilot-api-plus@latest logout --all
596
+ ```
623
597
 
624
- Create or edit `opencode.json` in your project root directory:
598
+ ### 查看使用量
625
599
 
626
- ```json
627
- {
628
- "$schema": "https://opencode.ai/config.json",
629
- "provider": {
630
- "copilot-api-plus": {
631
- "api": "openai-compatible",
632
- "name": "Copilot API Plus",
633
- "options": {
634
- "baseURL": "http://127.0.0.1:4141/v1"
635
- },
636
- "models": {
637
- "claude-sonnet-4": {
638
- "name": "Claude Sonnet 4",
639
- "id": "claude-sonnet-4",
640
- "max_tokens": 64000,
641
- "default_tokens": 16000,
642
- "profile": "coder",
643
- "attachment": true,
644
- "limit": {
645
- "context": 200000
646
- }
647
- },
648
- "claude-sonnet-4.5": {
649
- "name": "Claude Sonnet 4.5",
650
- "id": "claude-sonnet-4.5",
651
- "max_tokens": 64000,
652
- "default_tokens": 16000,
653
- "profile": "coder",
654
- "attachment": true,
655
- "limit": {
656
- "context": 200000
657
- }
658
- },
659
- "gpt-4.1": {
660
- "name": "GPT-4.1",
661
- "id": "gpt-4.1",
662
- "max_tokens": 32768,
663
- "default_tokens": 16000,
664
- "profile": "coder",
665
- "attachment": true,
666
- "limit": {
667
- "context": 1047576
668
- }
669
- },
670
- "o4-mini": {
671
- "name": "o4-mini",
672
- "id": "o4-mini",
673
- "max_tokens": 100000,
674
- "default_tokens": 16000,
675
- "profile": "coder",
676
- "attachment": true,
677
- "limit": {
678
- "context": 200000
679
- }
680
- },
681
- "gemini-2.5-pro": {
682
- "name": "Gemini 2.5 Pro",
683
- "id": "gemini-2.5-pro",
684
- "max_tokens": 65536,
685
- "default_tokens": 16000,
686
- "profile": "coder",
687
- "attachment": true,
688
- "limit": {
689
- "context": 1048576
690
- }
691
- }
692
- }
693
- }
694
- }
695
- }
600
+ ```bash
601
+ # 命令行查看(仅 Copilot)
602
+ npx copilot-api-plus@latest check-usage
696
603
  ```
697
604
 
698
- ### Usage
699
-
700
- 1. Start copilot-api-plus:
701
- ```sh
702
- npx copilot-api-plus@latest start --proxy-env
703
- ```
605
+ 启动服务器后,也可以访问 Web 仪表盘:
606
+ ```
607
+ https://imbuxiangnan-cyber.github.io/copilot-api-plus?endpoint=http://localhost:4141/usage
608
+ ```
704
609
 
705
- 2. Run opencode in the same project directory:
706
- ```sh
707
- npx opencode@latest
708
- ```
610
+ ### 调试问题
709
611
 
710
- 3. Select `copilot-api-plus` as your provider when prompted, or use the model switcher to change providers.
612
+ ```bash
613
+ # 显示调试信息
614
+ npx copilot-api-plus@latest debug
711
615
 
712
- ### Available Models
616
+ # JSON 格式输出
617
+ npx copilot-api-plus@latest debug --json
713
618
 
714
- When using copilot-api-plus with opencode, you can access all GitHub Copilot models:
619
+ # 启用详细日志
620
+ npx copilot-api-plus@latest start --verbose
621
+ ```
715
622
 
716
- | Model | Description |
717
- | ----------------- | ------------------------------------ |
718
- | `claude-sonnet-4` | Claude Sonnet 4 (200K context) |
719
- | `claude-sonnet-4.5` | Claude Sonnet 4.5 (200K context) |
720
- | `gpt-4.1` | GPT-4.1 (1M context) |
721
- | `o4-mini` | OpenAI o4-mini reasoning model |
722
- | `gemini-2.5-pro` | Google Gemini 2.5 Pro (1M context) |
623
+ ### 速率限制
723
624
 
724
- ### Environment Variables for opencode
625
+ 避免触发 GitHub 的滥用检测:
725
626
 
726
- If you prefer not to create a config file, you can also set environment variables:
627
+ ```bash
628
+ # 设置请求间隔 30 秒
629
+ npx copilot-api-plus@latest start --rate-limit 30
727
630
 
728
- ```sh
729
- # Set the base URL for opencode to use
730
- export OPENAI_BASE_URL=http://127.0.0.1:4141/v1
731
- export OPENAI_API_KEY=dummy
631
+ # 达到限制时等待而非报错
632
+ npx copilot-api-plus@latest start --rate-limit 30 --wait
732
633
 
733
- # Start opencode
734
- npx opencode@latest
634
+ # 手动审批每个请求
635
+ npx copilot-api-plus@latest start --manual
735
636
  ```
736
637
 
737
- ## Running from Source
738
-
739
- The project can be run from source in several ways:
638
+ ---
740
639
 
741
- ### Development Mode
640
+ ## ⚠️ 免责声明
742
641
 
743
- ```sh
744
- bun run dev
745
- ```
642
+ > [!WARNING]
643
+ > 这是 GitHub Copilot API 的逆向工程代理。**不受 GitHub 官方支持**,可能随时失效。使用风险自负。
746
644
 
747
- ### Production Mode
645
+ > [!WARNING]
646
+ > **GitHub 安全提示**:过度的自动化或脚本化使用 Copilot 可能触发 GitHub 的滥用检测系统,导致 Copilot 访问被暂停。请负责任地使用。
647
+ >
648
+ > 相关政策:
649
+ > - [GitHub 可接受使用政策](https://docs.github.com/site-policy/acceptable-use-policies/github-acceptable-use-policies)
650
+ > - [GitHub Copilot 条款](https://docs.github.com/site-policy/github-terms/github-terms-for-additional-products-and-features#github-copilot)
748
651
 
749
- ```sh
750
- bun run start
751
- ```
652
+ ---
752
653
 
753
- ## Usage Tips
654
+ ## 📄 许可证
754
655
 
755
- - To avoid hitting GitHub Copilot's rate limits, you can use the following flags:
756
- - `--manual`: Enables manual approval for each request, giving you full control over when requests are sent.
757
- - `--rate-limit <seconds>`: Enforces a minimum time interval between requests. For example, `copilot-api start --rate-limit 30` will ensure there's at least a 30-second gap between requests.
758
- - `--wait`: Use this with `--rate-limit`. It makes the server wait for the cooldown period to end instead of rejecting the request with an error. This is useful for clients that don't automatically retry on rate limit errors.
759
- - If you have a GitHub business or enterprise plan account with Copilot, use the `--account-type` flag (e.g., `--account-type business`). See the [official documentation](https://docs.github.com/en/enterprise-cloud@latest/copilot/managing-copilot/managing-github-copilot-in-your-organization/managing-access-to-github-copilot-in-your-organization/managing-github-copilot-access-to-your-organizations-network#configuring-copilot-subscription-based-network-routing-for-your-enterprise-or-organization) for more details.
656
+ MIT License