Skip to content

billxc/copilot-api

 
 

Repository files navigation

Copilot API Proxy

Fork Notice:
The original project by ericc-ch is no longer actively maintained. This fork by billxc updates the project for personal use, adding native passthrough support for the Responses API and Claude API.

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.

Warning

GitHub Security Notice:
Excessive automated or scripted use of Copilot (including rapid or bulk requests, such as via automated tools) may trigger GitHub's abuse-detection systems. Use this proxy responsibly to avoid account restrictions.

爱发电

A reverse-engineered proxy for the GitHub Copilot API that exposes it as an OpenAI and Anthropic compatible service. Use GitHub Copilot with Claude Code, Codex CLI, or any tool that supports the OpenAI / Anthropic API.

Note: If you are using opencode, you do not need this project. Opencode supports GitHub Copilot provider out of the box.

Quick Start

# 1. Start the server
npx xc-copilot-api@latest start

# 2. Configure your tool
npx xc-copilot-api@latest config --claude    # Claude Code (Opus 4.7)
npx xc-copilot-api@latest config --codex     # Codex CLI (GPT-5.5)

That's it. Your tool is now powered by GitHub Copilot.

Demo

copilot-api-demo.mp4

Features

  • OpenAI & Anthropic Compatibility/v1/chat/completions, /v1/responses, /v1/messages, /v1/embeddings, /v1/models
  • Native Passthrough — Claude and GPT models are forwarded directly to upstream with full protocol fidelity (tool use, streaming, thinking blocks, vision)
  • One-command Setupconfig --claude / config --codex writes the right settings automatically
  • Usage Dashboard — Web UI to monitor quotas and usage statistics
  • Rate Limiting--rate-limit and --wait to stay within GitHub's limits
  • Background Service — Run as a system service via easy-service
  • Multiple Account Types — Individual, business, and enterprise Copilot plans

Using with Claude Code

# Opus 4.7 (default)
npx xc-copilot-api@latest config --claude

# Opus 4.6
npx xc-copilot-api@latest config --claude -m 4.6

A backup of your existing config is saved as settings.json.bak.

Manual configuration

Opus 4.7 (default):

{
  "env": {
    "ANTHROPIC_BASE_URL": "http://localhost:4141",
    "ANTHROPIC_AUTH_TOKEN": "Powered by xc copilot",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-4.7-1m-internal",
    "CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"
  }
}

Opus 4.6:

{
  "env": {
    "ANTHROPIC_BASE_URL": "http://localhost:4141",
    "ANTHROPIC_AUTH_TOKEN": "Powered by xc copilot",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-4.6-1m",
    "CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"
  }
}

More options: Claude Code settings · IDE integration

Using with Codex CLI

npx xc-copilot-api@latest config --codex
Manual configuration

Add to ~/.codex/config.toml:

model = "gpt-5.5"
model_provider = "copilot-api"

[model_providers.copilot-api]
name = "copilot-api"
base_url = "http://localhost:4141/v1"
wire_api = "responses"

Command Reference

Commands

Command Description
start Start the API server (handles auth automatically)
auth Run GitHub auth flow only (for generating tokens for CI/CD)
config Configure Claude Code or Codex CLI to use this proxy
check-usage Show Copilot usage and quota in the terminal
debug Display version, runtime, file paths, and auth status

start Options

Option Description Default Alias
--port Port to listen on 4141 -p
--verbose Enable verbose logging false -v
--account-type Account type (individual, business, enterprise) individual -a
--manual Manually approve each request false
--rate-limit Minimum seconds between requests -r
--wait Wait instead of error when rate limited false -w
--github-token Provide GitHub token directly -g
--show-token Show tokens on fetch and refresh false
--proxy-env Initialize proxy from environment variables false

config Options

Option Description Default Alias
--claude Configure Claude Code (~/.claude/settings.json) false -c
--codex Configure Codex CLI (~/.codex/config.toml) false -x
--claude-model Claude Opus model version (4.7 or 4.6) 4.7 -m

