copilot-gateway 0.10.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 +22 -0
- package/README.md +444 -0
- package/dist/config-CcK4TXHc.js +281 -0
- package/dist/config-CcK4TXHc.js.map +1 -0
- package/dist/main.js +583 -0
- package/dist/main.js.map +1 -0
- package/dist/server-CKh3Pzh6.js +2257 -0
- package/dist/server-CKh3Pzh6.js.map +1 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Erick Christian Purwanto
|
|
4
|
+
Copyright (c) 2026-Now Pengfei Ni
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
# Copilot Gateway
|
|
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.
|
|
5
|
+
|
|
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.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
**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.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Project Overview
|
|
27
|
+
|
|
28
|
+
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).
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
- **OpenAI & Anthropic Compatibility**: Exposes GitHub Copilot as an OpenAI-compatible (`/v1/responses`, `/v1/chat/completions`, `/v1/models`, `/v1/embeddings`) and Anthropic-compatible (`/v1/messages`) API, with additional no-prefix aliases for OpenAI-style routes.
|
|
33
|
+
- **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`).
|
|
34
|
+
- **Usage Dashboard**: A web-based dashboard to monitor your Copilot API usage, view quotas, and see detailed statistics.
|
|
35
|
+
- **Rate Limit Control**: Manage API usage with rate-limiting options (`--rate-limit`) and a waiting mechanism (`--wait`) to prevent errors from rapid requests on generation endpoints.
|
|
36
|
+
- **Manual Request Approval**: Manually approve or deny each generation request for fine-grained control over usage (`--manual`).
|
|
37
|
+
- **Token Visibility**: Option to display GitHub and Copilot tokens during authentication and refresh for debugging (`--show-token`).
|
|
38
|
+
- **Flexible Authentication**: Authenticate interactively or provide a GitHub token directly, suitable for CI/CD environments.
|
|
39
|
+
- **Support for Different Account Types**: Works with individual, business, and enterprise GitHub Copilot plans.
|
|
40
|
+
- **GitHub Enterprise Support**: Compatible with GitHub Enterprise Server and GitHub Enterprise Cloud installations.
|
|
41
|
+
|
|
42
|
+
## Prerequisites
|
|
43
|
+
|
|
44
|
+
- Bun (>= 1.2.x)
|
|
45
|
+
- GitHub account with Copilot subscription (individual, business, or enterprise)
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
To install dependencies, run:
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
bun install
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Using with Docker
|
|
56
|
+
|
|
57
|
+
Build image
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
docker build -t copilot-gateway .
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Run the container
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
# Create a directory on your host to persist the GitHub token and related data
|
|
67
|
+
mkdir -p ./copilot-data
|
|
68
|
+
|
|
69
|
+
# Run the container with a bind mount to persist the token
|
|
70
|
+
# This ensures your authentication survives container restarts
|
|
71
|
+
|
|
72
|
+
docker run -p 4141:4141 -v $(pwd)/copilot-data:/root/.local/share/copilot-gateway copilot-gateway
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
> **Note:**
|
|
76
|
+
> The GitHub token and related data will be stored in `copilot-data` on your host. This is mapped to `/root/.local/share/copilot-gateway` inside the container, ensuring persistence across restarts.
|
|
77
|
+
> If you don't provide `GH_TOKEN`, make sure the mapped directory already contains a valid token from a previous auth flow.
|
|
78
|
+
|
|
79
|
+
### Docker with Environment Variables
|
|
80
|
+
|
|
81
|
+
You can pass the GitHub token directly to the container using environment variables:
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
# Build image
|
|
85
|
+
docker build -t copilot-gateway .
|
|
86
|
+
|
|
87
|
+
# Run with GitHub token
|
|
88
|
+
docker run -p 4141:4141 -e GH_TOKEN=your_github_token_here copilot-gateway
|
|
89
|
+
|
|
90
|
+
# Run with additional options
|
|
91
|
+
docker run -p 4141:4141 -e GH_TOKEN=your_token copilot-gateway start --verbose --port 4141
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Docker Compose Example
|
|
95
|
+
|
|
96
|
+
```yaml
|
|
97
|
+
version: "3.8"
|
|
98
|
+
services:
|
|
99
|
+
copilot-gateway:
|
|
100
|
+
build: .
|
|
101
|
+
ports:
|
|
102
|
+
- "4141:4141"
|
|
103
|
+
environment:
|
|
104
|
+
- GH_TOKEN=your_github_token_here
|
|
105
|
+
restart: unless-stopped
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The Docker image includes:
|
|
109
|
+
|
|
110
|
+
- Multi-stage build for optimized image size
|
|
111
|
+
- Health check for container monitoring
|
|
112
|
+
- Pinned base image version for reproducible builds
|
|
113
|
+
|
|
114
|
+
## Using with npx
|
|
115
|
+
|
|
116
|
+
You can run the project directly using npx:
|
|
117
|
+
|
|
118
|
+
```sh
|
|
119
|
+
npx copilot-gateway@latest start
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
With options:
|
|
123
|
+
|
|
124
|
+
```sh
|
|
125
|
+
npx copilot-gateway@latest start --port 8080
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
For authentication only:
|
|
129
|
+
|
|
130
|
+
```sh
|
|
131
|
+
npx copilot-gateway@latest auth
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Command Structure
|
|
135
|
+
|
|
136
|
+
Copilot Gateway uses a subcommand structure with these main commands:
|
|
137
|
+
|
|
138
|
+
- `start`: Start the Copilot Gateway server. This command will also handle authentication if needed.
|
|
139
|
+
- `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.
|
|
140
|
+
- `check-usage`: Show your current GitHub Copilot usage and quota information directly in the terminal (no server required).
|
|
141
|
+
- `debug`: Display diagnostic information including version, runtime details, file paths, and authentication status. Useful for troubleshooting and support.
|
|
142
|
+
|
|
143
|
+
## Command Line Options
|
|
144
|
+
|
|
145
|
+
### Start Command Options
|
|
146
|
+
|
|
147
|
+
The following command line options are available for the `start` command:
|
|
148
|
+
|
|
149
|
+
| Option | Description | Default | Alias |
|
|
150
|
+
| -------------- | ----------------------------------------------------------------------------- | ---------- | ----- |
|
|
151
|
+
| --port | Port to listen on | 4141 | -p |
|
|
152
|
+
| --verbose | Enable verbose logging | false | -v |
|
|
153
|
+
| --account-type | Account type to use (individual, business, enterprise) | individual | -a |
|
|
154
|
+
| --manual | Enable manual request approval | false | none |
|
|
155
|
+
| --rate-limit | Rate limit in seconds between requests | none | -r |
|
|
156
|
+
| --wait | Wait instead of error when rate limit is hit | false | -w |
|
|
157
|
+
| --github-token | Provide GitHub token directly (must be generated using the `auth` subcommand) | none | -g |
|
|
158
|
+
| --claude-code | Generate a command to launch Claude Code with Copilot Gateway config | false | -c |
|
|
159
|
+
| --show-token | Show GitHub and Copilot tokens on fetch and refresh | false | none |
|
|
160
|
+
| --proxy-env | Initialize proxy from environment variables (Node.js runtime only) | false | none |
|
|
161
|
+
| --enterprise-url | GitHub Enterprise host to use (eg. https://ghe.example.com) | none | none |
|
|
162
|
+
| --api-key | API keys for authentication. Can be specified multiple times | none | none |
|
|
163
|
+
|
|
164
|
+
### Auth Command Options
|
|
165
|
+
|
|
166
|
+
| Option | Description | Default | Alias |
|
|
167
|
+
| ------------ | ------------------------- | ------- | ----- |
|
|
168
|
+
| --verbose | Enable verbose logging | false | -v |
|
|
169
|
+
| --show-token | Show GitHub token on auth | false | none |
|
|
170
|
+
| --enterprise-url | GitHub Enterprise host (eg. https://ghe.example.com) | none | none |
|
|
171
|
+
|
|
172
|
+
### Debug Command Options
|
|
173
|
+
|
|
174
|
+
| Option | Description | Default | Alias |
|
|
175
|
+
| ------ | ------------------------- | ------- | ----- |
|
|
176
|
+
| --json | Output debug info as JSON | false | none |
|
|
177
|
+
|
|
178
|
+
## Configuration (config.json)
|
|
179
|
+
|
|
180
|
+
- **Location:** `~/.local/share/copilot-gateway/config.json` (Linux/macOS) or `%USERPROFILE%\.local\share\copilot-gateway\config.json` (Windows).
|
|
181
|
+
- **Related files in the same directory:** `github_token`, `enterprise_url`, and `logs/`.
|
|
182
|
+
- **Default shape:**
|
|
183
|
+
```json
|
|
184
|
+
{
|
|
185
|
+
"extraPrompts": {
|
|
186
|
+
"gpt-5-mini": "<built-in exploration prompt>",
|
|
187
|
+
"gpt-5.1-codex-max": "<built-in exploration prompt>"
|
|
188
|
+
},
|
|
189
|
+
"smallModel": "gpt-5-mini",
|
|
190
|
+
"modelReasoningEfforts": {
|
|
191
|
+
"gpt-5-mini": "low"
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
- **extraPrompts:** Map of `model -> prompt` appended to the first system prompt when translating Anthropic-style requests to Copilot. Use this to inject guardrails or guidance per model. Missing default entries are auto-added without overwriting your custom prompts.
|
|
196
|
+
- **smallModel:** Fallback model used for tool-less warmup messages (e.g., Claude Code probe requests) to avoid spending premium requests; defaults to `gpt-5-mini`.
|
|
197
|
+
- **modelReasoningEfforts:** Per-model `reasoning.effort` sent to the Copilot Responses API. Allowed values are `none`, `minimal`, `low`, `medium`, `high`, and `xhigh`. If a model isn’t listed, `high` is used by default.
|
|
198
|
+
|
|
199
|
+
Edit this file to customize prompts or swap in your own fast model. Restart the server (or rerun the command) after changes so the cached config is refreshed.
|
|
200
|
+
|
|
201
|
+
## API Endpoints
|
|
202
|
+
|
|
203
|
+
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.
|
|
204
|
+
|
|
205
|
+
### OpenAI Compatible Endpoints
|
|
206
|
+
|
|
207
|
+
These endpoints mimic the OpenAI API structure.
|
|
208
|
+
|
|
209
|
+
| Endpoint | Method | Description |
|
|
210
|
+
| --------------------------- | ------ | ---------------------------------------------------------------- |
|
|
211
|
+
| `POST /v1/responses` | `POST` | Advanced OpenAI response interface for generating model responses. |
|
|
212
|
+
| `POST /v1/chat/completions` | `POST` | Creates a model response for the given chat conversation. |
|
|
213
|
+
| `GET /v1/models` | `GET` | Lists the currently available models. |
|
|
214
|
+
| `POST /v1/embeddings` | `POST` | Creates an embedding vector representing the input text. |
|
|
215
|
+
|
|
216
|
+
OpenAI-style compatibility aliases are also available without the `/v1` prefix:
|
|
217
|
+
|
|
218
|
+
- `POST /responses`
|
|
219
|
+
- `POST /chat/completions`
|
|
220
|
+
- `GET /models`
|
|
221
|
+
- `POST /embeddings`
|
|
222
|
+
|
|
223
|
+
### Anthropic Compatible Endpoints
|
|
224
|
+
|
|
225
|
+
These endpoints are designed to be compatible with the Anthropic Messages API.
|
|
226
|
+
|
|
227
|
+
| Endpoint | Method | Description |
|
|
228
|
+
| -------------------------------- | ------ | ------------------------------------------------------------ |
|
|
229
|
+
| `POST /v1/messages` | `POST` | Creates a model response for a given conversation. |
|
|
230
|
+
| `POST /v1/messages/count_tokens` | `POST` | Calculates the number of tokens for a given set of messages. |
|
|
231
|
+
| `POST /api/event_logging/batch` | `POST` | Anthropic telemetry log (ignore, just return 200) |
|
|
232
|
+
|
|
233
|
+
### Usage Monitoring Endpoints
|
|
234
|
+
|
|
235
|
+
New endpoints for monitoring your Copilot usage and quotas.
|
|
236
|
+
|
|
237
|
+
| Endpoint | Method | Description |
|
|
238
|
+
| ------------ | ------ | ------------------------------------------------------------ |
|
|
239
|
+
| `GET /usage` | `GET` | Get detailed Copilot usage statistics and quota information. |
|
|
240
|
+
| `GET /token` | `GET` | Get the current Copilot token being used by the API. |
|
|
241
|
+
|
|
242
|
+
## API Key Authentication
|
|
243
|
+
|
|
244
|
+
The proxy supports API key authentication to restrict access to the endpoints. When API keys are configured, all API endpoints require authentication.
|
|
245
|
+
|
|
246
|
+
### Authentication Methods
|
|
247
|
+
|
|
248
|
+
The proxy supports both OpenAI and Anthropic authentication formats:
|
|
249
|
+
|
|
250
|
+
- **OpenAI format**: Include the API key in the `Authorization` header with `Bearer` prefix:
|
|
251
|
+
```bash
|
|
252
|
+
curl -H "Authorization: Bearer your_api_key_here" http://localhost:4141/v1/models
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
- **Anthropic format**: Include the API key in the `x-api-key` header:
|
|
256
|
+
```bash
|
|
257
|
+
curl -H "x-api-key: your_api_key_here" http://localhost:4141/v1/messages
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Configuration
|
|
261
|
+
|
|
262
|
+
Use the `--api-key` flag to enable API key authentication. You can specify multiple keys for different clients:
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
# Single API key
|
|
266
|
+
npx copilot-gateway@latest start --api-key your_secret_key
|
|
267
|
+
|
|
268
|
+
# Multiple API keys
|
|
269
|
+
npx copilot-gateway@latest start --api-key key1 --api-key key2 --api-key key3
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
When API keys are configured:
|
|
273
|
+
- All API endpoints (`/v1/responses`, `/v1/chat/completions`, `/v1/models`, `/v1/embeddings`, `/v1/messages`, `/usage`, `/token`, and their non-`/v1` OpenAI aliases) require authentication
|
|
274
|
+
- Requests without valid API keys will receive a 401 Unauthorized response
|
|
275
|
+
- The root endpoint `/` remains accessible without authentication
|
|
276
|
+
|
|
277
|
+
## Example Usage
|
|
278
|
+
|
|
279
|
+
Using with npx:
|
|
280
|
+
|
|
281
|
+
```sh
|
|
282
|
+
# Basic usage with start command
|
|
283
|
+
npx copilot-gateway@latest start
|
|
284
|
+
|
|
285
|
+
# Run on custom port with verbose logging
|
|
286
|
+
npx copilot-gateway@latest start --port 8080 --verbose
|
|
287
|
+
|
|
288
|
+
# Use with a business plan GitHub account
|
|
289
|
+
npx copilot-gateway@latest start --account-type business
|
|
290
|
+
|
|
291
|
+
# Use with an enterprise plan GitHub account
|
|
292
|
+
npx copilot-gateway@latest start --account-type enterprise
|
|
293
|
+
|
|
294
|
+
# Enable manual approval for each request
|
|
295
|
+
npx copilot-gateway@latest start --manual
|
|
296
|
+
|
|
297
|
+
# Set rate limit to 30 seconds between requests
|
|
298
|
+
npx copilot-gateway@latest start --rate-limit 30
|
|
299
|
+
|
|
300
|
+
# Wait instead of error when rate limit is hit
|
|
301
|
+
npx copilot-gateway@latest start --rate-limit 30 --wait
|
|
302
|
+
|
|
303
|
+
# Provide GitHub token directly
|
|
304
|
+
npx copilot-gateway@latest start --github-token ghp_YOUR_TOKEN_HERE
|
|
305
|
+
|
|
306
|
+
# Enable API key authentication with a single key
|
|
307
|
+
npx copilot-gateway@latest start --api-key your_secret_key_here
|
|
308
|
+
|
|
309
|
+
# Enable API key authentication with multiple keys
|
|
310
|
+
npx copilot-gateway@latest start --api-key key1 --api-key key2 --api-key key3
|
|
311
|
+
|
|
312
|
+
# Run only the auth flow
|
|
313
|
+
npx copilot-gateway@latest auth
|
|
314
|
+
|
|
315
|
+
# Run auth flow with verbose logging
|
|
316
|
+
npx copilot-gateway@latest auth --verbose
|
|
317
|
+
|
|
318
|
+
# Show your Copilot usage/quota in the terminal (no server needed)
|
|
319
|
+
npx copilot-gateway@latest check-usage
|
|
320
|
+
|
|
321
|
+
# Display debug information for troubleshooting
|
|
322
|
+
npx copilot-gateway@latest debug
|
|
323
|
+
|
|
324
|
+
# Display debug information in JSON format
|
|
325
|
+
npx copilot-gateway@latest debug --json
|
|
326
|
+
|
|
327
|
+
# Initialize proxy from environment variables (HTTP_PROXY, HTTPS_PROXY, etc.)
|
|
328
|
+
# Note: this option is currently relevant for Node.js runtime paths; Bun generally uses its own proxy behavior.
|
|
329
|
+
npx copilot-gateway@latest start --proxy-env
|
|
330
|
+
|
|
331
|
+
# Use GitHub Enterprise / GitHub Enterprise Server
|
|
332
|
+
npx copilot-gateway@latest start --account-type enterprise --enterprise-url https://ghe.example.com
|
|
333
|
+
|
|
334
|
+
# Authenticate with GitHub Enterprise interactively (will prompt for enterprise host)
|
|
335
|
+
npx copilot-gateway@latest auth
|
|
336
|
+
|
|
337
|
+
# Authenticate with GitHub Enterprise using CLI flag (for scripting)
|
|
338
|
+
npx copilot-gateway@latest auth --enterprise-url ghe.example.com
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
## Using the Usage Viewer
|
|
342
|
+
|
|
343
|
+
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.
|
|
344
|
+
|
|
345
|
+
1. Start the server. For example, using npx:
|
|
346
|
+
```sh
|
|
347
|
+
npx copilot-gateway@latest start
|
|
348
|
+
```
|
|
349
|
+
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:
|
|
350
|
+
`https://feiskyer.github.io/copilot-gateway?endpoint=http://localhost:4141/usage`
|
|
351
|
+
- If you use the `start.bat` script on Windows, this page will open automatically.
|
|
352
|
+
|
|
353
|
+
The dashboard provides a user-friendly interface to view your Copilot usage data:
|
|
354
|
+
|
|
355
|
+
- **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.
|
|
356
|
+
- **Fetch Data**: Click the "Fetch" button to load or refresh the usage data. The dashboard will automatically fetch data on load.
|
|
357
|
+
- **Usage Quotas**: View a summary of your usage quotas for different services like Chat and Completions, displayed with progress bars for a quick overview.
|
|
358
|
+
- **Detailed Information**: See the full JSON response from the API for a detailed breakdown of all available usage statistics.
|
|
359
|
+
- **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:
|
|
360
|
+
`https://feiskyer.github.io/copilot-gateway?endpoint=http://your-api-server/usage`
|
|
361
|
+
|
|
362
|
+
## Using with Claude Code
|
|
363
|
+
|
|
364
|
+
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.
|
|
365
|
+
|
|
366
|
+
There are two ways to configure Claude Code to use this proxy:
|
|
367
|
+
|
|
368
|
+
### Interactive Setup with `--claude-code` flag
|
|
369
|
+
|
|
370
|
+
To get started, run the `start` command with the `--claude-code` flag:
|
|
371
|
+
|
|
372
|
+
```sh
|
|
373
|
+
npx copilot-gateway@latest start --claude-code
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
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.
|
|
377
|
+
|
|
378
|
+
Paste and run this command in a new terminal to launch Claude Code.
|
|
379
|
+
|
|
380
|
+
### Manual Configuration with `settings.json`
|
|
381
|
+
|
|
382
|
+
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.
|
|
383
|
+
|
|
384
|
+
Here is an example `.claude/settings.json` file:
|
|
385
|
+
|
|
386
|
+
```json
|
|
387
|
+
{
|
|
388
|
+
"env": {
|
|
389
|
+
"ANTHROPIC_BASE_URL": "http://localhost:4141",
|
|
390
|
+
"ANTHROPIC_AUTH_TOKEN": "dummy",
|
|
391
|
+
"ANTHROPIC_MODEL": "gpt-4.1",
|
|
392
|
+
"ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-4.1",
|
|
393
|
+
"ANTHROPIC_SMALL_FAST_MODEL": "gpt-4.1",
|
|
394
|
+
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-4.1",
|
|
395
|
+
"DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1",
|
|
396
|
+
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
|
|
397
|
+
},
|
|
398
|
+
"permissions": {
|
|
399
|
+
"deny": [
|
|
400
|
+
"WebSearch"
|
|
401
|
+
]
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
You can find more options here: [Claude Code settings](https://docs.anthropic.com/en/docs/claude-code/settings#environment-variables)
|
|
407
|
+
|
|
408
|
+
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)
|
|
409
|
+
|
|
410
|
+
## Running from Source
|
|
411
|
+
|
|
412
|
+
The project can be run from source in several ways:
|
|
413
|
+
|
|
414
|
+
### Development Mode
|
|
415
|
+
|
|
416
|
+
```sh
|
|
417
|
+
bun run dev
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
### Production Mode
|
|
421
|
+
|
|
422
|
+
```sh
|
|
423
|
+
bun run start
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
## Usage Tips
|
|
427
|
+
|
|
428
|
+
- To avoid hitting GitHub Copilot's rate limits, you can use the following flags:
|
|
429
|
+
- `--manual`: Enables manual approval for each request, giving you full control over when requests are sent.
|
|
430
|
+
- `--rate-limit <seconds>`: Enforces a minimum time interval between requests. For example, `copilot-gateway start --rate-limit 30` will ensure there's at least a 30-second gap between requests.
|
|
431
|
+
- `--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.
|
|
432
|
+
- 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.
|
|
433
|
+
- For GitHub Enterprise Server/Cloud users: Use `--enterprise-url` to specify your enterprise host (e.g., `--enterprise-url https://ghe.example.com`). The interactive auth command (`copilot-gateway auth`) will prompt you for your enterprise host if you don't provide it via the CLI flag.
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
## Credits
|
|
439
|
+
|
|
440
|
+
<detail>
|
|
441
|
+
This project is maintained as a fork/rebrand of the original
|
|
442
|
+
[`ericc-ch/copilot-api`](https://github.com/ericc-ch/copilot-api).
|
|
443
|
+
Huge thanks to [@ericc-ch](https://github.com/ericc-ch) and all contributors for the original implementation.
|
|
444
|
+
</detail>
|