@daomar/copilot-api 0.7.1 → 0.8.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/README.md CHANGED
@@ -1,404 +1,140 @@
1
1
  # Copilot API Proxy
2
2
 
3
- > [!WARNING]
4
- > 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.
3
+ ## What is this?
5
4
 
6
- > [!WARNING]
7
- > **GitHub Security Notice:**
8
- > Excessive automated or scripted use of Copilot (including rapid or bulk requests, such as via automated tools) may trigger GitHub's abuse-detection systems.
9
- > You may receive a warning from GitHub Security, and further anomalous activity could result in temporary suspension of your Copilot access.
10
- >
11
- > GitHub prohibits use of their servers for excessive automated bulk activity or any activity that places undue burden on their infrastructure.
12
- >
13
- > Please review:
14
- >
15
- > - [GitHub Acceptable Use Policies](https://docs.github.com/site-policy/acceptable-use-policies/github-acceptable-use-policies#4-spam-and-inauthentic-activity-on-github)
16
- > - [GitHub Copilot Terms](https://docs.github.com/site-policy/github-terms/github-terms-for-additional-products-and-features#github-copilot)
17
- >
18
- > Use this proxy responsibly to avoid account restrictions.
5
+ A small local server that lets you use your **GitHub Copilot subscription** as the backend for AI coding tools like [Codex CLI](https://github.com/openai/codex) and [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview).
19
6
 
20
- [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/E1E519XS7W)
7
+ It exposes Copilot through OpenAI- and Anthropic-compatible APIs, so those tools talk to the proxy instead of paying for separate API keys. The proxy logs in once and refreshes your Copilot token automatically.
21
8
 
22
- ---
9
+ ## Requirements
23
10
 
24
- **Note:** If you are using [opencode](https://github.com/sst/opencode), you do not need this project. Opencode supports GitHub Copilot provider out of the box.
11
+ - A GitHub account with an active **Copilot** subscription (individual, business, or enterprise)
12
+ - [Node.js](https://nodejs.org) 20+ (so you can run `npx`)
25
13
 
26
- ---
14
+ ## Quick start
27
15
 
28
- ## Project Overview
29
-
30
- A reverse-engineered proxy for the GitHub Copilot API that exposes it as an OpenAI and Anthropic compatible service. This allows you to use GitHub Copilot with any tool that supports the OpenAI Chat Completions API or the Anthropic Messages API, including to power [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview).
31
-
32
- ## Features
33
-
34
- - **OpenAI & Anthropic Compatibility**: Exposes GitHub Copilot as an OpenAI-compatible (`/v1/chat/completions`, `/v1/models`, `/v1/embeddings`) and Anthropic-compatible (`/v1/messages`) API.
35
- - **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
- - **Usage Dashboard**: A web-based dashboard to monitor your Copilot API usage, view quotas, and see detailed statistics.
37
- - **Rate Limit Control**: Manage API usage with rate-limiting options (`--rate-limit`) and a waiting mechanism (`--wait`) to prevent errors from rapid requests.
38
- - **Manual Request Approval**: Manually approve or deny each API request for fine-grained control over usage (`--manual`).
39
- - **Token Visibility**: Option to display GitHub and Copilot tokens during authentication and refresh for debugging (`--show-token`).
40
- - **Flexible Authentication**: Authenticate interactively or provide a GitHub token directly, suitable for CI/CD environments.
41
- - **Support for Different Account Types**: Works with individual, business, and enterprise GitHub Copilot plans.
42
-
43
- ## Demo
44
-
45
- https://github.com/user-attachments/assets/7654b383-669d-4eb9-b23c-06d7aefee8c5
46
-
47
- ## Prerequisites
48
-
49
- - Bun (>= 1.2.x) [Bun Installation](https://bun.com/docs/installation#windows)
50
- - GitHub account with Copilot subscription (individual, business, or enterprise)
51
-
52
- ## Installation
53
-
54
- To install dependencies, run:
16
+ On any machine, run a single command:
55
17
 
56
18
  ```sh
57
- bun install
19
+ npx @daomar/copilot-api@latest setup
58
20
  ```
59
21
 
60
- ## Using with Docker
22
+ This will:
61
23
 
62
- Build image
24
+ 1. **Log you in** to GitHub (it shows a code to enter in your browser). You only do this once per machine.
25
+ 2. **Configure your tools** — it writes config for Codex CLI and Claude Code so they use the proxy. The config files are created even if those tools aren't installed yet, so they'll just work once you install them. Existing settings are kept (and backed up to `*.bak`).
26
+ 3. **Run it in the background, always** — it installs a service that starts on boot and restarts if it crashes, listening on `http://localhost:4141`:
27
+ - **Linux** — a `systemd` user service
28
+ - **Windows** — a Scheduled Task
63
29
 
64
- ```sh
65
- docker build -t copilot-api .
66
- ```
30
+ That's it. Open Codex or Claude Code and they'll use your Copilot subscription.
67
31
 
68
- Run the container
32
+ ### Setup questions
69
33
 
70
- ```sh
71
- # Create a directory on your host to persist the GitHub token and related data
72
- mkdir -p ./copilot-data
34
+ `setup` asks a few questions; press Enter to accept the defaults:
73
35
 
74
- # Run the container with a bind mount to persist the token
75
- # This ensures your authentication survives container restarts
36
+ - **Account type** `individual`, `business`, or `enterprise` (match your Copilot plan)
37
+ - **Port** defaults to `4141`
38
+ - **Which tools to configure** — Codex, Claude Code, or both
39
+ - **Which models to use**
40
+ - **Whether to install the background service**
76
41
 
77
- docker run -p 4141:4141 -v $(pwd)/copilot-data:/root/.local/share/copilot-api copilot-api
78
- ```
79
-
80
- > **Note:**
81
- > The GitHub token and related data will be stored in `copilot-data` on your host. This is mapped to `/root/.local/share/copilot-api` inside the container, ensuring persistence across restarts.
82
-
83
- ### Docker with Environment Variables
84
-
85
- You can pass the GitHub token directly to the container using environment variables:
42
+ To skip all questions and accept defaults:
86
43
 
87
44
  ```sh
88
- # Build with GitHub token
89
- docker build --build-arg GH_TOKEN=your_github_token_here -t copilot-api .
90
-
91
- # Run with GitHub token
92
- docker run -p 4141:4141 -e GH_TOKEN=your_github_token_here copilot-api
93
-
94
- # Run with additional options
95
- docker run -p 4141:4141 -e GH_TOKEN=your_token copilot-api start --verbose --port 4141
45
+ npx @daomar/copilot-api@latest setup --yes --account-type enterprise
96
46
  ```
97
47
 
98
- ### Docker Compose Example
99
-
100
- ```yaml
101
- version: "3.8"
102
- services:
103
- copilot-api:
104
- build: .
105
- ports:
106
- - "4141:4141"
107
- environment:
108
- - GH_TOKEN=your_github_token_here
109
- restart: unless-stopped
110
- ```
48
+ Re-running `setup` any time is safe — it updates your config and refreshes the service.
111
49
 
112
- The Docker image includes:
50
+ ## Using your tools
113
51
 
114
- - Multi-stage build for optimized image size
115
- - Non-root user for enhanced security
116
- - Health check for container monitoring
117
- - Pinned base image version for reproducible builds
52
+ After setup, just use the tools as normal:
118
53
 
119
- ## Using with npx
54
+ - **Codex CLI** — `codex` uses the `copilot` provider on port 4141. Note the GPT‑5.x codex models (e.g. `gpt-5.5`, `gpt-5.3-codex`) are served here too.
55
+ - **Claude Code** — `claude` is pointed at the proxy via `~/.claude/settings.json`.
120
56
 
121
- You can run the project directly using npx:
57
+ To change the model later, edit `~/.codex/config.toml` (Codex) or `~/.claude/settings.json` (Claude Code), or just re-run `setup`.
122
58
 
123
- ```sh
124
- npx copilot-api@latest start
125
- ```
59
+ ## Managing the background service
126
60
 
127
- With options:
61
+ **Linux (systemd):**
128
62
 
129
63
  ```sh
130
- npx copilot-api@latest start --port 8080
64
+ systemctl --user status copilot-api # check status
65
+ systemctl --user restart copilot-api # restart
66
+ systemctl --user stop copilot-api # stop
67
+ systemctl --user disable --now copilot-api # remove from startup
131
68
  ```
132
69
 
133
- For authentication only:
134
-
135
- ```sh
136
- npx copilot-api@latest auth
137
- ```
138
-
139
- ## Command Structure
140
-
141
- Copilot API now uses a subcommand structure with these main commands:
142
-
143
- - `start`: Start the Copilot API server. This command will also handle authentication if needed.
144
- - `auth`: Run GitHub authentication flow without starting the server. This is typically used if you need to generate a token for use with the `--github-token` option, especially in non-interactive environments.
145
- - `check-usage`: Show your current GitHub Copilot usage and quota information directly in the terminal (no server required).
146
- - `debug`: Display diagnostic information including version, runtime details, file paths, and authentication status. Useful for troubleshooting and support.
147
-
148
- ## Command Line Options
149
-
150
- ### Start Command Options
151
-
152
- The following command line options are available for the `start` command:
153
-
154
- | Option | Description | Default | Alias |
155
- | -------------- | ----------------------------------------------------------------------------- | ---------- | ----- |
156
- | --port | Port to listen on | 4141 | -p |
157
- | --verbose | Enable verbose logging | false | -v |
158
- | --account-type | Account type to use (individual, business, enterprise) | individual | -a |
159
- | --manual | Enable manual request approval | false | none |
160
- | --rate-limit | Rate limit in seconds between requests | none | -r |
161
- | --wait | Wait instead of error when rate limit is hit | false | -w |
162
- | --github-token | Provide GitHub token directly (must be generated using the `auth` subcommand) | none | -g |
163
- | --claude-code | Generate a command to launch Claude Code with Copilot API config | false | -c |
164
- | --show-token | Show GitHub and Copilot tokens on fetch and refresh | false | none |
165
- | --proxy-env | Initialize proxy from environment variables | false | none |
166
-
167
- ### Auth Command Options
168
-
169
- | Option | Description | Default | Alias |
170
- | ------------ | ------------------------- | ------- | ----- |
171
- | --verbose | Enable verbose logging | false | -v |
172
- | --show-token | Show GitHub token on auth | false | none |
173
-
174
- ### Debug Command Options
175
-
176
- | Option | Description | Default | Alias |
177
- | ------ | ------------------------- | ------- | ----- |
178
- | --json | Output debug info as JSON | false | none |
179
-
180
- ## API Endpoints
181
-
182
- The server exposes several endpoints to interact with the Copilot API. It provides OpenAI-compatible endpoints and now also includes support for Anthropic-compatible endpoints, allowing for greater flexibility with different tools and services.
183
-
184
- ### OpenAI Compatible Endpoints
185
-
186
- These endpoints mimic the OpenAI API structure.
187
-
188
- | Endpoint | Method | Description |
189
- | --------------------------- | ------ | --------------------------------------------------------- |
190
- | `POST /v1/chat/completions` | `POST` | Creates a model response for the given chat conversation. |
191
- | `GET /v1/models` | `GET` | Lists the currently available models. |
192
- | `POST /v1/embeddings` | `POST` | Creates an embedding vector representing the input text. |
193
-
194
- ### Anthropic Compatible Endpoints
195
-
196
- These endpoints are designed to be compatible with the Anthropic Messages API.
197
-
198
- | Endpoint | Method | Description |
199
- | -------------------------------- | ------ | ------------------------------------------------------------ |
200
- | `POST /v1/messages` | `POST` | Creates a model response for a given conversation. |
201
- | `POST /v1/messages/count_tokens` | `POST` | Calculates the number of tokens for a given set of messages. |
202
-
203
- ### Usage Monitoring Endpoints
204
-
205
- New endpoints for monitoring your Copilot usage and quotas.
206
-
207
- | Endpoint | Method | Description |
208
- | ------------ | ------ | ------------------------------------------------------------ |
209
- | `GET /usage` | `GET` | Get detailed Copilot usage statistics and quota information. |
210
- | `GET /token` | `GET` | Get the current Copilot token being used by the API. |
211
-
212
- ## Example Usage
213
-
214
- Using with npx:
70
+ **Windows (Task Scheduler):** manage the `CopilotAPI` task in the Task Scheduler app, or:
215
71
 
216
72
  ```sh
217
- # Basic usage with start command
218
- npx copilot-api@latest start
219
-
220
- # Run on custom port with verbose logging
221
- npx copilot-api@latest start --port 8080 --verbose
222
-
223
- # Use with a business plan GitHub account
224
- npx copilot-api@latest start --account-type business
225
-
226
- # Use with an enterprise plan GitHub account
227
- npx copilot-api@latest start --account-type enterprise
228
-
229
- # Enable manual approval for each request
230
- npx copilot-api@latest start --manual
231
-
232
- # Set rate limit to 30 seconds between requests
233
- npx copilot-api@latest start --rate-limit 30
234
-
235
- # Wait instead of error when rate limit is hit
236
- npx copilot-api@latest start --rate-limit 30 --wait
237
-
238
- # Provide GitHub token directly
239
- npx copilot-api@latest start --github-token ghp_YOUR_TOKEN_HERE
240
-
241
- # Run only the auth flow
242
- npx copilot-api@latest auth
243
-
244
- # Run auth flow with verbose logging
245
- npx copilot-api@latest auth --verbose
246
-
247
- # Show your Copilot usage/quota in the terminal (no server needed)
248
- npx copilot-api@latest check-usage
249
-
250
- # Display debug information for troubleshooting
251
- npx copilot-api@latest debug
252
-
253
- # Display debug information in JSON format
254
- npx copilot-api@latest debug --json
255
-
256
- # Initialize proxy from environment variables (HTTP_PROXY, HTTPS_PROXY, etc.)
257
- npx copilot-api@latest start --proxy-env
73
+ schtasks /Run /TN CopilotAPI # start now
74
+ schtasks /End /TN CopilotAPI # stop
75
+ schtasks /Delete /TN CopilotAPI /F # remove
258
76
  ```
259
77
 
260
- ## Using the Usage Viewer
261
-
262
- After starting the server, a URL to the Copilot Usage Dashboard will be displayed in your console. This dashboard is a web interface for monitoring your API usage.
263
-
264
- 1. Start the server. For example, using npx:
265
- ```sh
266
- npx copilot-api@latest start
267
- ```
268
- 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:
269
- `https://ericc-ch.github.io/copilot-api?endpoint=http://localhost:4141/usage`
270
- - If you use the `start.bat` script on Windows, this page will open automatically.
78
+ ## Other commands
271
79
 
272
- The dashboard provides a user-friendly interface to view your Copilot usage data:
80
+ You usually only need `setup`, but these are available via `npx @daomar/copilot-api@latest <command>`:
273
81
 
274
- - **API Endpoint URL**: The dashboard is pre-configured to fetch data from your local server endpoint via the URL query parameter. You can change this URL to point to any other compatible API endpoint.
275
- - **Fetch Data**: Click the "Fetch" button to load or refresh the usage data. The dashboard will automatically fetch data on load.
276
- - **Usage Quotas**: View a summary of your usage quotas for different services like Chat and Completions, displayed with progress bars for a quick overview.
277
- - **Detailed Information**: See the full JSON response from the API for a detailed breakdown of all available usage statistics.
278
- - **URL-based Configuration**: You can also specify the API endpoint directly in the URL using a query parameter. This is useful for bookmarks or sharing links. For example:
279
- `https://ericc-ch.github.io/copilot-api?endpoint=http://your-api-server/usage`
82
+ | Command | What it does |
83
+ | ------------- | ---------------------------------------------------------------------------- |
84
+ | `setup` | Guided login + configure tools + install the background service (recommended) |
85
+ | `start` | Run the proxy in the foreground (e.g. `start --port 4141`) |
86
+ | `config` | Just write/update the Codex and Claude Code config files (no service) |
87
+ | `auth` | Just log in to GitHub |
88
+ | `check-usage` | Show your Copilot usage and quota in the terminal |
89
+ | `debug` | Show diagnostic info for troubleshooting |
280
90
 
281
- ## Using with Claude Code
91
+ Useful `start` / `setup` options: `--port <n>` (default 4141), `--account-type <individual|business|enterprise>`, `--codex` / `--claude` (configure only one), `--no-service` (setup without the background service).
282
92
 
283
- This proxy can be used to power [Claude Code](https://docs.anthropic.com/en/claude-code), an experimental conversational AI assistant for developers from Anthropic.
93
+ ## Configure manually (optional)
284
94
 
285
- There are two ways to configure Claude Code to use this proxy:
95
+ If you'd rather not use `setup`, you can point the tools at a running proxy yourself.
286
96
 
287
- ### Interactive Setup with `--claude-code` flag
97
+ **Codex CLI** add to `~/.codex/config.toml`:
288
98
 
289
- To get started, run the `start` command with the `--claude-code` flag:
99
+ ```toml
100
+ model = "gpt-5.5"
101
+ model_provider = "copilot"
290
102
 
291
- ```sh
292
- npx copilot-api@latest start --claude-code
103
+ [model_providers.copilot]
104
+ name = "GitHub Copilot"
105
+ base_url = "http://localhost:4141/v1"
106
+ wire_api = "responses"
107
+ requires_openai_auth = false
108
+ http_headers = { "Openai-Intent" = "conversation-edits", "x-initiator" = "user" }
293
109
  ```
294
110
 
295
- 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.
296
-
297
- Paste and run this command in a new terminal to launch Claude Code.
298
-
299
- ### Manual Configuration with `settings.json`
300
-
301
- Alternatively, you can configure Claude Code by creating a `.claude/settings.json` file in your project's root directory. This file should contain the environment variables needed by Claude Code. This way you don't need to run the interactive setup every time.
302
-
303
- Here is an example `.claude/settings.json` file:
111
+ **Claude Code** add to `~/.claude/settings.json`:
304
112
 
305
113
  ```json
306
114
  {
307
115
  "env": {
308
116
  "ANTHROPIC_BASE_URL": "http://localhost:4141",
309
117
  "ANTHROPIC_AUTH_TOKEN": "dummy",
310
- "ANTHROPIC_MODEL": "gpt-4.1",
311
- "ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-4.1",
312
- "ANTHROPIC_SMALL_FAST_MODEL": "gpt-4.1",
313
- "ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-4.1",
314
- "DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1",
315
- "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
316
- },
317
- "permissions": {
318
- "deny": [
319
- "WebSearch"
320
- ]
118
+ "ANTHROPIC_MODEL": "claude-sonnet-4.5",
119
+ "ANTHROPIC_SMALL_FAST_MODEL": "claude-haiku-4.5"
321
120
  }
322
121
  }
323
122
  ```
324
123
 
325
- You can find more options here: [Claude Code settings](https://docs.anthropic.com/en/docs/claude-code/settings#environment-variables)
124
+ Then run `npx @daomar/copilot-api@latest start`.
326
125
 
327
- You can also read more about IDE integration here: [Add Claude Code to your IDE](https://docs.anthropic.com/en/docs/claude-code/ide-integrations)
126
+ ## Monitor your usage
328
127
 
329
- ## Running from Source
330
-
331
- The project can be run from source in several ways:
332
-
333
- ### Development Mode
334
-
335
- ```sh
336
- bun run dev
337
- ```
338
-
339
- ### Production Mode
340
-
341
- ```sh
342
- bun run start
343
- ```
344
-
345
- ### Run as a systemd user service (Linux)
346
-
347
- To keep the proxy running in the background and start it automatically on
348
- login, use the helper scripts (they auto-detect the repo path and the `bun`
349
- binary, so they work on any machine after `git clone`):
128
+ See your Copilot quota and usage anytime:
350
129
 
351
130
  ```sh
352
- # install + start the service (defaults: port 4141, account-type enterprise)
353
- ./scripts/install-service.sh
354
-
355
- # customize port / account type
356
- ./scripts/install-service.sh --port 8080 --account-type individual
357
- # or via env vars:
358
- PORT=8080 ACCOUNT_TYPE=individual ./scripts/install-service.sh
359
-
360
- # remove the service
361
- ./scripts/uninstall-service.sh
131
+ npx @daomar/copilot-api@latest check-usage
362
132
  ```
363
133
 
364
- The install script runs `bun install`, writes
365
- `~/.config/systemd/user/copilot-api.service`, enables + starts it, and turns on
366
- `linger` so it survives logout. On a fresh machine the first run needs a GitHub
367
- login — if the logs show a device-code prompt, run `bun run ./src/main.ts auth`
368
- once, then `systemctl --user restart copilot-api`.
369
-
370
- Handy commands:
371
-
372
- ```sh
373
- systemctl --user status copilot-api
374
- systemctl --user restart copilot-api
375
- journalctl --user -u copilot-api -f
376
- ```
377
-
378
- ## Usage Tips
379
-
380
- - To avoid hitting GitHub Copilot's rate limits, you can use the following flags:
381
- - `--manual`: Enables manual approval for each request, giving you full control over when requests are sent.
382
- - `--rate-limit <seconds>`: Enforces a minimum time interval between requests. For example, `copilot-api start --rate-limit 30` will ensure there's at least a 30-second gap between requests.
383
- - `--wait`: Use this with `--rate-limit`. It makes the server wait for the cooldown period to end instead of rejecting the request with an error. This is useful for clients that don't automatically retry on rate limit errors.
384
- - If you have a GitHub business or enterprise plan account with Copilot, use the `--account-type` flag (e.g., `--account-type business`). See the [official documentation](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) for more details.
385
-
386
- ## Trace
387
-
388
- ## Enable VS Code Claude Extension
389
-
390
- - Copy [settings.json](/settings.json) to `C:/Users/<user-name>/.claude/settings.json`
391
- (Create the file if it does not already exist.)
392
- - Restart the VS Code Claude extension
393
- (Close the current Claude chat and reopen it.)
134
+ Or open the web dashboard: <https://ericc-ch.github.io/copilot-api?endpoint=http://localhost:4141/usage> (while the proxy is running).
394
135
 
395
- ### Optional: Lightweight Windows Terminal startup
136
+ ## Troubleshooting
396
137
 
397
- - Copy the full path of `start-claude.cmd`.
398
- - Add it to Windows Terminal:
399
- 1. Open Windows Terminal.
400
- 2. Go to **Settings → Add a new profile → New empty profile**.
401
- 3. Enter a clear name and paste the script path into the **Command line** field.
402
- 4. Save the profile and open it from the dropdown list.
403
- 5. Configure `start-copilot-api.cmd` using the same steps.
404
- - You can now start the Copilot API and Claude scripts directly from Windows Terminal.
138
+ - **Run `npx @daomar/copilot-api@latest debug`** to see version, paths, and login status.
139
+ - **Port already in use?** Pick another with `setup --port 5151` (and re-run your tools' config, or just re-run `setup`).
140
+ - **Need to log in again?** Run `npx @daomar/copilot-api@latest auth`.