Local GitHub Copilot API proxy โ use GPT-4o, Claude, Gemini via OpenAI/Anthropic compatible APIs
Project description
๐ CopilotX
Local & Remote GitHub Copilot API proxy โ use GPT-4o, Claude, Gemini and more via OpenAI/Anthropic compatible APIs.
Turn your GitHub Copilot subscription into an AI API server. Use any model available through Copilot with any tool that supports OpenAI or Anthropic SDKs โ locally or on a remote VM.
โจ Features
- ๐ GitHub OAuth โ One-command login via Device Flow, or use existing token
- ๐ Auto Token Refresh โ Copilot JWT refreshed transparently before expiry
- ๐ Dual API Format โ OpenAI
/v1/chat/completions+ Anthropic/v1/messages - ๐ SSE Streaming โ Real-time streaming responses for both formats
- ๐ Model Discovery โ Auto-fetch available models from Copilot
- โก Zero Config โ
pip installโauth loginโserveโ done - ๐ Remote Deploy โ Serve on
0.0.0.0with API key protection, deploy behind Caddy for auto-HTTPS
๐ Quick Start
1. Install
pip install copilotx
# or
uv pip install copilotx
2. Authenticate
# Option A: OAuth Device Flow (recommended)
copilotx auth login
# โ Opens browser for GitHub authorization
# Option B: Use existing GitHub token
copilotx auth login --token ghp_xxxxx
# or
export GITHUB_TOKEN=ghp_xxxxx && copilotx auth login
3. Start Server
copilotx serve
Output:
๐ CopilotX v2.0.0
โ
Copilot Token valid (28m remaining, auto-refresh)
๐ Local mode (localhost only)
๐ Models: gpt-4o, gpt-4o-mini, o3-mini, claude-sonnet-4, gemini-2.0-flash
๐ OpenAI API: http://127.0.0.1:24680/v1/chat/completions
๐ Anthropic API: http://127.0.0.1:24680/v1/messages
๐ Models: http://127.0.0.1:24680/v1/models
Press Ctrl+C to stop
4. Use It
Python (OpenAI SDK):
from openai import OpenAI
client = OpenAI(base_url="http://localhost:24680/v1", api_key="copilotx")
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}],
stream=True,
)
for chunk in response:
print(chunk.choices[0].delta.content or "", end="")
Python (Anthropic SDK):
from anthropic import Anthropic
client = Anthropic(base_url="http://localhost:24680", api_key="copilotx")
message = client.messages.create(
model="claude-sonnet-4",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}],
)
print(message.content[0].text)
Claude Code:
# Set environment variables
export ANTHROPIC_BASE_URL=http://localhost:24680
export ANTHROPIC_API_KEY=copilotx
claude
Codex:
export OPENAI_BASE_URL=http://localhost:24680/v1
export OPENAI_API_KEY=copilotx
codex
cURL:
curl http://localhost:24680/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello!"}]
}'
๐ก API Endpoints
| Endpoint | Method | Description |
|---|---|---|
/v1/chat/completions |
POST | OpenAI-compatible chat completions |
/v1/messages |
POST | Anthropic-compatible messages |
/v1/models |
GET | List available models |
/health |
GET | Server health + token status |
๐ง CLI Commands
copilotx auth login # OAuth Device Flow login
copilotx auth login --token XXX # Quick login with existing token
copilotx auth status # Show auth status
copilotx auth logout # Clear credentials
copilotx models # List available models
copilotx serve # Start server (default: 127.0.0.1:24680)
copilotx serve --host 0.0.0.0 # Remote mode (bind all interfaces)
copilotx serve --port 9090 # Custom port (strict โ fails if in use)
copilotx --version # Show version
๐๏ธ How It Works
Your Tool (Claude Code / Codex / Python script)
โ
โ OpenAI or Anthropic format
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CopilotX (localhost:24680) โ
โ โ
โ โข Anthropic โ OpenAI โ
โ format translation โ
โ โข Token auto-refresh โ
โ โข SSE stream forwarding โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ
โ OpenAI format
โผ
api.githubcopilot.com/chat/completions
(GPT-4o, Claude, Gemini, o3-mini, ...)
CopilotX uses your GitHub Copilot subscription to access models. The Copilot backend natively speaks OpenAI format, so OpenAI requests are direct passthrough. Anthropic requests are translated on-the-fly.
๐ Port Discovery
When CopilotX starts, it writes ~/.copilotx/server.json:
{
"host": "127.0.0.1",
"port": 24680,
"pid": 12345,
"started_at": "2026-02-09T12:00:00+00:00",
"base_url": "http://127.0.0.1:24680"
}
Other scripts can read this to discover the actual port:
# Bash/Zsh
PORT=$(python -c "import json; print(json.load(open('$HOME/.copilotx/server.json'))['port'])")
curl http://localhost:$PORT/health
# PowerShell
$info = Get-Content "$HOME\.copilotx\server.json" | ConvertFrom-Json
curl http://localhost:$($info.port)/health
The file is automatically cleaned up when the server stops.
๐ Remote Deployment
Deploy CopilotX on a cloud VM to access your Copilot models from anywhere.
Quick Setup (Azure VM / any Linux server)
# 1. Install
pip install copilotx
# 2. Authenticate
copilotx auth login
# 3. Set API key for remote protection
export COPILOTX_API_KEY=$(openssl rand -hex 32)
echo "Save this key: $COPILOTX_API_KEY"
# 4. Start in remote mode
copilotx serve --host 0.0.0.0
Production Setup with Nginx + systemd
For production deployments with HTTPS, we recommend using Nginx as the reverse proxy.
1. Install and configure systemd service:
# Copy and customize the systemd service template
sudo cp deploy/copilotx.service /etc/systemd/system/
# Create environment file with your API key
mkdir -p ~/.copilotx
echo "COPILOTX_API_KEY=$(openssl rand -hex 32)" > ~/.copilotx/.env
# Enable and start service
sudo systemctl daemon-reload
sudo systemctl enable --now copilotx
2. Configure Nginx reverse proxy:
# Copy the Nginx config template
sudo cp deploy/nginx-copilotx.conf /etc/nginx/sites-available/copilotx
sudo ln -s /etc/nginx/sites-available/copilotx /etc/nginx/sites-enabled/
# Get SSL certificate with Let's Encrypt
sudo certbot --nginx -d your-domain.com
# Reload Nginx
sudo nginx -t && sudo systemctl reload nginx
The deploy/ directory includes ready-to-use templates:
copilotx.serviceโ systemd service unit (generic)copilotx-azureuser.serviceโ systemd service unit (Azure VM with virtualenv)nginx-copilotx.confโ Nginx reverse proxy with SSL, rate limiting, and SSE supportnginx-copilotx-http.confโ Temporary HTTP-only config for initial Let's Encrypt setupCaddyfileโ Alternative Caddy config (simpler setup with auto-HTTPS).env.exampleโ Environment variables template
Security Model
| Mode | Host | API Key | Behavior |
|---|---|---|---|
| Local | 127.0.0.1 (default) |
Not needed | Fully open, localhost only |
| Remote (protected) | 0.0.0.0 |
COPILOTX_API_KEY set |
Localhost exempt, remote needs Bearer token |
| Remote (open) | 0.0.0.0 |
Not set | โ ๏ธ Warning shown, fully open |
Accessing from remote:
# Use Bearer token
curl https://your-domain.com/v1/models \
-H "Authorization: Bearer YOUR_API_KEY"
# Or x-api-key header
curl https://your-domain.com/v1/models \
-H "x-api-key: YOUR_API_KEY"
With OpenAI SDK:
client = OpenAI(
base_url="https://your-domain.com/v1",
api_key="YOUR_COPILOTX_API_KEY",
)
๐ Version Roadmap
| Version | Codename | Features |
|---|---|---|
| v1.0.0 | Local | OAuth, dual API, streaming, model discovery |
| v2.0.0 | Remote | API key auth, remote deploy, Nginx/Caddy + systemd templates |
| v3.0.0 | Multi-User | Token pool, user database, OpenRouter mode |
โ ๏ธ Disclaimer
This tool is for personal local use only. Please comply with GitHub Copilot Terms of Service. The author is not responsible for any account restrictions resulting from misuse.
๐ License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file copilotx-2.0.1.tar.gz.
File metadata
- Download URL: copilotx-2.0.1.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8593d3879e43f6b75f5e7cd6cad660f06cdd5952af36886705b26b7d4e9a262
|
|
| MD5 |
ddfbb8064b5deb1745b582b238c97d7c
|
|
| BLAKE2b-256 |
cdf20d6341cf6458d7963805f1856d35d06fc0c9ef3760f36333a07a67c44a12
|
File details
Details for the file copilotx-2.0.1-py3-none-any.whl.
File metadata
- Download URL: copilotx-2.0.1-py3-none-any.whl
- Upload date:
- Size: 23.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9dcdb57682966c59d5bda3029370b90df383c7fe171105327f492ba1a09ef982
|
|
| MD5 |
1895b820fbe272445503e0bae3b8e1cf
|
|
| BLAKE2b-256 |
7fb101ee0378a624067eb7bc17b4eec759042a892fb9c9cda15696101c02f690
|