@hsupu/copilot-api 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +168 -0
- package/dist/main.js +3271 -0
- package/dist/main.js.map +1 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Erick Christian Purwanto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# Copilot API Proxy (Fork)
|
|
2
|
+
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This is a fork of [ericc-ch/copilot-api](https://github.com/ericc-ch/copilot-api) with additional improvements and bug fixes.
|
|
5
|
+
|
|
6
|
+
> [!WARNING]
|
|
7
|
+
> 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.
|
|
8
|
+
|
|
9
|
+
## Fork Improvements
|
|
10
|
+
|
|
11
|
+
This fork includes the following enhancements over the upstream project:
|
|
12
|
+
|
|
13
|
+
### New Features
|
|
14
|
+
|
|
15
|
+
- **`--host` option**: Bind the server to a specific network interface (e.g., `--host 0.0.0.0` for all interfaces, `--host 127.0.0.1` for localhost only)
|
|
16
|
+
- **Queue-based rate limiting**: Requests are queued and processed sequentially with configurable delays, instead of being rejected when rate limited
|
|
17
|
+
- **`/v1/event_logging/batch` endpoint**: Compatibility endpoint for Anthropic SDK's event logging (returns OK without processing)
|
|
18
|
+
- **`logout` command**: Remove stored GitHub token with `copilot-api logout`
|
|
19
|
+
- **Tool name length handling**: Automatically truncates long tool names (>64 chars) to comply with OpenAI's limit, with hash-based suffix to avoid collisions. Original names are restored in responses.
|
|
20
|
+
- **Request History UI**: Optional built-in Web UI (`--history`) to view, search, filter, and export all API requests/responses. Access at `/history` when enabled.
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
- **Fixed missing `model` field in streaming**: The first streaming chunk from Copilot API sometimes has an empty `choices` array but contains the model name. We now store this for use in subsequent events.
|
|
25
|
+
- **Auto-fix message sequence errors**: When tool calls are interrupted (e.g., by user cancel), the API now automatically adds placeholder `tool_result` blocks to maintain valid message sequences
|
|
26
|
+
- **Fixed `bunx` symlink issue**: Changed pre-commit hook to use `bun x` instead of `bunx` for better compatibility
|
|
27
|
+
|
|
28
|
+
### Documentation
|
|
29
|
+
|
|
30
|
+
- Added [CLAUDE.md](./CLAUDE.md) with project architecture documentation
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
### Install from npm (Recommended)
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
# Run directly with npx
|
|
38
|
+
npx @hsupu/copilot-api start
|
|
39
|
+
|
|
40
|
+
# Or install globally
|
|
41
|
+
npm install -g @hsupu/copilot-api
|
|
42
|
+
copilot-api start
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Install from GitHub
|
|
46
|
+
|
|
47
|
+
You can also install directly from GitHub (requires build step):
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
npm install -g github:puxu-msft/copilot-api-js
|
|
51
|
+
copilot-api start
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Running from Source
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
# Clone the repository
|
|
58
|
+
git clone https://github.com/puxu-msft/copilot-api-js.git
|
|
59
|
+
cd copilot-api-js
|
|
60
|
+
|
|
61
|
+
# Install dependencies
|
|
62
|
+
bun install
|
|
63
|
+
|
|
64
|
+
# Development mode (with hot reload)
|
|
65
|
+
bun run dev
|
|
66
|
+
|
|
67
|
+
# Production mode
|
|
68
|
+
bun run start
|
|
69
|
+
|
|
70
|
+
# Build for distribution
|
|
71
|
+
bun run build
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### After Building
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
# Run the built version locally
|
|
78
|
+
npx .
|
|
79
|
+
|
|
80
|
+
# Or link globally
|
|
81
|
+
bun link
|
|
82
|
+
copilot-api start
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Command Reference
|
|
86
|
+
|
|
87
|
+
| Command | Description |
|
|
88
|
+
|---------|-------------|
|
|
89
|
+
| `start` | Start the API server (handles auth if needed) |
|
|
90
|
+
| `auth` | Run GitHub authentication flow only |
|
|
91
|
+
| `logout` | Remove stored GitHub token |
|
|
92
|
+
| `check-usage` | Show Copilot usage and quota |
|
|
93
|
+
| `debug` | Display diagnostic information |
|
|
94
|
+
|
|
95
|
+
### Start Command Options
|
|
96
|
+
|
|
97
|
+
| Option | Description | Default |
|
|
98
|
+
|--------|-------------|---------|
|
|
99
|
+
| `--port`, `-p` | Port to listen on | 4141 |
|
|
100
|
+
| `--host` | Host/interface to bind to | (all interfaces) |
|
|
101
|
+
| `--verbose`, `-v` | Enable verbose logging | false |
|
|
102
|
+
| `--account-type`, `-a` | Account type (individual, business, enterprise) | individual |
|
|
103
|
+
| `--rate-limit`, `-r` | Seconds between requests (uses queue) | none |
|
|
104
|
+
| `--wait`, `-w` | Wait in queue instead of rejecting | false |
|
|
105
|
+
| `--github-token`, `-g` | Provide GitHub token directly | none |
|
|
106
|
+
| `--claude-code`, `-c` | Generate Claude Code launch command | false |
|
|
107
|
+
| `--show-token` | Show tokens on fetch/refresh | false |
|
|
108
|
+
| `--manual` | Manual request approval mode | false |
|
|
109
|
+
| `--proxy-env` | Use proxy from environment | false |
|
|
110
|
+
| `--history` | Enable request history UI at `/history` | false |
|
|
111
|
+
| `--history-limit` | Max history entries in memory | 1000 |
|
|
112
|
+
|
|
113
|
+
## API Endpoints
|
|
114
|
+
|
|
115
|
+
### OpenAI Compatible
|
|
116
|
+
|
|
117
|
+
| Endpoint | Method | Description |
|
|
118
|
+
|----------|--------|-------------|
|
|
119
|
+
| `/v1/chat/completions` | POST | Chat completions |
|
|
120
|
+
| `/v1/models` | GET | List available models |
|
|
121
|
+
| `/v1/embeddings` | POST | Text embeddings |
|
|
122
|
+
|
|
123
|
+
### Anthropic Compatible
|
|
124
|
+
|
|
125
|
+
| Endpoint | Method | Description |
|
|
126
|
+
|----------|--------|-------------|
|
|
127
|
+
| `/v1/messages` | POST | Messages API |
|
|
128
|
+
| `/v1/messages/count_tokens` | POST | Token counting |
|
|
129
|
+
| `/v1/event_logging/batch` | POST | Event logging (no-op) |
|
|
130
|
+
|
|
131
|
+
### Utility
|
|
132
|
+
|
|
133
|
+
| Endpoint | Method | Description |
|
|
134
|
+
|----------|--------|-------------|
|
|
135
|
+
| `/usage` | GET | Copilot usage stats |
|
|
136
|
+
| `/token` | GET | Current Copilot token |
|
|
137
|
+
| `/history` | GET | Request history Web UI (requires `--history`) |
|
|
138
|
+
| `/history/api/*` | GET/DELETE | History API endpoints |
|
|
139
|
+
|
|
140
|
+
## Using with Claude Code
|
|
141
|
+
|
|
142
|
+
Create `.claude/settings.json` in your project:
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"env": {
|
|
147
|
+
"ANTHROPIC_BASE_URL": "http://localhost:4141",
|
|
148
|
+
"ANTHROPIC_AUTH_TOKEN": "dummy",
|
|
149
|
+
"ANTHROPIC_MODEL": "gpt-4.1",
|
|
150
|
+
"ANTHROPIC_SMALL_FAST_MODEL": "gpt-4.1",
|
|
151
|
+
"DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1",
|
|
152
|
+
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
|
|
153
|
+
},
|
|
154
|
+
"permissions": {
|
|
155
|
+
"deny": ["WebSearch"]
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Or use the interactive setup:
|
|
161
|
+
|
|
162
|
+
```sh
|
|
163
|
+
bun run start --claude-code
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Upstream Project
|
|
167
|
+
|
|
168
|
+
For the original project documentation, features, and updates, see: [ericc-ch/copilot-api](https://github.com/ericc-ch/copilot-api)
|