Add GitHub Copilot API proxy integration to LLM Gateway: * Implement copilot-bridge service: - HTTP wrapper managing copilot-api (GitHub Copilot API proxy) - OpenAI-compatible /v1/chat/completions endpoint (port 3252) - Graceful startup and SIGTERM shutdown handling - Health check endpoint with service diagnostics * Register copilot-bridge in provider fallback chain: - Position: After OpenAI, before free LLM APIs (tier 4) - Rate limit: 60 requests/min (GitHub Copilot API limit) - Models: gpt-4 (reasoning), gpt-3.5-turbo (medium) - Authentication: GitHub Copilot subscription (internal to copilot-api) * Update PM2 ecosystem configuration: - Add copilot-bridge service definition (port 3252) - Configure COPILOT_BRIDGE_URL in gateway environment - Add copilot to LLM_PROVIDERS list * Enhance deployment automation: - Update ensure-bridges.sh with copilot-bridge deployment - Copy service files from repo to /opt/copilot-bridge - Run npm install for copilot-api dependency * Comprehensive documentation: - Expand DEPLOYMENT-BRIDGES.md with copilot-bridge section - Prerequisites: Node.js 20+, GitHub Copilot subscription - Authentication workflow: npm run auth with GitHub OAuth - Troubleshooting: subscription verification, auth cache reset Provider chain now supports: 1. Ollama (local, free) 2. claude-bridge (Claude subscription) 3. openai-bridge (OpenAI subscription) 4. copilot-bridge (GitHub Copilot subscription) ← NEW 5. Free APIs: Cerebras, Groq, Mistral, NVIDIA, Cloudflare Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
GitHub Copilot Bridge
Exposes GitHub Copilot as an OpenAI-compatible API endpoint for LLM Gateway integration.
Architecture
LLM Gateway
↓
copilot-bridge (port 3252)
↓
GitHub Copilot API Proxy (copilot-api, port 4141)
↓
GitHub Copilot API (requires GitHub subscription)
Prerequisites
- Node.js 20+ installed
- GitHub Account with GitHub Copilot subscription (not free)
- GitHub CLI (for initial authentication)
- PM2 for process management (optional, but recommended)
Installation
1. Install Dependencies
cd copilot-bridge
npm install
This installs copilot-api as a dependency.
2. Authenticate with GitHub Copilot
# Method 1: Using npm script
npm run auth
# Method 2: Direct npx command
npx copilot-api@latest auth
This opens a browser window for GitHub OAuth authentication. Follow the prompts:
- Click the authorization link
- Approve access to GitHub Copilot API
- The CLI will save your GitHub and Copilot tokens locally
Important: Authentication is per-machine and persists in ~/.copilot-api/ or similar directory.
3. Verify Authentication
# Check GitHub Copilot subscription and usage
npm run debug
# Or use the wrapper to verify both are working
node server.js
Configuration
Environment Variables
| Variable | Default | Notes |
|---|---|---|
COPILOT_BRIDGE_PORT |
3252 | Port for this wrapper |
COPILOT_API_INTERNAL_PORT |
4141 | Internal port for copilot-api |
Example .env
COPILOT_BRIDGE_PORT=3252
COPILOT_API_INTERNAL_PORT=4141
Running
Local Development
npm start
This will:
- Start the GitHub Copilot API proxy on port 4141
- Start the bridge wrapper on port 3252
- Expose OpenAI-compatible
/v1/chat/completionsendpoint
With PM2
npm run pm2
# Or manually
pm2 start server.js --name copilot-bridge
Verify Health
curl http://localhost:3252/health
Response:
{
"status": "ok",
"provider": "github-copilot",
"version": "1.0.0",
"copilot_api_port": 4141,
"healthy": true
}
Usage
Direct API Call
curl -X POST http://localhost:3252/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4",
"messages": [
{
"role": "user",
"content": "Write a hello world function in TypeScript"
}
],
"temperature": 0.3,
"max_tokens": 2048
}'
Via LLM Gateway
Once integrated into the gateway:
curl -X POST http://localhost:3103/api/generate \
-H "Content-Type: application/json" \
-d '{
"model": "copilot",
"messages": [
{
"role": "user",
"content": "Explain quantum computing"
}
]
}'
Integration with LLM Gateway
1. Add to external-providers.ts
export const EXTERNAL_PROVIDERS: ExternalProviderConfig = {
// ... other providers
copilot: {
name: 'GitHub Copilot',
baseUrl: 'http://localhost:3252',
requiresAuth: false, // Auth handled internally by copilot-api
models: ['gpt-4', 'gpt-3.5-turbo'],
rateLimit: 60, // requests per minute
pricing: 'subscription-based'
}
}
2. Update ecosystem.config.cjs
{
apps: [
// ... other apps
{
name: 'copilot-bridge',
script: '/opt/copilot-bridge/server.js',
env: {
COPILOT_BRIDGE_PORT: 3252,
COPILOT_API_INTERNAL_PORT: 4141
},
error_file: '/var/log/llm-gateway/copilot-bridge.err.log',
out_file: '/var/log/llm-gateway/copilot-bridge.out.log',
log_date_format: 'YYYY-MM-DD HH:mm:ss Z'
}
]
}
3. Update ensure-bridges.sh
# Add copilot-bridge deployment
if [ ! -d "$COPILOT_BRIDGE_DIR" ]; then
echo "Deploying copilot-bridge..."
mkdir -p "$COPILOT_BRIDGE_DIR"
cp copilot-bridge/server.js "$COPILOT_BRIDGE_DIR/"
cp copilot-bridge/package.json "$COPILOT_BRIDGE_DIR/"
cd "$COPILOT_BRIDGE_DIR"
npm install
echo "✓ copilot-bridge deployed"
fi
Provider Fallback Chain (After Integration)
Request → LLM Gateway
↓
1. Ollama (local)
2. claude-bridge (Claude subscription)
3. openai-bridge (OpenAI subscription)
4. copilot-bridge (GitHub Copilot subscription) ← NEW
5. cerebras (free tier)
6. groq (free tier)
7. mistral (free tier)
8. nvidia (free tier)
9. cloudflare (free tier)
Troubleshooting
Authentication Failed
# Clear cached tokens and re-authenticate
rm -rf ~/.copilot-api
npm run auth
Port Already in Use
# Find process using port 4141
lsof -i :4141
# Kill if needed
kill -9 <PID>
Copilot API Won't Start
# Test copilot-api directly
npx copilot-api@latest start --port 4141 --verbose
# Check for GitHub subscription
npm run debug
Bridge Wrapper Fails
# Check logs
pm2 logs copilot-bridge
# Test direct server start
node server.js
# Verify Node.js version
node --version # Should be 20+
Subscription Issues
GitHub Copilot API requires an active GitHub Copilot subscription. If you see authentication errors:
- Verify your GitHub Copilot subscription is active
- Check payment method is valid
- Re-authenticate:
npm run auth - Review usage at: https://github.com/settings/copilot
Security Notes
- Authentication tokens are stored in
~/.copilot-api/on the local machine - Do NOT commit authentication credentials to git
- Environment variables should be set via
.envor PM2 environment - Rate limiting is per GitHub account (not per API key)
- Usage tracking is available via GitHub Copilot dashboard
Performance Characteristics
| Metric | Value | Notes |
|---|---|---|
| Cold start | ~5-10s | copilot-api initialization |
| Warm latency | 200-500ms | Per request (varies by model) |
| Rate limit | 60 req/min | GitHub Copilot API limit |
| Max tokens | 2048 default | Configurable per request |
| Timeout | 300s | Global timeout |
Cost Considerations
- GitHub Copilot Individual: $10/month (monthly) or $100/year (annual)
- GitHub Copilot Business: $19/month per user
- No per-request cost once subscription is active
- Unlimited requests within rate limits
Differences from OpenAI
| Aspect | Copilot | OpenAI |
|---|---|---|
| Auth | GitHub subscription | API key |
| Cost | Flat subscription | Per token |
| Rate limit | 60 req/min | Varies by plan |
| Models | Limited selection | More options |
| Availability | GitHub-backed | Anthropic-backed |
Switching Providers
If you need to switch away from Copilot:
# Stop copilot-bridge
pm2 stop copilot-bridge
pm2 delete copilot-bridge
# Gateway will fall back to next provider automatically
# Restart gateway to clear connections
pm2 restart llm-gateway
Next Steps
- Deploy to Erik: Follow integration steps in main DEPLOYMENT-BRIDGES.md
- Test with LLM Gateway: Verify routing works correctly
- Monitor usage: Track GitHub Copilot API quota
- Optimize fallback chain: Adjust provider preferences based on performance
Last Updated: 2026-04-25 Maintained By: Rene Fichtmüller License: MIT