Copilot API Server Proxy

0.7.0 · active · verified Tue Apr 21

copilot-api transforms GitHub Copilot into an API-compatible server that mimics OpenAI and Anthropic interfaces, making Copilot's capabilities accessible to applications designed for these popular LLM APIs. This allows tools like Claude Code to leverage GitHub Copilot directly. The package is currently at version 0.7.0 and receives frequent updates, often with minor feature additions and bug fixes, as seen in recent patch and minor releases. Its key differentiator is bridging GitHub Copilot's proprietary access with standard API formats, offering flexibility for developers who want to integrate Copilot into existing LLM toolchains without vendor lock-in to GitHub's specific integration methods. It runs as a standalone server, typically invoked via `npx`.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to programmatically start the Copilot API server within a Node.js application, allowing for custom configuration beyond CLI arguments and illustrating basic setup.

import { startServer } from 'copilot-api';
import { fileURLToPath } from 'url';
import path from 'path';

// ESM equivalent of __dirname
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

async function runCopilotApiServer() {
  const config = {
    port: 3000,
    host: '0.0.0.0',
    // Example: Pass a custom path to a session token file if needed
    // copilotTokenPath: path.join(__dirname, 'copilot_session.json'),
    // As of v0.7.0, proxy environment variables require explicit enabling:
    // useProxyEnv: true, // Corresponds to --proxy-env CLI flag
    // Enable Claude Code specific environment variables:
    // enableClaudeCode: true, // Corresponds to --claude-code CLI flag
  };

  console.log('Starting Copilot API server programmatically...');
  try {
    await startServer(config);
    console.log(`Copilot API server listening on http://${config.host}:${config.port}`);
    console.log('Use Ctrl+C to stop the server.');
  } catch (error) {
    console.error('Failed to start Copilot API server:', error);
    process.exit(1);
  }
}

runCopilotApiServer();

view raw JSON →