A module used for interacting with the GitHub Copilot API.
Installation
With npm:
npm install @vscode/copilot-api
With yarn:
yarn add @vscode/copilot-api
Usage
Basic Setup
import { CAPIClient, RequestType } from '@vscode/copilot-api';
// Create a new client instance
const client = new CAPIClient(editorDetails, license, optionalFetcherService);
// Update domains (if needed)
const domainChanges = client.updateDomains(copilotToken, enterpriseUrlConfig);
// Make requests
const response = await client.makeRequest(fetchOptions, RequestType.ChatCompletions);
Available Request Types
RequestType.CopilotToken - Get Copilot token
RequestType.ChatCompletions - Chat completions
RequestType.RemoteAgent - Remote agent requests
RequestType.Embeddings - Embeddings
RequestType.Models - Available models
RequestType.CCAModelsList - Get available models for Copilot coding agent
RequestType.Chunks - Code chunks
RequestType.EmbeddingsCodeSearch - Embeddings code search
RequestType.ListSkills - List available skills
RequestType.SearchSkill - Search skills
RequestType.ContentExclusion - Content exclusion
RequestType.Telemetry - Telemetry
RequestType.CopilotUserInfo - User info
RequestType.OriginTracker - Origin tracking
Development
Building
The package is built using esbuild to create a single platform-neutral ESM module that works in both Node.js and web environments:
# Build for production (minified)
npm run build
# Build for development (unminified)
npm run build:dev
# Clean build artifacts
npm run clean
Build Output
dist/index.js - Platform-neutral ESM build
dist/index.d.ts - TypeScript declarations
Package Exports
The package is configured with a simplified ESM export structure:
{
"exports": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
}
}
Testing
This project uses Vitest for testing. Run tests with:
# Run tests once
npm test
# Run tests in watch mode
npm run test:watch