@hsupu/copilot-api 0.7.17 → 0.7.18-beta
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 +47 -49
- package/README.zh.md +39 -0
- package/dist/main.mjs +6674 -5600
- package/dist/main.mjs.map +1 -1
- package/package.json +23 -15
- package/ui/history-v1/index.html +149 -0
- package/ui/history-v1/script.js +1799 -0
- package/ui/history-v1/styles.css +1467 -0
- package/ui/history-v3/dist/assets/index-BJHz2Wfg.js +3 -0
- package/ui/history-v3/dist/assets/index-DZDkeXE1.css +1 -0
- package/ui/history-v3/dist/assets/vendor-C3jfkhqq.js +125 -0
- package/ui/history-v3/dist/assets/vue-jlQnwi-P.js +1 -0
- package/ui/history-v3/dist/index.html +15 -0
package/README.md
CHANGED
|
@@ -6,14 +6,13 @@
|
|
|
6
6
|
> [!WARNING]
|
|
7
7
|
> This is a reverse proxy for the GitHub Copilot API. It is not officially supported by GitHub and may break at any time. Use at your own risk.
|
|
8
8
|
|
|
9
|
-
A reverse proxy that exposes GitHub Copilot API as OpenAI and Anthropic compatible
|
|
9
|
+
A reverse proxy that exposes GitHub Copilot's API as standard OpenAI and Anthropic compatible endpoints. Works with Claude Code, Cursor, and other tools that speak these protocols.
|
|
10
10
|
|
|
11
11
|
## Quick Start
|
|
12
12
|
|
|
13
13
|
### Install from npm (Recommended)
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
|
-
# Run directly
|
|
17
16
|
npx -y @hsupu/copilot-api start
|
|
18
17
|
```
|
|
19
18
|
|
|
@@ -26,6 +25,12 @@ bun install
|
|
|
26
25
|
bun run dev # Development mode with hot reload
|
|
27
26
|
bun run start # Production mode
|
|
28
27
|
bun run build # Build for distribution
|
|
28
|
+
|
|
29
|
+
# Testing
|
|
30
|
+
bun test # Backend unit tests
|
|
31
|
+
bun run test:all # All backend tests
|
|
32
|
+
bun run test:ui # Frontend (History UI) tests
|
|
33
|
+
bun run typecheck # TypeScript type checking
|
|
29
34
|
```
|
|
30
35
|
|
|
31
36
|
## Using with Claude Code
|
|
@@ -57,18 +62,8 @@ Or manually create `~/.claude/settings.json`:
|
|
|
57
62
|
|
|
58
63
|
Exposes both OpenAI and Anthropic compatible endpoints through a single proxy:
|
|
59
64
|
|
|
60
|
-
- **Direct Anthropic path** — Uses Copilot API's
|
|
61
|
-
- **Translated path** — Translates
|
|
62
|
-
|
|
63
|
-
### Adaptive Rate Limiting
|
|
64
|
-
|
|
65
|
-
Intelligent rate limiting with exponential backoff, replacing the upstream queue-based approach. Operates in three modes:
|
|
66
|
-
|
|
67
|
-
- **Normal** — Requests pass through freely
|
|
68
|
-
- **Rate-limited** — Queues requests with configurable intervals after hitting limits
|
|
69
|
-
- **Recovering** — Gradually resumes normal operation after consecutive successes
|
|
70
|
-
|
|
71
|
-
Learns from Copilot API's `Retry-After` headers for optimal retry timing.
|
|
65
|
+
- **Direct Anthropic path** — Uses Copilot API's native Anthropic endpoint for Claude models
|
|
66
|
+
- **Translated path** — Translates between OpenAI and Anthropic formats for other models
|
|
72
67
|
|
|
73
68
|
### Auto-Truncate
|
|
74
69
|
|
|
@@ -77,20 +72,18 @@ Automatically handles context length limits (enabled by default):
|
|
|
77
72
|
- **Reactive** — Retries failed requests with a truncated payload when hitting token or byte limits
|
|
78
73
|
- **Proactive** — Pre-checks requests against known model limits before sending
|
|
79
74
|
- **Dynamic limit learning** — Adjusts limits based on actual API error responses
|
|
80
|
-
- **Tool result compression** — Compresses old `tool_result` content before truncating messages
|
|
81
|
-
- Up to 5 retry attempts per request with 2% safety margin
|
|
75
|
+
- **Tool result compression** — Compresses old `tool_result` content before truncating messages
|
|
82
76
|
|
|
83
77
|
### Message Sanitization
|
|
84
78
|
|
|
85
79
|
Cleans up messages before forwarding to the API:
|
|
86
80
|
|
|
87
81
|
- Filters orphaned `tool_use` / `tool_result` blocks (unpaired due to interrupted tool calls or truncation)
|
|
88
|
-
- Handles server-side tools (`server_tool_use` / `*_tool_result`) that appear inline in assistant messages
|
|
89
|
-
- Fixes double-serialized tool inputs from stream accumulation
|
|
90
|
-
- Removes corrupted blocks from older history data
|
|
91
82
|
- Fixes tool name casing mismatches
|
|
92
83
|
- Removes empty text content blocks
|
|
93
84
|
- Strips `<system-reminder>` tags from message content
|
|
85
|
+
- **[Optional]** Deduplicates repeated tool calls (`config.yaml: anthropic.dedup_tool_calls`)
|
|
86
|
+
- **[Optional]** Strips system-reminder tags from Read tool results (`config.yaml: anthropic.truncate_read_tool_result`)
|
|
94
87
|
|
|
95
88
|
### Model Name Translation
|
|
96
89
|
|
|
@@ -103,28 +96,26 @@ Translates client-sent model names to matching Copilot models:
|
|
|
103
96
|
| `claude-sonnet-4-5-20250514` | `claude-sonnet-4.5` |
|
|
104
97
|
| `claude-sonnet-4`, `gpt-4` | Passed through directly |
|
|
105
98
|
|
|
106
|
-
|
|
99
|
+
User-configured `model_overrides` (via config.yaml) can redirect any model name to another, with chained resolution and family-level overrides.
|
|
107
100
|
|
|
108
101
|
### Server-Side Tools
|
|
109
102
|
|
|
110
|
-
Supports Anthropic server-side tools (
|
|
103
|
+
Supports Anthropic server-side tools (`web_search`, `tool_search`). These tools are executed by the API backend, with both `server_tool_use` and result blocks appearing inline in assistant messages. Tool definitions can optionally be rewritten to a custom format (`--no-rewrite-anthropic-tools`).
|
|
111
104
|
|
|
112
105
|
### Request History UI
|
|
113
106
|
|
|
114
|
-
Built-in web interface for inspecting API requests and responses. Access at `http://localhost:4141/history
|
|
107
|
+
Built-in web interface for inspecting API requests and responses. Access at `http://localhost:4141/history/v3/`.
|
|
115
108
|
|
|
116
109
|
- Real-time updates via WebSocket
|
|
117
110
|
- Filter by model, endpoint, status, and time range
|
|
118
|
-
- Full-text search across request/response content
|
|
119
|
-
- Export as JSON or CSV
|
|
120
111
|
- Session tracking and statistics
|
|
121
112
|
|
|
122
113
|
### Additional Features
|
|
123
114
|
|
|
124
|
-
- **
|
|
125
|
-
- **
|
|
126
|
-
- **Tool name truncation** —
|
|
127
|
-
- **Health checks** — Container-ready
|
|
115
|
+
- **Model overrides** — Configure arbitrary model name redirections via config.yaml
|
|
116
|
+
- **Adaptive rate limiting** — Intelligent rate limiting with exponential backoff (3 modes: Normal, Rate-limited, Recovering)
|
|
117
|
+
- **Tool name truncation** — Truncates tool names exceeding 64 characters (OpenAI limit) with hash suffixes
|
|
118
|
+
- **Health checks** — Container-ready endpoint at `/health`
|
|
128
119
|
- **Graceful shutdown** — Connection draining on shutdown signals
|
|
129
120
|
- **Proxy support** — HTTP/HTTPS proxy via environment variables
|
|
130
121
|
|
|
@@ -143,43 +134,49 @@ Built-in web interface for inspecting API requests and responses. Access at `htt
|
|
|
143
134
|
|
|
144
135
|
### `start` Options
|
|
145
136
|
|
|
137
|
+
**General:**
|
|
138
|
+
|
|
146
139
|
| Option | Default | Description |
|
|
147
140
|
|--------|---------|-------------|
|
|
148
141
|
| `--port`, `-p` | 4141 | Port to listen on |
|
|
149
142
|
| `--host`, `-H` | (all interfaces) | Host/interface to bind to |
|
|
150
143
|
| `--verbose`, `-v` | false | Enable verbose logging |
|
|
151
144
|
| `--account-type`, `-a` | individual | Account type: `individual`, `business`, or `enterprise` |
|
|
152
|
-
| `--manual` | false | Manual request approval mode |
|
|
153
145
|
| `--github-token`, `-g` | | Provide GitHub token directly |
|
|
154
|
-
| `--proxy-env` |
|
|
155
|
-
| `--history-limit` | 200 | Max history entries in memory (0 = unlimited) |
|
|
146
|
+
| `--no-http-proxy-from-env` | enabled | Disable HTTP proxy from environment variables |
|
|
156
147
|
|
|
157
|
-
**
|
|
148
|
+
**Auto-Truncate:**
|
|
158
149
|
|
|
159
150
|
| Option | Default | Description |
|
|
160
151
|
|--------|---------|-------------|
|
|
161
|
-
| `--no-
|
|
162
|
-
| `--retry-interval` | 10 | Seconds to wait before retrying after rate limit |
|
|
163
|
-
| `--request-interval` | 10 | Seconds between requests in rate-limited mode |
|
|
164
|
-
| `--recovery-timeout` | 10 | Minutes before attempting recovery |
|
|
165
|
-
| `--consecutive-successes` | 5 | Consecutive successes needed to exit rate-limited mode |
|
|
152
|
+
| `--no-auto-truncate` | enabled | Disable auto-truncation on context limit errors |
|
|
166
153
|
|
|
167
|
-
**
|
|
154
|
+
**Anthropic-Specific (via config.yaml):**
|
|
155
|
+
|
|
156
|
+
These options are configured in `config.yaml` under the `anthropic:` section. See [`config.example.yaml`](config.example.yaml).
|
|
157
|
+
|
|
158
|
+
| Config Key | Default | Description |
|
|
159
|
+
|------------|---------|-------------|
|
|
160
|
+
| `anthropic.rewrite_tools` | true | Rewrite server-side tools to custom format |
|
|
161
|
+
| `stream_idle_timeout` | 300 | Max seconds between SSE events (0 = no timeout) |
|
|
162
|
+
|
|
163
|
+
**Sanitization:**
|
|
168
164
|
|
|
169
165
|
| Option | Default | Description |
|
|
170
166
|
|--------|---------|-------------|
|
|
171
|
-
| `--
|
|
172
|
-
| `--no-compress-tool-results` | false | Disable tool result compression during truncation |
|
|
167
|
+
| `--collect-system-prompts` | false | Collect system prompts to file |
|
|
173
168
|
|
|
174
|
-
**
|
|
169
|
+
**Rate Limiting:**
|
|
175
170
|
|
|
176
171
|
| Option | Default | Description |
|
|
177
172
|
|--------|---------|-------------|
|
|
178
|
-
| `--
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
173
|
+
| `--no-rate-limit` | enabled | Disable adaptive rate limiting |
|
|
174
|
+
|
|
175
|
+
Rate limiter sub-parameters are configured in `config.yaml` under `rate_limiter:`. See [`config.example.yaml`](config.example.yaml).
|
|
176
|
+
|
|
177
|
+
## Configuration
|
|
178
|
+
|
|
179
|
+
Create a `config.yaml` in the working directory. See [`config.example.yaml`](config.example.yaml) for all available options.
|
|
183
180
|
|
|
184
181
|
## API Endpoints
|
|
185
182
|
|
|
@@ -188,6 +185,7 @@ Built-in web interface for inspecting API requests and responses. Access at `htt
|
|
|
188
185
|
| Endpoint | Method | Description |
|
|
189
186
|
|----------|--------|-------------|
|
|
190
187
|
| `/v1/chat/completions` | POST | Chat completions |
|
|
188
|
+
| `/v1/responses` | POST | Responses API |
|
|
191
189
|
| `/v1/models` | GET | List available models |
|
|
192
190
|
| `/v1/models/:model` | GET | Get specific model details |
|
|
193
191
|
| `/v1/embeddings` | POST | Text embeddings |
|
|
@@ -200,7 +198,6 @@ All endpoints also work without the `/v1` prefix.
|
|
|
200
198
|
|----------|--------|-------------|
|
|
201
199
|
| `/v1/messages` | POST | Messages API |
|
|
202
200
|
| `/v1/messages/count_tokens` | POST | Token counting |
|
|
203
|
-
| `/api/event_logging/batch` | POST | Event logging (no-op, returns OK) |
|
|
204
201
|
|
|
205
202
|
### Utility
|
|
206
203
|
|
|
@@ -209,11 +206,12 @@ All endpoints also work without the `/v1` prefix.
|
|
|
209
206
|
| `/health` | GET | Health check (200 healthy, 503 unhealthy) |
|
|
210
207
|
| `/usage` | GET | Copilot usage and quota statistics |
|
|
211
208
|
| `/token` | GET | Current Copilot token information |
|
|
212
|
-
| `/history
|
|
209
|
+
| `/history/v3/` | GET | History web UI |
|
|
213
210
|
| `/history/ws` | WebSocket | Real-time history updates |
|
|
214
211
|
| `/history/api/entries` | GET | Query history entries |
|
|
212
|
+
| `/history/api/entries/:id` | GET | Get single entry |
|
|
213
|
+
| `/history/api/summaries` | GET | Entry summaries |
|
|
215
214
|
| `/history/api/stats` | GET | Usage statistics |
|
|
216
|
-
| `/history/api/export` | GET | Export history (JSON/CSV) |
|
|
217
215
|
| `/history/api/sessions` | GET | List sessions |
|
|
218
216
|
|
|
219
217
|
## Account Types
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
## 项目概述
|
|
3
|
+
|
|
4
|
+
GitHub Copilot API 的逆向代理,将其暴露为 OpenAI 和 Anthropic 兼容端点。使得 Claude Code 等工具可以使用 GitHub Copilot 作为后端。
|
|
5
|
+
|
|
6
|
+
## 常用命令
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
bun install # 安装依赖
|
|
10
|
+
bun run dev # 开发模式(热重载)
|
|
11
|
+
bun run start # 生产模式
|
|
12
|
+
bun run build # 构建发布版(tsdown)
|
|
13
|
+
bun run typecheck # 类型检查
|
|
14
|
+
bun run lint # Lint 暂存文件
|
|
15
|
+
bun run lint:all # Lint 所有文件
|
|
16
|
+
bun run knip # 查找未使用的导出/依赖
|
|
17
|
+
bun test # 运行所有测试
|
|
18
|
+
bun test tests/foo.test.ts # 运行单个测试文件
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## API 端点
|
|
22
|
+
|
|
23
|
+
| 端点 | 用途 |
|
|
24
|
+
|------|------|
|
|
25
|
+
| `/v1/chat/completions` | OpenAI 兼容 chat |
|
|
26
|
+
| `/v1/messages` | Anthropic 兼容 messages |
|
|
27
|
+
| `/v1/messages/count_tokens` | Anthropic 兼容 token 计数 |
|
|
28
|
+
| `/v1/models` | 列出可用模型 |
|
|
29
|
+
| `/v1/embeddings` | 文本嵌入 |
|
|
30
|
+
| `/api/event_logging/batch` | Event logging(空操作) |
|
|
31
|
+
| `/usage` | Copilot 配额/用量统计 |
|
|
32
|
+
| `/health` | 健康检查 |
|
|
33
|
+
| `/token` | 当前 Copilot token 信息 |
|
|
34
|
+
| `/history` | 请求历史 Web UI(v1 和 v2) |
|
|
35
|
+
| `/history/ws` | WebSocket 实时历史更新 |
|
|
36
|
+
| `/history/api/entries` | 历史查询 API |
|
|
37
|
+
| `/history/api/sessions` | 会话列表 API |
|
|
38
|
+
| `/history/api/stats` | 统计 API |
|
|
39
|
+
| `/history/api/export` | 导出历史(JSON/CSV) |
|