Copilot API Server Proxy
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
-
ReferenceError: require is not defined in ES module scope
cause Attempting to import `copilot-api` using CommonJS `require()` syntax in an ESM project or a JavaScript file without `"type": "module"`.fixSwitch to ES module `import` syntax (e.g., `import { startServer } from 'copilot-api'`) and ensure your Node.js project or file is configured for ESM. -
Proxy settings are not working/applied when running copilot-api.
cause Since v0.7.0, proxy environment variables (`HTTP_PROXY`, `HTTPS_PROXY`) are no longer automatically enabled.fixRestart the `copilot-api` server with the `--proxy-env` flag (e.g., `npx copilot-api@latest start --proxy-env`) or ensure `useProxyEnv: true` is passed in programmatic configurations. -
Error: Could not get Copilot token. Please make sure Copilot is running and logged in.
cause The `copilot-api` server failed to establish communication with or retrieve an authentication token from a valid GitHub Copilot instance.fixEnsure that GitHub Copilot is actively running and authenticated on your system (e.g., via VS Code or GitHub CLI) before starting the `copilot-api` server.
Warnings
- breaking Proxy environment variables (e.g., HTTP_PROXY, HTTPS_PROXY) are no longer automatically initialized or detected by the server by default.
- gotcha This package is an ECMAScript Module (ESM) and does not support direct `require()` calls from CommonJS environments.
- gotcha The `copilot-api` server relies on a locally authenticated GitHub Copilot session to function. It does not handle Copilot authentication itself.
Install
-
npm install copilot-api -
yarn add copilot-api -
pnpm add copilot-api
Imports
- startServer
const { startServer } = require('copilot-api')import { startServer } from 'copilot-api' - CopilotApiConfig
import { CopilotApiConfig } from 'copilot-api'import type { CopilotApiConfig } from 'copilot-api' - default
import CopilotApi from 'copilot-api'
(No default export)
Quickstart
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();