{"id":15994,"library":"copilot-api","title":"Copilot API Server Proxy","description":"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`.","status":"active","version":"0.7.0","language":"javascript","source_language":"en","source_url":"https://github.com/ericc-ch/copilot-api","tags":["javascript","proxy","github-copilot","openai-compatible"],"install":[{"cmd":"npm install copilot-api","lang":"bash","label":"npm"},{"cmd":"yarn add copilot-api","lang":"bash","label":"yarn"},{"cmd":"pnpm add copilot-api","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is primarily a CLI tool. Programmatic usage via 'startServer' is for embedding the server within another application. It is an ESM-only package.","wrong":"const { startServer } = require('copilot-api')","symbol":"startServer","correct":"import { startServer } from 'copilot-api'"},{"note":"Type import for configuring the Copilot API server programmatically. While 'import { ... }' also works, 'import type' is preferred for clarity and bundle optimization.","wrong":"import { CopilotApiConfig } from 'copilot-api'","symbol":"CopilotApiConfig","correct":"import type { CopilotApiConfig } from 'copilot-api'"},{"note":"The 'copilot-api' package does not provide a default export. Use named imports for specific programmatic components or rely on the 'npx copilot-api' CLI for standard operation.","wrong":"import CopilotApi from 'copilot-api'","symbol":"default","correct":"(No default export)"}],"quickstart":{"code":"import { startServer } from 'copilot-api';\nimport { fileURLToPath } from 'url';\nimport path from 'path';\n\n// ESM equivalent of __dirname\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nasync function runCopilotApiServer() {\n  const config = {\n    port: 3000,\n    host: '0.0.0.0',\n    // Example: Pass a custom path to a session token file if needed\n    // copilotTokenPath: path.join(__dirname, 'copilot_session.json'),\n    // As of v0.7.0, proxy environment variables require explicit enabling:\n    // useProxyEnv: true, // Corresponds to --proxy-env CLI flag\n    // Enable Claude Code specific environment variables:\n    // enableClaudeCode: true, // Corresponds to --claude-code CLI flag\n  };\n\n  console.log('Starting Copilot API server programmatically...');\n  try {\n    await startServer(config);\n    console.log(`Copilot API server listening on http://${config.host}:${config.port}`);\n    console.log('Use Ctrl+C to stop the server.');\n  } catch (error) {\n    console.error('Failed to start Copilot API server:', error);\n    process.exit(1);\n  }\n}\n\nrunCopilotApiServer();","lang":"typescript","description":"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."},"warnings":[{"fix":"To enable proxy support from environment variables, you must explicitly use the `--proxy-env` flag when starting the server via CLI (e.g., `npx copilot-api start --proxy-env`) or set `useProxyEnv: true` in programmatic configurations.","message":"Proxy environment variables (e.g., HTTP_PROXY, HTTPS_PROXY) are no longer automatically initialized or detected by the server by default.","severity":"breaking","affected_versions":">=0.7.0"},{"fix":"Ensure your project is configured for ESM (e.g., by setting `\"type\": \"module\"` in `package.json` or using `.mjs` file extensions) and use `import` statements for programmatic access.","message":"This package is an ECMAScript Module (ESM) and does not support direct `require()` calls from CommonJS environments.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Verify that GitHub Copilot is installed and logged in on the machine running the `copilot-api` server. This typically involves having VS Code with the Copilot extension or the GitHub CLI with Copilot features enabled and authenticated.","message":"The `copilot-api` server relies on a locally authenticated GitHub Copilot session to function. It does not handle Copilot authentication itself.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Switch to ES module `import` syntax (e.g., `import { startServer } from 'copilot-api'`) and ensure your Node.js project or file is configured for ESM.","cause":"Attempting to import `copilot-api` using CommonJS `require()` syntax in an ESM project or a JavaScript file without `\"type\": \"module\"`.","error":"ReferenceError: require is not defined in ES module scope"},{"fix":"Restart 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.","cause":"Since v0.7.0, proxy environment variables (`HTTP_PROXY`, `HTTPS_PROXY`) are no longer automatically enabled.","error":"Proxy settings are not working/applied when running copilot-api."},{"fix":"Ensure 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.","cause":"The `copilot-api` server failed to establish communication with or retrieve an authentication token from a valid GitHub Copilot instance.","error":"Error: Could not get Copilot token. Please make sure Copilot is running and logged in."}],"ecosystem":"npm"}