@jer-y/copilot-proxy 0.1.0 → 0.1.2
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 +80 -30
- package/README.zh-CN.md +396 -0
- package/dist/main.js +14 -4
- package/dist/main.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
English | [简体中文](README.zh-CN.md)
|
|
2
|
+
|
|
1
3
|
# Copilot API Proxy
|
|
2
4
|
|
|
3
5
|
> [!WARNING]
|
|
@@ -25,12 +27,13 @@
|
|
|
25
27
|
|
|
26
28
|
## Project Overview
|
|
27
29
|
|
|
28
|
-
A reverse-engineered proxy for the GitHub Copilot API that exposes it as an OpenAI and Anthropic
|
|
30
|
+
A reverse-engineered proxy for the GitHub Copilot API that exposes it as an OpenAI- and Anthropic-compatible service. This lets you use GitHub Copilot with tools that support OpenAI Chat Completions/Responses or Anthropic Messages, including [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview) and OpenAI Codex.
|
|
29
31
|
|
|
30
32
|
## Features
|
|
31
33
|
|
|
32
34
|
- **OpenAI & Anthropic Compatibility**: Exposes GitHub Copilot as an OpenAI-compatible (`/v1/chat/completions`, `/v1/models`, `/v1/embeddings`) and Anthropic-compatible (`/v1/messages`) API.
|
|
33
35
|
- **Responses API Support**: Supports the OpenAI Responses API (`/v1/responses`) for thinking-mode models like `gpt-5`, `gpt-5.1-codex`, `gpt-5.2-codex`, `o3-mini`, and `o4-mini`.
|
|
36
|
+
- **Codex Ready**: Works with OpenAI Codex CLI/SDK by pointing its base URL to this proxy.
|
|
34
37
|
- **Model-Aware Translation**: Automatically applies model-specific optimizations — prompt caching (`copilot_cache_control`) for Claude models, `reasoning_effort` mapping from Anthropic's `thinking.budget_tokens`, and intelligent model name normalization (e.g., `claude-sonnet-4-5-20250929` → `claude-sonnet-4.5`).
|
|
35
38
|
- **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`).
|
|
36
39
|
- **Usage Dashboard**: A web-based dashboard to monitor your Copilot API usage, view quotas, and see detailed statistics.
|
|
@@ -47,7 +50,52 @@ A reverse-engineered proxy for the GitHub Copilot API that exposes it as an Open
|
|
|
47
50
|
|
|
48
51
|
## Installation
|
|
49
52
|
|
|
50
|
-
|
|
53
|
+
### Install the CLI (global)
|
|
54
|
+
|
|
55
|
+
Pick your package manager:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
# npm
|
|
59
|
+
npm i -g @jer-y/copilot-proxy
|
|
60
|
+
|
|
61
|
+
# pnpm
|
|
62
|
+
pnpm add -g @jer-y/copilot-proxy
|
|
63
|
+
|
|
64
|
+
# yarn (classic)
|
|
65
|
+
yarn global add @jer-y/copilot-proxy
|
|
66
|
+
|
|
67
|
+
# bun
|
|
68
|
+
bun add -g @jer-y/copilot-proxy
|
|
69
|
+
|
|
70
|
+
# volta (optional)
|
|
71
|
+
volta install @jer-y/copilot-proxy
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Then run:
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
copilot-proxy start
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Run without installing (one-off)
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
# npx
|
|
84
|
+
npx @jer-y/copilot-proxy@latest start
|
|
85
|
+
|
|
86
|
+
# pnpm dlx
|
|
87
|
+
pnpm dlx @jer-y/copilot-proxy@latest start
|
|
88
|
+
|
|
89
|
+
# yarn dlx
|
|
90
|
+
yarn dlx @jer-y/copilot-proxy@latest start
|
|
91
|
+
|
|
92
|
+
# bunx
|
|
93
|
+
bunx @jer-y/copilot-proxy@latest start
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Install from source (development)
|
|
97
|
+
|
|
98
|
+
To install dependencies locally, run:
|
|
51
99
|
|
|
52
100
|
```sh
|
|
53
101
|
bun install
|
|
@@ -70,7 +118,7 @@ mkdir -p ./copilot-data
|
|
|
70
118
|
# Run the container with a bind mount to persist the token
|
|
71
119
|
# This ensures your authentication survives container restarts
|
|
72
120
|
|
|
73
|
-
docker run -p
|
|
121
|
+
docker run -p 4399:4399 -v $(pwd)/copilot-data:/root/.local/share/copilot-proxy copilot-proxy
|
|
74
122
|
```
|
|
75
123
|
|
|
76
124
|
> **Note:**
|
|
@@ -85,10 +133,10 @@ You can pass the GitHub token directly to the container using environment variab
|
|
|
85
133
|
docker build --build-arg GH_TOKEN=your_github_token_here -t copilot-proxy .
|
|
86
134
|
|
|
87
135
|
# Run with GitHub token
|
|
88
|
-
docker run -p
|
|
136
|
+
docker run -p 4399:4399 -e GH_TOKEN=your_github_token_here copilot-proxy
|
|
89
137
|
|
|
90
138
|
# Run with additional options
|
|
91
|
-
docker run -p
|
|
139
|
+
docker run -p 4399:4399 -e GH_TOKEN=your_token copilot-proxy start --verbose --port 4399
|
|
92
140
|
```
|
|
93
141
|
|
|
94
142
|
### Docker Compose Example
|
|
@@ -99,7 +147,7 @@ services:
|
|
|
99
147
|
copilot-proxy:
|
|
100
148
|
build: .
|
|
101
149
|
ports:
|
|
102
|
-
- '
|
|
150
|
+
- '4399:4399'
|
|
103
151
|
environment:
|
|
104
152
|
- GH_TOKEN=your_github_token_here
|
|
105
153
|
restart: unless-stopped
|
|
@@ -112,26 +160,28 @@ The Docker image includes:
|
|
|
112
160
|
- Health check for container monitoring
|
|
113
161
|
- Pinned base image version for reproducible builds
|
|
114
162
|
|
|
115
|
-
## Using with npx
|
|
163
|
+
## Using with npx (or pnpm/bunx)
|
|
116
164
|
|
|
117
165
|
You can run the project directly using npx:
|
|
118
166
|
|
|
119
167
|
```sh
|
|
120
|
-
npx copilot-proxy@latest start
|
|
168
|
+
npx @jer-y/copilot-proxy@latest start
|
|
121
169
|
```
|
|
122
170
|
|
|
123
171
|
With options:
|
|
124
172
|
|
|
125
173
|
```sh
|
|
126
|
-
npx copilot-proxy@latest start --port 8080
|
|
174
|
+
npx @jer-y/copilot-proxy@latest start --port 8080
|
|
127
175
|
```
|
|
128
176
|
|
|
129
177
|
For authentication only:
|
|
130
178
|
|
|
131
179
|
```sh
|
|
132
|
-
npx copilot-proxy@latest auth
|
|
180
|
+
npx @jer-y/copilot-proxy@latest auth
|
|
133
181
|
```
|
|
134
182
|
|
|
183
|
+
> Tip: If you prefer pnpm/bun/yarn, replace `npx` with `pnpm dlx`, `bunx`, or `yarn dlx`.
|
|
184
|
+
|
|
135
185
|
## Command Structure
|
|
136
186
|
|
|
137
187
|
Copilot API now uses a subcommand structure with these main commands:
|
|
@@ -149,7 +199,7 @@ The following command line options are available for the `start` command:
|
|
|
149
199
|
|
|
150
200
|
| Option | Description | Default | Alias |
|
|
151
201
|
| -------------- | ----------------------------------------------------------------------------- | ---------- | ----- |
|
|
152
|
-
| --port | Port to listen on |
|
|
202
|
+
| --port | Port to listen on | 4399 | -p |
|
|
153
203
|
| --verbose | Enable verbose logging | false | -v |
|
|
154
204
|
| --account-type | Account type to use (individual, business, enterprise) | individual | -a |
|
|
155
205
|
| --manual | Enable manual request approval | false | none |
|
|
@@ -215,50 +265,50 @@ Endpoints for monitoring your Copilot usage and quotas.
|
|
|
215
265
|
|
|
216
266
|
## Example Usage
|
|
217
267
|
|
|
218
|
-
Using with npx:
|
|
268
|
+
Using with npx (replace with `pnpm dlx`, `bunx`, or `yarn dlx` if preferred):
|
|
219
269
|
|
|
220
270
|
```sh
|
|
221
271
|
# Basic usage with start command
|
|
222
|
-
npx copilot-proxy@latest start
|
|
272
|
+
npx @jer-y/copilot-proxy@latest start
|
|
223
273
|
|
|
224
274
|
# Run on custom port with verbose logging
|
|
225
|
-
npx copilot-proxy@latest start --port 8080 --verbose
|
|
275
|
+
npx @jer-y/copilot-proxy@latest start --port 8080 --verbose
|
|
226
276
|
|
|
227
277
|
# Use with a business plan GitHub account
|
|
228
|
-
npx copilot-proxy@latest start --account-type business
|
|
278
|
+
npx @jer-y/copilot-proxy@latest start --account-type business
|
|
229
279
|
|
|
230
280
|
# Use with an enterprise plan GitHub account
|
|
231
|
-
npx copilot-proxy@latest start --account-type enterprise
|
|
281
|
+
npx @jer-y/copilot-proxy@latest start --account-type enterprise
|
|
232
282
|
|
|
233
283
|
# Enable manual approval for each request
|
|
234
|
-
npx copilot-proxy@latest start --manual
|
|
284
|
+
npx @jer-y/copilot-proxy@latest start --manual
|
|
235
285
|
|
|
236
286
|
# Set rate limit to 30 seconds between requests
|
|
237
|
-
npx copilot-proxy@latest start --rate-limit 30
|
|
287
|
+
npx @jer-y/copilot-proxy@latest start --rate-limit 30
|
|
238
288
|
|
|
239
289
|
# Wait instead of error when rate limit is hit
|
|
240
|
-
npx copilot-proxy@latest start --rate-limit 30 --wait
|
|
290
|
+
npx @jer-y/copilot-proxy@latest start --rate-limit 30 --wait
|
|
241
291
|
|
|
242
292
|
# Provide GitHub token directly
|
|
243
|
-
npx copilot-proxy@latest start --github-token ghp_YOUR_TOKEN_HERE
|
|
293
|
+
npx @jer-y/copilot-proxy@latest start --github-token ghp_YOUR_TOKEN_HERE
|
|
244
294
|
|
|
245
295
|
# Run only the auth flow
|
|
246
|
-
npx copilot-proxy@latest auth
|
|
296
|
+
npx @jer-y/copilot-proxy@latest auth
|
|
247
297
|
|
|
248
298
|
# Run auth flow with verbose logging
|
|
249
|
-
npx copilot-proxy@latest auth --verbose
|
|
299
|
+
npx @jer-y/copilot-proxy@latest auth --verbose
|
|
250
300
|
|
|
251
301
|
# Show your Copilot usage/quota in the terminal (no server needed)
|
|
252
|
-
npx copilot-proxy@latest check-usage
|
|
302
|
+
npx @jer-y/copilot-proxy@latest check-usage
|
|
253
303
|
|
|
254
304
|
# Display debug information for troubleshooting
|
|
255
|
-
npx copilot-proxy@latest debug
|
|
305
|
+
npx @jer-y/copilot-proxy@latest debug
|
|
256
306
|
|
|
257
307
|
# Display debug information in JSON format
|
|
258
|
-
npx copilot-proxy@latest debug --json
|
|
308
|
+
npx @jer-y/copilot-proxy@latest debug --json
|
|
259
309
|
|
|
260
310
|
# Initialize proxy from environment variables (HTTP_PROXY, HTTPS_PROXY, etc.)
|
|
261
|
-
npx copilot-proxy@latest start --proxy-env
|
|
311
|
+
npx @jer-y/copilot-proxy@latest start --proxy-env
|
|
262
312
|
```
|
|
263
313
|
|
|
264
314
|
## Using the Usage Viewer
|
|
@@ -267,10 +317,10 @@ After starting the server, a URL to the Copilot Usage Dashboard will be displaye
|
|
|
267
317
|
|
|
268
318
|
1. Start the server. For example, using npx:
|
|
269
319
|
```sh
|
|
270
|
-
npx copilot-proxy@latest start
|
|
320
|
+
npx @jer-y/copilot-proxy@latest start
|
|
271
321
|
```
|
|
272
322
|
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:
|
|
273
|
-
`https://jer-y.github.io/copilot-proxy?endpoint=http://localhost:
|
|
323
|
+
`https://jer-y.github.io/copilot-proxy?endpoint=http://localhost:4399/usage`
|
|
274
324
|
- If you use the `start.bat` script on Windows, this page will open automatically.
|
|
275
325
|
|
|
276
326
|
The dashboard provides a user-friendly interface to view your Copilot usage data:
|
|
@@ -293,7 +343,7 @@ There are two ways to configure Claude Code to use this proxy:
|
|
|
293
343
|
To get started, run the `start` command with the `--claude-code` flag:
|
|
294
344
|
|
|
295
345
|
```sh
|
|
296
|
-
npx copilot-proxy@latest start --claude-code
|
|
346
|
+
npx @jer-y/copilot-proxy@latest start --claude-code
|
|
297
347
|
```
|
|
298
348
|
|
|
299
349
|
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.
|
|
@@ -309,7 +359,7 @@ Here is an example `.claude/settings.json` file:
|
|
|
309
359
|
```json
|
|
310
360
|
{
|
|
311
361
|
"env": {
|
|
312
|
-
"ANTHROPIC_BASE_URL": "http://localhost:
|
|
362
|
+
"ANTHROPIC_BASE_URL": "http://localhost:4399",
|
|
313
363
|
"ANTHROPIC_AUTH_TOKEN": "dummy",
|
|
314
364
|
"ANTHROPIC_MODEL": "gpt-4.1",
|
|
315
365
|
"ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-4.1",
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
[English](README.md) | 简体中文
|
|
2
|
+
|
|
3
|
+
# Copilot API 代理
|
|
4
|
+
|
|
5
|
+
> [!WARNING]
|
|
6
|
+
> 这是一个通过逆向工程实现的 GitHub Copilot API 代理。它不受 GitHub 官方支持,可能随时失效。使用风险自负。
|
|
7
|
+
|
|
8
|
+
> [!WARNING]
|
|
9
|
+
> **GitHub 安全提示:**
|
|
10
|
+
> 对 Copilot 的过度自动化或脚本化使用(包括快速或批量请求)可能触发 GitHub 的滥用检测系统。
|
|
11
|
+
> 你可能会收到 GitHub Security 的警告,进一步的异常活动可能导致 Copilot 权限被临时暂停。
|
|
12
|
+
>
|
|
13
|
+
> GitHub 禁止过度的自动化批量活动或任何对其基础设施造成不当负担的行为。
|
|
14
|
+
>
|
|
15
|
+
> 请阅读:
|
|
16
|
+
>
|
|
17
|
+
> - [GitHub 可接受使用政策](https://docs.github.com/site-policy/acceptable-use-policies/github-acceptable-use-policies#4-spam-and-inauthentic-activity-on-github)
|
|
18
|
+
> - [GitHub Copilot 条款](https://docs.github.com/site-policy/github-terms/github-terms-for-additional-products-and-features#github-copilot)
|
|
19
|
+
>
|
|
20
|
+
> 请负责任地使用本代理以避免账号受限。
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
**注意:** 如果你在使用 [opencode](https://github.com/sst/opencode),则不需要本项目。Opencode 已原生支持 GitHub Copilot Provider。
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 项目概览
|
|
29
|
+
|
|
30
|
+
这是一个面向 GitHub Copilot API 的逆向代理,将其暴露为 OpenAI/Anthropic 兼容服务。你可以用任何支持 OpenAI Chat Completions/Responses 或 Anthropic Messages 的工具来调用 GitHub Copilot,包括 [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview) 与 OpenAI Codex。
|
|
31
|
+
|
|
32
|
+
## 功能特性
|
|
33
|
+
|
|
34
|
+
- **OpenAI & Anthropic 兼容**:提供 OpenAI 兼容端点(`/v1/chat/completions`, `/v1/models`, `/v1/embeddings`)与 Anthropic 兼容端点(`/v1/messages`)。
|
|
35
|
+
- **Responses API 支持**:支持 OpenAI Responses API(`/v1/responses`),适用于 `gpt-5`、`gpt-5.1-codex`、`gpt-5.2-codex`、`o3-mini`、`o4-mini` 等思考型模型。
|
|
36
|
+
- **Codex 可用**:将 OpenAI Codex CLI/SDK 的 base URL 指向本代理即可使用。
|
|
37
|
+
- **模型感知翻译**:自动应用模型优化 —— Claude 的提示缓存(`copilot_cache_control`)、Anthropic `thinking.budget_tokens` → `reasoning_effort` 映射,以及模型名归一化(如 `claude-sonnet-4-5-20250929` → `claude-sonnet-4.5`)。
|
|
38
|
+
- **Claude Code 集成**:通过 `--claude-code` 一键生成配置命令,直接用 Copilot 作为 Claude Code 后端。
|
|
39
|
+
- **用量面板**:Web 仪表盘查看 Copilot API 使用量与配额。
|
|
40
|
+
- **速率限制**:通过 `--rate-limit` 与 `--wait` 控制请求节流,避免频繁请求报错。
|
|
41
|
+
- **手动审核**:通过 `--manual` 对每个请求进行人工确认。
|
|
42
|
+
- **Token 可视化**:`--show-token` 显示 GitHub/Copilot token 便于调试。
|
|
43
|
+
- **灵活认证**:支持交互式登录或直接传入 GitHub token,适用于 CI/CD。
|
|
44
|
+
- **多账号类型**:支持个人、企业、组织三种 Copilot 账户类型。
|
|
45
|
+
|
|
46
|
+
## 前置要求
|
|
47
|
+
|
|
48
|
+
- Bun (>= 1.2.x)
|
|
49
|
+
- 拥有 Copilot 订阅的 GitHub 账号(个人 / 企业 / 组织)
|
|
50
|
+
|
|
51
|
+
## 安装
|
|
52
|
+
|
|
53
|
+
### 全局安装 CLI
|
|
54
|
+
|
|
55
|
+
选择你的包管理器:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
# npm
|
|
59
|
+
npm i -g @jer-y/copilot-proxy
|
|
60
|
+
|
|
61
|
+
# pnpm
|
|
62
|
+
pnpm add -g @jer-y/copilot-proxy
|
|
63
|
+
|
|
64
|
+
# yarn (classic)
|
|
65
|
+
yarn global add @jer-y/copilot-proxy
|
|
66
|
+
|
|
67
|
+
# bun
|
|
68
|
+
bun add -g @jer-y/copilot-proxy
|
|
69
|
+
|
|
70
|
+
# volta (可选)
|
|
71
|
+
volta install @jer-y/copilot-proxy
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
然后运行:
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
copilot-proxy start
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 免安装运行(一次性)
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
# npx
|
|
84
|
+
npx @jer-y/copilot-proxy@latest start
|
|
85
|
+
|
|
86
|
+
# pnpm dlx
|
|
87
|
+
pnpm dlx @jer-y/copilot-proxy@latest start
|
|
88
|
+
|
|
89
|
+
# yarn dlx
|
|
90
|
+
yarn dlx @jer-y/copilot-proxy@latest start
|
|
91
|
+
|
|
92
|
+
# bunx
|
|
93
|
+
bunx @jer-y/copilot-proxy@latest start
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### 从源码安装(开发)
|
|
97
|
+
|
|
98
|
+
本地安装依赖:
|
|
99
|
+
|
|
100
|
+
```sh
|
|
101
|
+
bun install
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## 使用 Docker
|
|
105
|
+
|
|
106
|
+
构建镜像:
|
|
107
|
+
|
|
108
|
+
```sh
|
|
109
|
+
docker build -t copilot-proxy .
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
运行容器:
|
|
113
|
+
|
|
114
|
+
```sh
|
|
115
|
+
# 在宿主机创建目录以持久化 GitHub token 等数据
|
|
116
|
+
mkdir -p ./copilot-data
|
|
117
|
+
|
|
118
|
+
# 使用挂载目录来保持认证信息,确保容器重启后依旧有效
|
|
119
|
+
docker run -p 4399:4399 -v $(pwd)/copilot-data:/root/.local/share/copilot-proxy copilot-proxy
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
> **提示:**
|
|
123
|
+
> GitHub token 与相关数据会保存在宿主机的 `copilot-data`,映射到容器内 `/root/.local/share/copilot-proxy`,便于持久化。
|
|
124
|
+
|
|
125
|
+
### Docker 环境变量
|
|
126
|
+
|
|
127
|
+
可以通过环境变量直接传入 GitHub token:
|
|
128
|
+
|
|
129
|
+
```sh
|
|
130
|
+
# 构建时注入 GitHub token
|
|
131
|
+
docker build --build-arg GH_TOKEN=your_github_token_here -t copilot-proxy .
|
|
132
|
+
|
|
133
|
+
# 运行时传入 GitHub token
|
|
134
|
+
docker run -p 4399:4399 -e GH_TOKEN=your_github_token_here copilot-proxy
|
|
135
|
+
|
|
136
|
+
# 运行时追加参数
|
|
137
|
+
docker run -p 4399:4399 -e GH_TOKEN=your_token copilot-proxy start --verbose --port 4399
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Docker Compose 示例
|
|
141
|
+
|
|
142
|
+
```yaml
|
|
143
|
+
version: '3.8'
|
|
144
|
+
services:
|
|
145
|
+
copilot-proxy:
|
|
146
|
+
build: .
|
|
147
|
+
ports:
|
|
148
|
+
- '4399:4399'
|
|
149
|
+
environment:
|
|
150
|
+
- GH_TOKEN=your_github_token_here
|
|
151
|
+
restart: unless-stopped
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Docker 镜像包含:
|
|
155
|
+
|
|
156
|
+
- 多阶段构建,体积更小
|
|
157
|
+
- 非 root 用户,安全性更好
|
|
158
|
+
- 健康检查,便于容器监控
|
|
159
|
+
- 固定基础镜像版本,保证可复现
|
|
160
|
+
|
|
161
|
+
## 使用 npx(或 pnpm/bunx)
|
|
162
|
+
|
|
163
|
+
使用 npx 直接运行:
|
|
164
|
+
|
|
165
|
+
```sh
|
|
166
|
+
npx @jer-y/copilot-proxy@latest start
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
带参数示例:
|
|
170
|
+
|
|
171
|
+
```sh
|
|
172
|
+
npx @jer-y/copilot-proxy@latest start --port 8080
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
仅进行认证:
|
|
176
|
+
|
|
177
|
+
```sh
|
|
178
|
+
npx @jer-y/copilot-proxy@latest auth
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
> 提示:如果你使用 pnpm/bun/yarn,可替换为 `pnpm dlx`、`bunx` 或 `yarn dlx`。
|
|
182
|
+
|
|
183
|
+
## 命令结构
|
|
184
|
+
|
|
185
|
+
Copilot API 使用子命令结构,主要命令如下:
|
|
186
|
+
|
|
187
|
+
- `start`:启动 Copilot API 服务(必要时会自动认证)。
|
|
188
|
+
- `auth`:仅进行 GitHub 认证,不启动服务,常用于生成 `--github-token`(CI/CD 场景)。
|
|
189
|
+
- `check-usage`:直接查看 Copilot 使用量/配额(无需启动服务)。
|
|
190
|
+
- `debug`:输出诊断信息,包括版本、运行环境、路径与认证状态。
|
|
191
|
+
|
|
192
|
+
## 命令行参数
|
|
193
|
+
|
|
194
|
+
### start 参数
|
|
195
|
+
|
|
196
|
+
| 参数 | 说明 | 默认值 | 简写 |
|
|
197
|
+
| -------------- | ----------------------------------------------------------------------- | ----------- | ---- |
|
|
198
|
+
| --port | 监听端口 | 4399 | -p |
|
|
199
|
+
| --verbose | 开启详细日志 | false | -v |
|
|
200
|
+
| --account-type | 账户类型(individual, business, enterprise) | individual | -a |
|
|
201
|
+
| --manual | 手动审批每个请求 | false | 无 |
|
|
202
|
+
| --rate-limit | 两次请求之间的最小间隔(秒) | 无 | -r |
|
|
203
|
+
| --wait | 触发限流时等待,而非直接报错 | false | -w |
|
|
204
|
+
| --github-token | 直接传入 GitHub token(需通过 `auth` 命令生成) | 无 | -g |
|
|
205
|
+
| --claude-code | 生成 Claude Code 配置命令 | false | -c |
|
|
206
|
+
| --show-token | 在获取/刷新时显示 GitHub/Copilot token | false | 无 |
|
|
207
|
+
| --proxy-env | 从环境变量初始化代理(HTTP_PROXY/HTTPS_PROXY 等) | false | 无 |
|
|
208
|
+
|
|
209
|
+
### auth 参数
|
|
210
|
+
|
|
211
|
+
| 参数 | 说明 | 默认值 | 简写 |
|
|
212
|
+
| ------------ | ------------------- | ------ | ---- |
|
|
213
|
+
| --verbose | 开启详细日志 | false | -v |
|
|
214
|
+
| --show-token | 显示 GitHub token | false | 无 |
|
|
215
|
+
|
|
216
|
+
### debug 参数
|
|
217
|
+
|
|
218
|
+
| 参数 | 说明 | 默认值 | 简写 |
|
|
219
|
+
| ------ | -------------------- | ------ | ---- |
|
|
220
|
+
| --json | 以 JSON 输出调试信息 | false | 无 |
|
|
221
|
+
|
|
222
|
+
## API 端点
|
|
223
|
+
|
|
224
|
+
服务提供多组端点,以兼容 OpenAI / Anthropic API。所有端点均支持有无 `/v1/` 前缀。
|
|
225
|
+
|
|
226
|
+
### OpenAI 兼容端点
|
|
227
|
+
|
|
228
|
+
| 端点 | 方法 | 说明 |
|
|
229
|
+
| -------------------------- | ---- | ------------------------------------------------ |
|
|
230
|
+
| `POST /v1/chat/completions` | POST | 基于对话创建模型响应 |
|
|
231
|
+
| `GET /v1/models` | GET | 获取可用模型列表 |
|
|
232
|
+
| `POST /v1/embeddings` | POST | 创建文本 Embedding 向量 |
|
|
233
|
+
|
|
234
|
+
### OpenAI Responses API 端点
|
|
235
|
+
|
|
236
|
+
支持 OpenAI Responses API(`/v1/responses`),适用于 `gpt-5`、`gpt-5.1-codex`、`gpt-5.2-codex`、`o3-mini`、`o4-mini` 等思考型模型。请求会被直接转发到 Copilot `/responses`。
|
|
237
|
+
|
|
238
|
+
| 端点 | 方法 | 说明 |
|
|
239
|
+
| ------------------ | ---- | ------------------------------------------------------ |
|
|
240
|
+
| `POST /v1/responses` | POST | 创建 Responses API 响应(支持流式) |
|
|
241
|
+
|
|
242
|
+
### Anthropic 兼容端点
|
|
243
|
+
|
|
244
|
+
这些端点与 Anthropic Messages API 兼容。收到 Anthropic 格式请求后会自动翻译为 OpenAI 格式转发给 Copilot,再将响应翻译回 Anthropic 格式。
|
|
245
|
+
|
|
246
|
+
| 端点 | 方法 | 说明 |
|
|
247
|
+
| ------------------------------- | ---- | -------------------------------------------- |
|
|
248
|
+
| `POST /v1/messages` | POST | 为对话创建模型响应 |
|
|
249
|
+
| `POST /v1/messages/count_tokens` | POST | 计算消息 token 数量 |
|
|
250
|
+
|
|
251
|
+
### 用量监控端点
|
|
252
|
+
|
|
253
|
+
| 端点 | 方法 | 说明 |
|
|
254
|
+
| -------- | ---- | ---------------------------------------------- |
|
|
255
|
+
| `GET /usage` | GET | 获取 Copilot 使用量与配额信息 |
|
|
256
|
+
| `GET /token` | GET | 获取当前正在使用的 Copilot token |
|
|
257
|
+
|
|
258
|
+
## 使用示例
|
|
259
|
+
|
|
260
|
+
使用 npx(可替换为 `pnpm dlx`、`bunx` 或 `yarn dlx`):
|
|
261
|
+
|
|
262
|
+
```sh
|
|
263
|
+
# 基础启动
|
|
264
|
+
npx @jer-y/copilot-proxy@latest start
|
|
265
|
+
|
|
266
|
+
# 自定义端口 + 详细日志
|
|
267
|
+
npx @jer-y/copilot-proxy@latest start --port 8080 --verbose
|
|
268
|
+
|
|
269
|
+
# 商业账号
|
|
270
|
+
npx @jer-y/copilot-proxy@latest start --account-type business
|
|
271
|
+
|
|
272
|
+
# 企业账号
|
|
273
|
+
npx @jer-y/copilot-proxy@latest start --account-type enterprise
|
|
274
|
+
|
|
275
|
+
# 手动审批
|
|
276
|
+
npx @jer-y/copilot-proxy@latest start --manual
|
|
277
|
+
|
|
278
|
+
# 设置请求间隔
|
|
279
|
+
npx @jer-y/copilot-proxy@latest start --rate-limit 30
|
|
280
|
+
|
|
281
|
+
# 触发限流时等待
|
|
282
|
+
npx @jer-y/copilot-proxy@latest start --rate-limit 30 --wait
|
|
283
|
+
|
|
284
|
+
# 直接传入 GitHub token
|
|
285
|
+
npx @jer-y/copilot-proxy@latest start --github-token ghp_YOUR_TOKEN_HERE
|
|
286
|
+
|
|
287
|
+
# 仅认证
|
|
288
|
+
npx @jer-y/copilot-proxy@latest auth
|
|
289
|
+
|
|
290
|
+
# 认证 + 详细日志
|
|
291
|
+
npx @jer-y/copilot-proxy@latest auth --verbose
|
|
292
|
+
|
|
293
|
+
# 查看使用量
|
|
294
|
+
npx @jer-y/copilot-proxy@latest check-usage
|
|
295
|
+
|
|
296
|
+
# 输出调试信息
|
|
297
|
+
npx @jer-y/copilot-proxy@latest debug
|
|
298
|
+
|
|
299
|
+
# JSON 输出调试信息
|
|
300
|
+
npx @jer-y/copilot-proxy@latest debug --json
|
|
301
|
+
|
|
302
|
+
# 从环境变量初始化代理
|
|
303
|
+
npx @jer-y/copilot-proxy@latest start --proxy-env
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## 使用用量面板
|
|
307
|
+
|
|
308
|
+
启动服务后,终端会输出用量面板的 URL。该面板用于查看 Copilot API 的配额与统计信息。
|
|
309
|
+
|
|
310
|
+
1. 使用 npx 启动服务:
|
|
311
|
+
```sh
|
|
312
|
+
npx @jer-y/copilot-proxy@latest start
|
|
313
|
+
```
|
|
314
|
+
2. 终端输出的 URL 类似:
|
|
315
|
+
`https://jer-y.github.io/copilot-proxy?endpoint=http://localhost:4399/usage`
|
|
316
|
+
- 如果你使用 Windows 的 `start.bat`,该页面会自动打开。
|
|
317
|
+
|
|
318
|
+
面板功能包括:
|
|
319
|
+
|
|
320
|
+
- **API Endpoint URL**:可在 URL 中传入 endpoint 参数来指定数据源。
|
|
321
|
+
- **Fetch Data**:点击按钮刷新数据。
|
|
322
|
+
- **Usage Quotas**:以进度条方式展示配额使用情况。
|
|
323
|
+
- **Detailed Information**:查看完整 JSON 响应。
|
|
324
|
+
- **URL 参数配置**:可将 endpoint 直接写入 URL 便于收藏与分享:
|
|
325
|
+
`https://jer-y.github.io/copilot-proxy?endpoint=http://your-api-server/usage`
|
|
326
|
+
|
|
327
|
+
## 使用 Claude Code
|
|
328
|
+
|
|
329
|
+
本代理可用于 [Claude Code](https://docs.anthropic.com/en/claude-code)。
|
|
330
|
+
|
|
331
|
+
有两种方式:
|
|
332
|
+
|
|
333
|
+
### 交互式配置(`--claude-code`)
|
|
334
|
+
|
|
335
|
+
```sh
|
|
336
|
+
npx @jer-y/copilot-proxy@latest start --claude-code
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
会提示选择主要模型与“快速模型”,随后把 Claude Code 所需的环境变量命令复制到剪贴板,粘贴执行即可。
|
|
340
|
+
|
|
341
|
+
### 手动配置 `settings.json`
|
|
342
|
+
|
|
343
|
+
在项目根目录创建 `.claude/settings.json`:
|
|
344
|
+
|
|
345
|
+
```json
|
|
346
|
+
{
|
|
347
|
+
"env": {
|
|
348
|
+
"ANTHROPIC_BASE_URL": "http://localhost:4399",
|
|
349
|
+
"ANTHROPIC_AUTH_TOKEN": "dummy",
|
|
350
|
+
"ANTHROPIC_MODEL": "gpt-4.1",
|
|
351
|
+
"ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-4.1",
|
|
352
|
+
"ANTHROPIC_SMALL_FAST_MODEL": "gpt-4.1",
|
|
353
|
+
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-4.1",
|
|
354
|
+
"DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1",
|
|
355
|
+
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
|
|
356
|
+
},
|
|
357
|
+
"permissions": {
|
|
358
|
+
"deny": [
|
|
359
|
+
"WebSearch"
|
|
360
|
+
]
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
更多选项见:[Claude Code settings](https://docs.anthropic.com/en/docs/claude-code/settings#environment-variables)
|
|
366
|
+
|
|
367
|
+
IDE 集成说明:[Add Claude Code to your IDE](https://docs.anthropic.com/en/docs/claude-code/ide-integrations)
|
|
368
|
+
|
|
369
|
+
## 从源码运行
|
|
370
|
+
|
|
371
|
+
### 开发模式
|
|
372
|
+
|
|
373
|
+
```sh
|
|
374
|
+
bun run dev
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### 生产模式
|
|
378
|
+
|
|
379
|
+
```sh
|
|
380
|
+
bun run start
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
## 使用建议
|
|
384
|
+
|
|
385
|
+
- 为避免触发 GitHub Copilot 的速率限制,可使用:
|
|
386
|
+
- `--manual`:每次请求手动确认
|
|
387
|
+
- `--rate-limit <seconds>`:限制请求最小间隔
|
|
388
|
+
- `--wait`:配合 `--rate-limit` 使用,触发限流时等待而不是报错
|
|
389
|
+
- 如果你是商业版/企业版 Copilot 账号,可使用 `--account-type`:
|
|
390
|
+
- `--account-type business`
|
|
391
|
+
- `--account-type enterprise`
|
|
392
|
+
详见:[官方文档](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)
|
|
393
|
+
|
|
394
|
+
## 致谢
|
|
395
|
+
|
|
396
|
+
本项目 fork 自 [ericc-ch/copilot-api](https://github.com/ericc-ch/copilot-api),仓库主要用于个人使用。
|
package/dist/main.js
CHANGED
|
@@ -92,8 +92,13 @@ function githubHeaders(state$1) {
|
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
94
|
const GITHUB_BASE_URL = "https://github.com";
|
|
95
|
-
const GITHUB_CLIENT_ID = "
|
|
96
|
-
const GITHUB_APP_SCOPES = [
|
|
95
|
+
const GITHUB_CLIENT_ID = "Ov23ctDVkRmgkPke0Mmm";
|
|
96
|
+
const GITHUB_APP_SCOPES = [
|
|
97
|
+
"read:user",
|
|
98
|
+
"read:org",
|
|
99
|
+
"repo",
|
|
100
|
+
"gist"
|
|
101
|
+
].join(",");
|
|
97
102
|
|
|
98
103
|
//#endregion
|
|
99
104
|
//#region src/lib/error.ts
|
|
@@ -163,7 +168,12 @@ async function getGitHubUser() {
|
|
|
163
168
|
//#endregion
|
|
164
169
|
//#region src/services/copilot/get-models.ts
|
|
165
170
|
async function getModels() {
|
|
166
|
-
const
|
|
171
|
+
const headers = copilotHeaders(state);
|
|
172
|
+
if (state.githubToken) {
|
|
173
|
+
headers.Authorization = `Bearer ${state.githubToken}`;
|
|
174
|
+
headers["copilot-integration-id"] = "copilot-developer-cli";
|
|
175
|
+
}
|
|
176
|
+
const response = await fetch(`${copilotBaseUrl(state)}/models`, { headers });
|
|
167
177
|
if (!response.ok) throw new HTTPError("Failed to get models", response);
|
|
168
178
|
return await response.json();
|
|
169
179
|
}
|
|
@@ -1620,7 +1630,7 @@ const start = defineCommand({
|
|
|
1620
1630
|
"port": {
|
|
1621
1631
|
alias: "p",
|
|
1622
1632
|
type: "string",
|
|
1623
|
-
default: "
|
|
1633
|
+
default: "4399",
|
|
1624
1634
|
description: "Port to listen on"
|
|
1625
1635
|
},
|
|
1626
1636
|
"verbose": {
|