Warning
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.
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.
- 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
copilot-api-demo.mp4
- Bun (>= 1.2.x)
- GitHub account with Copilot subscription (individual, business, or enterprise)
To install dependencies, run:
bun installBuild image
docker build -t copilot-api .Run the container
docker run -p 4141:4141 copilot-apiYou can run the project directly using npx:
npx copilot-api@latest startWith options:
npx copilot-api@latest start --port 8080For authentication only:
npx copilot-api@latest authCopilot API now uses a subcommand structure with two main commands:
start: Start the Copilot API server. This command will also handle authentication if needed.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-tokenoption, especially in non-interactive environments.
The following command line options are available for the start command:
| Option | Description | Default | Alias |
|---|---|---|---|
| --port | Port to listen on | 4141 | -p |
| --verbose | Enable verbose logging | false | -v |
| --account-type | Account type to use (individual, business, enterprise) | individual | -a |
| --manual | Enable manual request approval | false | none |
| --rate-limit | Rate limit in seconds between requests | none | -r |
| --wait | Wait instead of error when rate limit is hit | false | -w |
| --github-token | Provide GitHub token directly (must be generated using the auth subcommand) |
none | -g |
| --claude-code | Generate a command to launch Claude Code with Copilot API config | false | -c |
| Option | Description | Default | Alias |
|---|---|---|---|
| --verbose | Enable verbose logging | false | -v |
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.
These endpoints mimic the OpenAI API structure.
| Endpoint | Method | Description |
|---|---|---|
POST /v1/chat/completions |
POST |
Creates a model response for the given chat conversation. |
GET /v1/models |
GET |
Lists the currently available models. |
POST /v1/embeddings |
POST |
Creates an embedding vector representing the input text. |
These endpoints are designed to be compatible with the Anthropic Messages API.
| Endpoint | Method | Description |
|---|---|---|
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. |
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). |
Using with npx:
# Basic usage with start command
npx copilot-api@latest start
# Run on custom port with verbose logging
npx copilot-api@latest start --port 8080 --verbose
# Use with a business plan GitHub account
npx copilot-api@latest start --account-type business
# Use with an enterprise plan GitHub account
npx copilot-api@latest start --account-type enterprise
# Enable manual approval for each request
npx copilot-api@latest start --manual
# Set rate limit to 30 seconds between requests
npx copilot-api@latest start --rate-limit 30
# Wait instead of error when rate limit is hit
npx copilot-api@latest start --rate-limit 30 --wait
# Provide GitHub token directly
npx copilot-api@latest start --github-token ghp_YOUR_TOKEN_HERE
# Run only the auth flow
npx copilot-api@latest auth
# Run auth flow with verbose logging
npx copilot-api@latest auth --verboseAfter starting the server, you can access the Copilot Usage Viewer through your web browser:
- Start the server:
npx copilot-api@latest start - Open your browser and navigate to:
http://localhost:4141/public/usage.html - The page will automatically load your usage data when opened
- 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
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
This proxy can be used to power Claude Code, an experimental conversational AI assistant for developers from Anthropic.
There are two ways to configure Claude Code to use this proxy:
To get started, run the start command with the --claude-code flag:
npx copilot-api@latest start --claude-codeYou 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.
Paste and run this command in a new terminal to launch Claude Code.
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.
Here is an example .claude/settings.json file:
{
"env": {
"ANTHROPIC_BASE_URL": "http://localhost:4141",
"ANTHROPIC_AUTH_TOKEN": "dummy",
"ANTHROPIC_MODEL": "gpt-4.1",
"ANTHROPIC_SMALL_FAST_MODEL": "gpt-4.1"
}
}You can find more options here: Claude Code settings
You can also read more about IDE integration here: Add Claude Code to your IDE
The project can be run from source in several ways:
bun run devbun run start- To avoid hitting GitHub Copilot's rate limits, you can use the following flags:
--manual: Enables manual approval for each request, giving you full control over when requests are sent.--rate-limit <seconds>: Enforces a minimum time interval between requests. For example,copilot-api start --rate-limit 30will ensure there's at least a 30-second gap between requests.--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.
- If you have a GitHub business or enterprise plan account with Copilot, use the
--account-typeflag (e.g.,--account-type business). See the official documentation for more details.