← Back to all toys

copilot2api

A lightweight Go proxy that exposes GitHub Copilot as OpenAI-compatible and Anthropic-compatible API endpoints.

The Problem

Using GitHub Copilot's LLM capabilities outside of its native IDE integrations requires a compatible API layer that doesn't exist natively.

Highlights

  • OpenAI and Anthropic API compatible endpoints
  • Full SSE streaming support
  • Auto GitHub Device Flow OAuth authentication
  • Built-in usage monitoring and models cache

Quick Start

Docker

docker run -it --rm \
  -p 127.0.0.1:7777:7777 \
  -v ~/.config/copilot2api:/root/.config/copilot2api \
  ghcr.io/whtsky/copilot2api:latest

The volume mount persists your GitHub credentials across container restarts. The examples publish the port on 127.0.0.1 only so the proxy stays local by default.

Download a release binary

# Example: macOS Apple Silicon
curl -L -o copilot2api \
  https://github.com/whtsky/copilot2api/releases/latest/download/copilot2api-darwin-arm64

# Example: Linux x64
# curl -L -o copilot2api \
#   https://github.com/whtsky/copilot2api/releases/latest/download/copilot2api-linux-amd64

chmod +x copilot2api
./copilot2api

Download the asset that matches your platform from GitHub Releases. Published binaries use names like copilot2api-linux-amd64, copilot2api-linux-arm64, copilot2api-darwin-amd64, copilot2api-darwin-arm64, copilot2api-windows-amd64.exe, and copilot2api-windows-arm64.exe.

On first run, both Docker and downloaded binaries prompt GitHub Device Flow authentication:

🔐 GitHub Authentication Required
Please visit: https://github.com/login/device
Enter code: XXXX-XXXX

Waiting for authorization...
✅ Authentication successful!

Server starts on http://127.0.0.1:7777 by default.

Security

⚠️ This proxy is designed for local development only.

  • Does not implement API key validation — any request is accepted
  • Do not expose publicly — it becomes an open proxy consuming your Copilot quota
  • Credentials are stored in ~/.config/copilot2api/credentials.json

Usage with Claude Code

Add to ~/.claude/settings.json:

{
  "env": {
    "ANTHROPIC_BASE_URL": "http://127.0.0.1:7777",
    "ANTHROPIC_API_KEY": "dummy",
    "ANTHROPIC_MODEL": "claude-opus-4.6",
    "ANTHROPIC_SMALL_FAST_MODEL": "claude-haiku-4.5",
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
  },
  "permissions": {
    "deny": ["WebSearch"]
  }
}

1M Context Window

copilot2api supports Claude 1M context models. When Claude Code sends the anthropic-beta: context-1m-... header, the proxy automatically appends -1m to the model ID (e.g. claude-opus-4.6claude-opus-4.6-1m) so Copilot routes to the 1M variant.

To use it, select the 1M model variant in Claude Code via the /model command (e.g. Opus (1M)). Without this, Claude Code defaults to the standard 200K context window.

Usage with Codex

Add to ~/.codex/config.toml:

model = "gpt-5.3-codex"
model_provider = "copilot2api"
model_reasoning_effort = "high"
web_search = "disabled"

[model_providers.copilot2api]
name = "copilot2api"
base_url = "http://127.0.0.1:7777/v1"
wire_api = "responses"
api_key = "dummy"