@dianshuv/copilot-api 0.1.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 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,170 @@
1
+ # Copilot API Proxy (Fork)
2
+
3
+ > [!NOTE]
4
+ > This is a fork of [@hsupu/copilot-api](https://www.npmjs.com/package/@hsupu/copilot-api), which itself 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
+ ## New Features (over @hsupu/copilot-api)
10
+
11
+ - **Responses API endpoint**: `/v1/responses` passthrough for codex models (e.g., `gpt-5.2-codex`, `gpt-5.3-codex`) used by tools like OpenCode. Includes stream ID synchronization for `@ai-sdk/openai` compatibility.
12
+ - **SubagentStart marker support**: Detects `__SUBAGENT_MARKER__` injected by Claude Code hooks to override `X-Initiator` header to `"agent"` for subagent requests, ensuring correct credit tier usage. Includes a ready-to-use Claude plugin (`claude-plugin/`).
13
+
14
+ ## Quick Start
15
+
16
+ ### Install from npm (Recommended)
17
+
18
+ ```sh
19
+ # Run directly with npx
20
+ npx @dianshuv/copilot-api start
21
+
22
+ # Or install globally
23
+ npm install -g @dianshuv/copilot-api
24
+ copilot-api start
25
+ ```
26
+
27
+ ### Install from GitHub
28
+
29
+ You can also install directly from GitHub (requires build step):
30
+
31
+ ```sh
32
+ npm install -g github:puxu-msft/copilot-api-js
33
+ copilot-api start
34
+ ```
35
+
36
+ ### Running from Source
37
+
38
+ ```sh
39
+ # Clone the repository
40
+ git clone https://github.com/puxu-msft/copilot-api-js.git
41
+ cd copilot-api-js
42
+
43
+ # Install dependencies
44
+ bun install
45
+
46
+ # Development mode (with hot reload)
47
+ bun run dev
48
+
49
+ # Production mode
50
+ bun run start
51
+
52
+ # Build for distribution
53
+ bun run build
54
+ ```
55
+
56
+ ### After Building
57
+
58
+ ```sh
59
+ # Run the built version locally
60
+ npx .
61
+
62
+ # Or link globally
63
+ bun link
64
+ copilot-api start
65
+ ```
66
+
67
+ ## Command Reference
68
+
69
+ | Command | Description |
70
+ |---------|-------------|
71
+ | `start` | Start the API server (handles auth if needed) |
72
+ | `auth` | Run GitHub authentication flow only |
73
+ | `logout` | Remove stored GitHub token |
74
+ | `check-usage` | Show Copilot usage and quota |
75
+ | `debug` | Display diagnostic information |
76
+ | `patch-claude` | Patch Claude Code's context window limit |
77
+
78
+ ### Start Command Options
79
+
80
+ | Option | Description | Default |
81
+ |--------|-------------|---------|
82
+ | `--port`, `-p` | Port to listen on | 4141 |
83
+ | `--host`, `-H` | Host/interface to bind to | (all interfaces) |
84
+ | `--verbose`, `-v` | Enable verbose logging | false |
85
+ | `--account-type`, `-a` | Account type (individual, business, enterprise) | individual |
86
+ | `--manual` | Manual request approval mode | false |
87
+ | `--no-rate-limit` | Disable adaptive rate limiting | false |
88
+ | `--retry-interval` | Seconds to wait before retrying after rate limit | 10 |
89
+ | `--request-interval` | Seconds between requests in rate-limited mode | 10 |
90
+ | `--recovery-timeout` | Minutes before attempting recovery | 10 |
91
+ | `--consecutive-successes` | Successes needed to exit rate-limited mode | 5 |
92
+ | `--github-token`, `-g` | Provide GitHub token directly | none |
93
+ | `--claude-code`, `-c` | Generate Claude Code launch command | false |
94
+ | `--show-token` | Show tokens on fetch/refresh | false |
95
+ | `--proxy-env` | Use proxy from environment | false |
96
+ | `--no-history` | Disable request history UI at `/history` | false |
97
+ | `--history-limit` | Max history entries in memory | 1000 |
98
+ | `--no-auto-truncate` | Disable auto-truncate when exceeding limits | false |
99
+ | `--compress-tool-results` | Compress old tool results before truncating | false |
100
+ | `--redirect-anthropic` | Force Anthropic through OpenAI translation | false |
101
+ | `--no-rewrite-anthropic-tools` | Don't rewrite server-side tools | false |
102
+
103
+ ### Patch-Claude Command Options
104
+
105
+ | Option | Description | Default |
106
+ |--------|-------------|---------|
107
+ | `--limit`, `-l` | Context window limit in tokens | 128000 |
108
+ | `--restore`, `-r` | Restore original 200k limit | false |
109
+ | `--path`, `-p` | Path to Claude Code cli.js | auto-detect |
110
+ | `--status`, `-s` | Show current patch status | false |
111
+
112
+ ## API Endpoints
113
+
114
+ ### OpenAI Compatible
115
+
116
+ | Endpoint | Method | Description |
117
+ |----------|--------|-------------|
118
+ | `/v1/chat/completions` | POST | Chat completions |
119
+ | `/v1/models` | GET | List available models |
120
+ | `/v1/embeddings` | POST | Text embeddings |
121
+ | `/v1/responses` | POST | Responses API (for codex models) |
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
+ | `/` | GET | Server status |
136
+ | `/usage` | GET | Copilot usage stats |
137
+ | `/token` | GET | Current Copilot token |
138
+ | `/health` | GET | Health check |
139
+ | `/history` | GET | Request history Web UI (enabled by default) |
140
+ | `/history/api/*` | GET/DELETE | History API endpoints |
141
+
142
+ ## Using with Claude Code
143
+
144
+ Create `.claude/settings.json` in your project:
145
+
146
+ ```json
147
+ {
148
+ "env": {
149
+ "ANTHROPIC_BASE_URL": "http://localhost:4141",
150
+ "ANTHROPIC_AUTH_TOKEN": "dummy",
151
+ "ANTHROPIC_MODEL": "gpt-4.1",
152
+ "ANTHROPIC_SMALL_FAST_MODEL": "gpt-4.1",
153
+ "DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1",
154
+ "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
155
+ },
156
+ "permissions": {
157
+ "deny": ["WebSearch"]
158
+ }
159
+ }
160
+ ```
161
+
162
+ Or use the interactive setup:
163
+
164
+ ```sh
165
+ bun run start --claude-code
166
+ ```
167
+
168
+ ## Upstream Project
169
+
170
+ For the original project documentation, features, and updates, see: [ericc-ch/copilot-api](https://github.com/ericc-ch/copilot-api)