API Endpoints

Endpoint Description
POST /v1/chat/completions OpenAI Chat Completions API
POST /v1/responses OpenAI Responses API (native passthrough)
POST /v1/messages Anthropic Messages API (native passthrough)
POST /v1/messages/count_tokens Anthropic token counting
GET /v1/models List available models
POST /v1/embeddings Create embedding vectors
GET /usage Copilot usage statistics and quota
GET /token Current Copilot token

Running as a Background Service

# Install easy-service
uv tool install git+https://github.com/billxc/easy-service.git

# Install and start
easy-service install copilot-api -- npx -y xc-copilot-api@latest start

# Manage
easy-service status copilot-api
easy-service logs copilot-api -f
easy-service restart copilot-api
easy-service stop copilot-api
easy-service uninstall copilot-api

Running from Source

bun install        # install dependencies
bun run dev        # development mode
bun run start      # production mode

Prerequisites: Bun >= 1.2.x, GitHub account with Copilot subscription.

Usage Tips

  • Use --rate-limit 30 --wait to stay within Copilot's rate limits without client errors.
  • Use --account-type business or enterprise if you have a business/enterprise Copilot plan. See official docs.
  • Use --manual to approve each request individually for fine-grained control.

Using with Docker

Pre-built Image

docker pull ghcr.io/billxc/copilot-api:latest
mkdir -p ./copilot-data
docker run -p 4141:4141 -v $(pwd)/copilot-data:/root/.local/share/copilot-api ghcr.io/billxc/copilot-api:latest

Available tags: latest, v*.*.*, master, <sha>

Build from Source

docker build -t copilot-api .
mkdir -p ./copilot-data
docker run -p 4141:4141 -v $(pwd)/copilot-data:/root/.local/share/copilot-api copilot-api

Environment Variables

docker run -p 4141:4141 -e GH_TOKEN=your_token copilot-api

Docker Compose

version: "3.8"
services:
  copilot-api:
    image: ghcr.io/billxc/copilot-api:latest
    ports:
      - "4141:4141"
    environment:
      - GH_TOKEN=your_github_token_here
    volumes:
      - ./copilot-data:/root/.local/share/copilot-api
    restart: unless-stopped

Note: Token data is persisted in copilot-data on your host, mapped to /root/.local/share/copilot-api inside the container.

Update Log

v1.2.3 — Claude Model Selection & Codex 5.5

  • Claude model version selection: New --claude-model (-m) option for config --claude. Choose between Opus 4.7 (default) and Opus 4.6.
  • Codex default model updated: config --codex now defaults to gpt-5.5.
  • Filter unsupported tools in Responses API: Automatically strips image_generation and other unsupported tool types before forwarding to upstream, preventing errors from Codex CLI.
  • Bun idle timeout fix: Increased idleTimeout to 255s to prevent streaming responses from being cut off after 10 seconds.
  • README restructured: Quick Start first, collapsible Docker/Update Log sections, consolidated command reference.

v1.2.1 — easy-service & Config Command

  • New config subcommand: One-command setup for Claude Code (config --claude) and Codex CLI (config --codex).
  • Background service: Replaced built-in daemon with easy-service for cross-platform service management.

v1.1.x — Anthropic 1M Models

  • Anthropic 1M model support: Enhanced beta header handling for claude-opus-4.6-1m and other 1M context models.

v1.0.x — Native Passthrough

  • Native passthrough for Responses API and Claude API: Claude models forward the entire Anthropic Messages request directly to upstream. GPT models forward Responses API requests without transformation.
  • Full protocol fidelity: Tool use, streaming, thinking blocks, vision — all preserved without translation loss.
  • Fallback translation: Non-Claude models hitting /v1/messages still use the Anthropic-to-OpenAI translation layer.

About

Turn GitHub Copilot into OpenAI/Anthropic API compatible server. Usable with Claude Code!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 85.9%
  • JavaScript 13.0%
  • Other 1.1%