Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

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

### New Features

- **Copilot Usage Viewer**: Integrated web interface to view your GitHub Copilot usage statistics and quota information
- **Token Display**: View the current Copilot token being used by the API
- **Real-time Monitoring**: Track your usage and remaining quotas in real-time

## Demo

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

### Usage Monitoring Endpoints

New endpoints for monitoring your Copilot usage and quotas.

| Endpoint | Method | Description |
| --------------------------- | ------ | --------------------------------------------------------- |
| `GET /usage` | `GET` | Get detailed Copilot usage statistics and quota information. |
| `GET /token` | `GET` | Get the current Copilot token being used by the API. |
| `GET /public/usage.html` | `GET` | Web interface for viewing usage statistics (accessible via browser). |

## Example Usage

Using with npx:
Expand Down Expand Up @@ -149,6 +165,34 @@ npx copilot-api@latest auth
npx copilot-api@latest auth --verbose
```

## Using the Usage Viewer

After starting the server, you can access the Copilot Usage Viewer through your web browser:

1. Start the server: `npx copilot-api@latest start`
2. Open your browser and navigate to: `http://localhost:4141/public/usage.html`
3. The page will automatically load your usage data when opened
4. Use the controls to:
- **Fetch Usage**: Manually refresh usage data
- **Show Current Token**: View the current Copilot token
- **Enable Auto Refresh**: Automatically refresh data every 30 seconds

### Auto Refresh Feature

The usage viewer includes an automatic refresh feature that:
- Updates usage data every 30 seconds when enabled
- Shows a countdown timer to the next refresh
- Displays the last update time
- Can be toggled on/off at any time
- Continues running in the background without interrupting your view

The usage viewer provides:
- Account information (plan type, access type, assigned date)
- Quota information (remaining usage, total quota, overage count)
- Real-time token display with automatic refresh
- Support for Chinese and English interfaces
- Auto-refresh functionality for continuous monitoring

## Using with Claude Code

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.
Expand Down
8 changes: 7 additions & 1 deletion src/lib/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ export const setupCopilotToken = async () => {
const { token, refresh_in } = await getCopilotToken()
state.copilotToken = token

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

const refreshInterval = (refresh_in - 60) * 1000
setInterval(async () => {
consola.start("Refreshing Copilot token")
try {
const { token } = await getCopilotToken()
state.copilotToken = token
consola.success("Copilot token refreshed")
consola.info(`New Token: ${token}`)
} catch (error) {
consola.error("Failed to refresh Copilot token:", error)
throw error
Expand Down
11 changes: 7 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ export async function runServer(options: RunServerOptions): Promise<void> {
consola.info("Using provided GitHub token")
} else {
await setupGitHubToken()
}

await setupCopilotToken()
await cacheModels()
} await setupCopilotToken()
Copy link

Copilot AI Jun 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider placing the 'await setupCopilotToken()' call on a new line for improved readability and to avoid any potential parsing ambiguities.

Suggested change
} await setupCopilotToken()
}
await setupCopilotToken()

Copilot uses AI. Check for mistakes.
await cacheModels() // Display token information prominently
consola.info("=".repeat(50))
consola.success("🚀 GitHub Copilot API has been successfully started!")
consola.info(`🔑 Current Copilot Token: ${state.copilotToken}`)
consola.info(`🌐 Usage Viewer: http://localhost:${options.port}/public/usage.html`)
consola.info("=".repeat(50))

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