Copilot API Proxy

repository·master·Indexed 24 days ago

https://github.com/ericc-ch/copilot-api

A reverse-engineered proxy that exposes the GitHub Copilot API as an OpenAI and Anthropic compatible service. Version 0.7.0 allows developers to use their Copilot subscription with standard LLM tools, including Claude Code. It features OpenAI-compatible endpoints for chat completions, models, and embeddings, as well as Anthropic Messages API support. The tool includes a CLI for authentication, usage monitoring via a web dashboard, and support for deployment via npx, Docker, or Bun.

Tokens
7.4K
Snippets
20
Records
40
Agent score
87%

What's inside copilot-api

  1. Install and run Copilot API Proxy via npx

    master

    You can run the proxy directly without a permanent installation using npx. This is useful for quick testing or running the service on demand.

    Common tasks:

    • Start the server: npx copilot-api@latest start
    • Start on a custom port: npx copilot-api@latest start --port 8080
    • Run authentication flow only: npx copilot-api@latest auth
    # Basic usage with start command
    npx copilot-api@latest start
    
    # Run on custom port with verbose logging
    npx copilot-api@latest start --port 8080 --verbose
    
    # Run only the auth flow
    npx copilot-api@latest auth
  2. Access the Copilot Usage Dashboard

    master

    The Copilot Usage Dashboard is a web interface for monitoring your API usage. After starting the server, the console will output a URL (e.g., https://ericc-ch.github.io/copilot-api?endpoint=http://localhost:4141/usage).

    Features:

    • Usage Quotas: View progress bars for Chat and Completions services.
    • Detailed Information: View the full JSON response from the API.
    • Custom Endpoints: You can point the dashboard to any compatible API endpoint by using the endpoint query parameter in the URL.

    To view the dashboard, start the server and copy the provided URL into your browser.

    npx copilot-api@latest start
  3. Configure Claude Code to use the Copilot API Proxy

    master

    You can use this proxy to power Anthropic's Claude Code. There are two methods for configuration:

    1. Interactive Setup

    Run the start command with the --claude-code flag. You will be prompted to select a primary model and a "small, fast" model. The tool will copy a command to your clipboard which you can paste into a new terminal to launch Claude Code with the correct environment variables.

    2. Manual Configuration via settings.json

    Create a .claude/settings.json file in your project's root directory to persist the configuration. This avoids running the interactive setup every time.

    npx copilot-api@latest start --claude-code
  4. Run Copilot API Proxy with Docker

    master

    To run the proxy in a containerized environment, follow these steps to ensure your authentication persists across restarts.

    1. Build the image: docker build -t copilot-api .

    2. Persist data: Create a directory on your host to store the GitHub token and related data.

    3. Run the container: Use a bind mount to map the host directory to /root/.local/share/copilot-api inside the container.

    Using Environment Variables: You can pass the GH_TOKEN directly via environment variables to avoid interactive authentication.

    # Build image
    docker build -t copilot-api .
    
    # Create a directory on your host to persist the GitHub token and related data
    mkdir -p ./copilot-data
    
    # Run the container with a bind mount to persist the token
    docker run -p 4141:4141 -v $(pwd)/copilot-data:/root/.local/share/copilot-api copilot-api
    
    # Run with GitHub token via environment variable
    docker run -p 4141:4141 -e GH_TOKEN=your_github_token_here copilot-api
  5. Configure Copilot API Proxy via Docker Compose

    master

    Use the following docker-compose.yml configuration to deploy the service with automatic restarts and environment-based authentication.

    version: "3.8"
    services:
      copilot-api:
        build: .
        ports:
          - "4141:4141"
        environment:
          - GH_TOKEN=your_github_token_here
        restart: unless-stopped
  6. Configure Claude Code `.claude/settings.json`

    master

    To manually configure Claude Code to use the proxy, create a .claude/settings.json file in your project root. This file defines the environment variables required to route Claude Code traffic through the proxy.

    {
      "env": {
        "ANTHROPIC_BASE_URL": "http://localhost:4141",
        "ANTHROPIC_AUTH_TOKEN": "dummy",
        "ANTHROPIC_MODEL": "gpt-4.1",
        "ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-4.1",
        "ANTHROPIC_SMALL_FAST_MODEL": "gpt-4.1",
        "ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-4.1",
        "DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1",
        "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
      },
      "permissions": {
        "deny": [
          "WebSearch"
        ]
      }
    }
  7. Configure Claude Code to use Copilot API

    master

    You can automatically generate the environment configuration required to run Claude Code through the Copilot API proxy.

    When running the server with the --claude-code flag, the CLI will:

    1. Prompt you to select a primary model for Claude Code.
    2. Prompt you to select a 'small' model (for fast/haiku-style tasks).
    3. Generate a shell command containing the necessary ANTHROPIC_ environment variables.
    4. Copy that command to your clipboard.

    The generated environment variables include:

    • ANTHROPIC_BASE_URL: The URL of your running proxy.
    • ANTHROPIC_AUTH_TOKEN: Set to "dummy".
    • ANTHROPIC_MODEL: Your selected primary model.
    • ANTHROPIC_DEFAULT_SONNET_MODEL: Your selected primary model.
    • ANTHROPIC_SMALL_FAST_MODEL: Your selected small model.
    • ANTHROPIC_DEFAULT_HAIKU_MODEL: Your selected small model.
    • DISABLE_NON_ESSENTIAL_MODEL_CALLS: Set to "1".
    • CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: Set to "1".