A high-performance Go proxy server that turns GitHub Copilot's chat completion/embeddings capabilities into an OpenAI-compatible API service, with Anthropic compatibility and robust security.
I wouldn't call this a "fork" but I would say it's heavily inspired by copilot-openai-api. If you want to use Python instead of Go then you should check out that project.
π Advanced Integration
- Seamless GitHub Copilot chat completion API proxy (
/v1/chat/completions) - Embeddings API proxy (
/v1/embeddings) - Anthropic API compatibility (
/v1/messages, experimental) - Real-time streaming response support
- High-performance, concurrent request handling
π Security & Reliability
- Secure authentication middleware (Bearer token)
- Automatic Copilot token management and refresh
- Built-in CORS support for web applications
- Clear error handling (401, 403, etc.)
π» Universal Compatibility
- Cross-platform config auto-detection (Windows, Unix, macOS)
- Docker containerization ready
- Flexible deployment and configuration
- Go 1.21+ (https://golang.org/dl/)
- GitHub Copilot subscription
- GitHub authentication token (see below)
- Clone the repository:
git clone https://github.com/your-org/copilot-openai-api-go.git
cd go-copilot-api- Build the binary:
go build -o bin/go-copilot-api ./cmd/go-copilot-apiSet up environment variables (or use a .env file):
| Variable | Description | Default |
|---|---|---|
COPILOT_TOKEN |
Required. API access token for authentication. | Randomly generated |
COPILOT_OAUTH_TOKEN |
Copilot OAuth token (auto-detected if not set) | (auto) |
COPILOT_SERVER_PORT |
Port to listen on (e.g. 8080 for :8080) |
9191 |
CORS_ALLOWED_ORIGINS |
Comma-separated list of allowed CORS origins | * |
DEBUG |
Enable debug logging | false |
DEFAULT_MODEL |
Default model to use if not specified in request | (none) |
Copilot OAuth Token Auto-Detection:
- If
COPILOT_OAUTH_TOKENis not set, the app will look for your Copilot config:- Unix/macOS:
~/.config/github-copilot/apps.json - Windows:
%LOCALAPPDATA%/github-copilot/apps.json
- Unix/macOS:
- The first available
oauth_tokenwill be used.
How to get a valid Copilot configuration?
- Install any official GitHub Copilot plugin (VS Code, JetBrains, Vim, etc.), sign in, and the config files will be created automatically.
Start the server:
go run ./cmd/go-copilot-apior
bin/go-copilot-apicurl -X POST http://localhost:9191/v1/chat/completions \
-H "Authorization: Bearer your_access_token_here" \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": "Hello, Copilot!"}]
}'curl -X POST http://localhost:9191/v1/embeddings \
-H "Authorization: Bearer your_access_token_here" \
-H "Content-Type: application/json" \
-d '{
"model": "copilot-text-embedding-ada-002",
"input": ["The quick brown fox", "Jumped over the lazy dog"]
}'curl -X POST http://localhost:9191/v1/messages \
-H "Authorization: Bearer your_access_token_here" \
-H "Content-Type: application/json" \
-d '{ ...Anthropic API message format... }'Fetch the list of available models and their capabilities:
curl -X GET http://localhost:9191/v1/models- This endpoint does not require authentication.
- The models list is fetched from GitHub's model catalog API at server startup and periodically refreshed (every 6 hours).
- The response is a JSON array of model objects, including
id,name,summary, and more. - Use the
"id"field (e.g.,"gpt-5-mini","gpt-4o-mini-2024-07-18") as the"model"value in your requests.
curl -s http://localhost:9191/v1/models | jq '.[] | select(.id | test("5-mini"))'You can set a default model for all requests by adding to your .env or environment:
DEFAULT_MODEL=gpt-5-mini
If a client request does not specify a "model" field, this value will be used automatically for /v1/chat/completions, /v1/embeddings, and /v1/messages.
- If
DEFAULT_MODELis not set, and the client omits"model", no model is sent to Copilot (Copilot will auto-select). - If the client provides a
"model", that value is always used as-is.
COPILOT_TOKEN=your_token_here
DEFAULT_MODEL=gpt-5-mini
COPILOT_SERVER_PORT=9191
- Proxies requests to GitHub Copilot's Completions API.
- Headers:
Authorization: Bearer <your_access_token>,Content-Type: application/json - Body: Must include
"messages". You may include"model"(see/v1/modelsfor valid values). If omitted andDEFAULT_MODELis set, it will be injected. - Response: Streams responses directly from Copilot (supports streaming and non-streaming).
- Proxies requests to Copilot's Embeddings API.
- Headers:
Authorization: Bearer <your_access_token>,Content-Type: application/json - Body: Must include
"input". You may include"model"(see/v1/models). If omitted andDEFAULT_MODELis set, it will be injected. - Response: JSON from Copilot's embeddings API.
- Converts Anthropic API format to Copilot chat completion format.
- Headers:
Authorization: Bearer <your_access_token>,Content-Type: application/json - Body: Anthropic-compatible. You may include
"model"(see/v1/models). If omitted andDEFAULT_MODELis set, it will be injected. - Response: Anthropic API-compatible response.
Note: Claude Code/Anthropic compatibility is currently untested. If you use Claude Code or Anthropic clients and encounter issues, we would appreciate any PRs or feedback to help improve support!
- Returns a list of available models and their capabilities.
- No authentication required.
- Response: JSON array of models as provided by GitHub's model catalog API.
- Tip: Use the
"id"field as the"model"value in your requests.
- Set
COPILOT_TOKENin your environment. - Include in request headers:
Authorization: Bearer your_access_token_here
- 401: Missing/invalid authorization header
- 403: Invalid access token
- Other errors are propagated from GitHub Copilot API
- Configure CORS for your specific domains (default:
*) - Safeguard your
COPILOT_TOKENand GitHub OAuth token - Built-in token management with concurrent access protection
- Anthropic API compatibility (
/v1/messages)
go-copilot-api/
βββ cmd/
β βββ go-copilot-api/
β βββ main.go # Application entrypoint
βββ internal/
β βββ api/ # HTTP handlers and routing
βββ pkg/
β βββ config/ # Configuration loading
βββ test/ # Test files
βββ LICENSE # YO LICENSE
βββ go.mod # Go module definition
βββ go.sum # Go module checksums
βββ README.md # This file
Run all tests:
go test ./...See LICENSE β YO LICENSE, Version 1.0, February 2025 Copyright (C) 2025 Travis Peacock
