Skip to content

Commit 636f90c

Browse files
authored
Merge pull request ericc-ch#48 from Asheblog/master
Add advanced request usage query to display remaining quota via the web version.
2 parents 1bd8afd + 8f419fb commit 636f90c

10 files changed

Lines changed: 803 additions & 8 deletions

File tree

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99

1010
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).
1111

12+
### New Features
13+
14+
- **Copilot Usage Viewer**: Integrated web interface to view your GitHub Copilot usage statistics and quota information
15+
- **Token Display**: View the current Copilot token being used by the API
16+
- **Real-time Monitoring**: Track your usage and remaining quotas in real-time
17+
1218
## Demo
1319

1420
https://github.com/user-attachments/assets/7654b383-669d-4eb9-b23c-06d7aefee8c5
@@ -113,6 +119,16 @@ These endpoints are designed to be compatible with the Anthropic Messages API.
113119
| `POST /v1/messages` | `POST` | Creates a model response for a given conversation. |
114120
| `POST /v1/messages/count_tokens` | `POST` | Calculates the number of tokens for a given set of messages. |
115121

122+
### Usage Monitoring Endpoints
123+
124+
New endpoints for monitoring your Copilot usage and quotas.
125+
126+
| Endpoint | Method | Description |
127+
| --------------------------- | ------ | --------------------------------------------------------- |
128+
| `GET /usage` | `GET` | Get detailed Copilot usage statistics and quota information. |
129+
| `GET /token` | `GET` | Get the current Copilot token being used by the API. |
130+
| `GET /public/usage.html` | `GET` | Web interface for viewing usage statistics (accessible via browser). |
131+
116132
## Example Usage
117133

118134
Using with npx:
@@ -149,6 +165,34 @@ npx copilot-api@latest auth
149165
npx copilot-api@latest auth --verbose
150166
```
151167

168+
## Using the Usage Viewer
169+
170+
After starting the server, you can access the Copilot Usage Viewer through your web browser:
171+
172+
1. Start the server: `npx copilot-api@latest start`
173+
2. Open your browser and navigate to: `http://localhost:4141/public/usage.html`
174+
3. The page will automatically load your usage data when opened
175+
4. Use the controls to:
176+
- **Fetch Usage**: Manually refresh usage data
177+
- **Show Current Token**: View the current Copilot token
178+
- **Enable Auto Refresh**: Automatically refresh data every 30 seconds
179+
180+
### Auto Refresh Feature
181+
182+
The usage viewer includes an automatic refresh feature that:
183+
- Updates usage data every 30 seconds when enabled
184+
- Shows a countdown timer to the next refresh
185+
- Displays the last update time
186+
- Can be toggled on/off at any time
187+
- Continues running in the background without interrupting your view
188+
189+
The usage viewer provides:
190+
- Account information (plan type, access type, assigned date)
191+
- Quota information (remaining usage, total quota, overage count)
192+
- Real-time token display with automatic refresh
193+
- Support for Chinese and English interfaces
194+
- Auto-refresh functionality for continuous monitoring
195+
152196
## Using with Claude Code
153197

154198
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.

src/lib/token.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@ export const setupCopilotToken = async () => {
1919
const { token, refresh_in } = await getCopilotToken()
2020
state.copilotToken = token
2121

22-
const refreshInterval = (refresh_in - 60) * 1000
22+
// Display the Copilot token to the screen
23+
consola.success("GitHub Copilot Token fetched successfully!")
24+
consola.info(`Token: ${token}`)
25+
consola.info(`Token validity: ${Math.floor(refresh_in / 60)} minutes`)
2326

27+
const refreshInterval = (refresh_in - 60) * 1000
2428
setInterval(async () => {
2529
consola.start("Refreshing Copilot token")
2630
try {
2731
const { token } = await getCopilotToken()
2832
state.copilotToken = token
33+
consola.success("Copilot token refreshed")
34+
consola.info(`New Token: ${token}`)
2935
} catch (error) {
3036
consola.error("Failed to refresh Copilot token:", error)
3137
throw error

src/main.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ export async function runServer(options: RunServerOptions): Promise<void> {
4949
consola.info("Using provided GitHub token")
5050
} else {
5151
await setupGitHubToken()
52-
}
53-
54-
await setupCopilotToken()
55-
await cacheModels()
52+
} await setupCopilotToken()
53+
await cacheModels() // Display token information prominently
54+
consola.info("=".repeat(50))
55+
consola.success("🚀 GitHub Copilot API has been successfully started!")
56+
consola.info(`🔑 Current Copilot Token: ${state.copilotToken}`)
57+
consola.info(`🌐 Usage Viewer: http://localhost:${options.port}/public/usage.html`)
58+
consola.info("=".repeat(50))
5659

5760
consola.info(
5861
`Available models: \n${state.models?.data.map((model) => `- ${model.id}`).join("\n")}`,

0 commit comments

Comments
 (0)