@dianshuv/copilot-api 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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +131 -0
  3. package/dist/main.mjs +6778 -0
  4. package/package.json +61 -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,131 @@
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
+
28
+ ## Command Reference
29
+
30
+ | Command | Description |
31
+ |---------|-------------|
32
+ | `start` | Start the API server (handles auth if needed) |
33
+ | `auth` | Run GitHub authentication flow only |
34
+ | `logout` | Remove stored GitHub token |
35
+ | `check-usage` | Show Copilot usage and quota |
36
+ | `debug` | Display diagnostic information |
37
+ | `patch-claude` | Patch Claude Code's context window limit |
38
+
39
+ ### Start Command Options
40
+
41
+ | Option | Description | Default |
42
+ |--------|-------------|---------|
43
+ | `--port`, `-p` | Port to listen on | 4141 |
44
+ | `--host`, `-H` | Host/interface to bind to | (all interfaces) |
45
+ | `--verbose`, `-v` | Enable verbose logging | false |
46
+ | `--account-type`, `-a` | Account type (individual, business, enterprise) | individual |
47
+ | `--manual` | Manual request approval mode | false |
48
+ | `--no-rate-limit` | Disable adaptive rate limiting | false |
49
+ | `--retry-interval` | Seconds to wait before retrying after rate limit | 10 |
50
+ | `--request-interval` | Seconds between requests in rate-limited mode | 10 |
51
+ | `--recovery-timeout` | Minutes before attempting recovery | 10 |
52
+ | `--consecutive-successes` | Successes needed to exit rate-limited mode | 5 |
53
+ | `--github-token`, `-g` | Provide GitHub token directly | none |
54
+ | `--claude-code`, `-c` | Generate Claude Code launch command | false |
55
+ | `--show-token` | Show tokens on fetch/refresh | false |
56
+ | `--proxy-env` | Use proxy from environment | false |
57
+ | `--no-history` | Disable request history UI at `/history` | false |
58
+ | `--history-limit` | Max history entries in memory | 1000 |
59
+ | `--no-auto-truncate` | Disable auto-truncate when exceeding limits | false |
60
+ | `--compress-tool-results` | Compress old tool results before truncating | false |
61
+ | `--redirect-anthropic` | Force Anthropic through OpenAI translation | false |
62
+ | `--no-rewrite-anthropic-tools` | Don't rewrite server-side tools | false |
63
+
64
+ ### Patch-Claude Command Options
65
+
66
+ | Option | Description | Default |
67
+ |--------|-------------|---------|
68
+ | `--limit`, `-l` | Context window limit in tokens | 128000 |
69
+ | `--restore`, `-r` | Restore original 200k limit | false |
70
+ | `--path`, `-p` | Path to Claude Code cli.js | auto-detect |
71
+ | `--status`, `-s` | Show current patch status | false |
72
+
73
+ ## API Endpoints
74
+
75
+ ### OpenAI Compatible
76
+
77
+ | Endpoint | Method | Description |
78
+ |----------|--------|-------------|
79
+ | `/v1/chat/completions` | POST | Chat completions |
80
+ | `/v1/models` | GET | List available models |
81
+ | `/v1/embeddings` | POST | Text embeddings |
82
+ | `/v1/responses` | POST | Responses API (for codex models) |
83
+
84
+ ### Anthropic Compatible
85
+
86
+ | Endpoint | Method | Description |
87
+ |----------|--------|-------------|
88
+ | `/v1/messages` | POST | Messages API |
89
+ | `/v1/messages/count_tokens` | POST | Token counting |
90
+ | `/v1/event_logging/batch` | POST | Event logging (no-op) |
91
+
92
+ ### Utility
93
+
94
+ | Endpoint | Method | Description |
95
+ |----------|--------|-------------|
96
+ | `/` | GET | Server status |
97
+ | `/usage` | GET | Copilot usage stats |
98
+ | `/token` | GET | Current Copilot token |
99
+ | `/health` | GET | Health check |
100
+ | `/history` | GET | Request history Web UI (enabled by default) |
101
+ | `/history/api/*` | GET/DELETE | History API endpoints |
102
+
103
+ ## Using with Claude Code
104
+
105
+ Create `.claude/settings.json` in your project:
106
+
107
+ ```json
108
+ {
109
+ "env": {
110
+ "ANTHROPIC_BASE_URL": "http://localhost:4141",
111
+ "ANTHROPIC_AUTH_TOKEN": "dummy",
112
+ "ANTHROPIC_MODEL": "gpt-4.1",
113
+ "ANTHROPIC_SMALL_FAST_MODEL": "gpt-4.1",
114
+ "DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1",
115
+ "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
116
+ },
117
+ "permissions": {
118
+ "deny": ["WebSearch"]
119
+ }
120
+ }
121
+ ```
122
+
123
+ Or use the interactive setup:
124
+
125
+ ```sh
126
+ bun run start --claude-code
127
+ ```
128
+
129
+ ## Upstream Project
130
+
131
+ For the original project documentation, features, and updates, see: [ericc-ch/copilot-api](https://github.com/ericc-ch/copilot-api)