### Start Production Server Source: https://github.com/ericc-ch/copilot-api/blob/master/AGENTS.md Starts the application in production mode. This command should be used after building the project for deployment. ```bash bun run start ``` -------------------------------- ### Install Dependencies with Bun Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Install project dependencies using Bun. Ensure Bun is installed and at least version 1.2.x. ```sh bun install ``` -------------------------------- ### Start Copilot API with Manual Approval Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Enable manual approval for each request by using the --manual flag when starting the server. ```bash npx copilot-api@latest start --manual ``` -------------------------------- ### Start Copilot API Server with Business Account Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Starts the Copilot API server using a business GitHub account type. ```bash npx copilot-api@latest start --account-type business ``` -------------------------------- ### start — Start the proxy server Source: https://context7.com/ericc-ch/copilot-api/llms.txt Starts the Copilot API proxy server. It handles GitHub authentication automatically and can be configured with various operational flags for port, account type, rate limiting, and more. ```APIDOC ## start ### Description Starts the Copilot API proxy. Handles GitHub authentication automatically on first run and refreshes Copilot tokens in the background. Accepts all operational flags. ### Usage ```sh # Basic start on default port 4141 npx copilot-api@latest start # Custom port with verbose logging npx copilot-api@latest start --port 8080 --verbose # Business/enterprise GitHub Copilot account npx copilot-api@latest start --account-type business npx copilot-api@latest start --account-type enterprise # Rate limit to 30 seconds between requests; wait instead of error on breach npx copilot-api@latest start --rate-limit 30 --wait # Provide pre-generated GitHub token (non-interactive / CI) npx copilot-api@latest start --github-token ghp_YOUR_TOKEN_HERE # Interactive Claude Code setup: prompts for model selection, copies launch command to clipboard npx copilot-api@latest start --claude-code # Enable manual per-request approval prompt in the terminal npx copilot-api@latest start --manual # Route outbound requests through HTTP_PROXY / HTTPS_PROXY env vars npx copilot-api@latest start --proxy-env # Show GitHub and Copilot tokens on fetch/refresh (debug) npx copilot-api@latest start --show-token ``` ``` -------------------------------- ### Run Development Server Source: https://github.com/ericc-ch/copilot-api/blob/master/AGENTS.md Starts the development server for live updates and debugging. Assumes project dependencies are met. ```bash bun run dev ``` -------------------------------- ### Start Copilot API Server with Custom Port and Verbose Logging Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Starts the Copilot API server on a specified port and enables verbose logging for detailed output. ```bash npx copilot-api@latest start --port 8080 --verbose ``` -------------------------------- ### Start Copilot API Server with Enterprise Account Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Starts the Copilot API server using an enterprise GitHub account type. ```bash npx copilot-api@latest start --account-type enterprise ``` -------------------------------- ### Build Project with tsup Source: https://github.com/ericc-ch/copilot-api/blob/master/AGENTS.md Use this command to build the project using tsup. Ensure all dependencies are installed. ```bash bun run build ``` -------------------------------- ### Initialize Proxy from Environment Variables Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Start the proxy server and configure it to use environment variables for proxy settings (e.g., HTTP_PROXY, HTTPS_PROXY). ```bash npx copilot-api@latest start --proxy-env ``` -------------------------------- ### Start Copilot API Proxy Server Source: https://context7.com/ericc-ch/copilot-api/llms.txt Starts the Copilot API proxy server. Handles GitHub authentication automatically and refreshes tokens in the background. Use flags to customize port, logging, account type, rate limiting, and more. ```sh npx copilot-api@latest start ``` ```sh # Custom port with verbose logging npx copilot-api@latest start --port 8080 --verbose ``` ```sh # Business/enterprise GitHub Copilot account npx copilot-api@latest start --account-type business npx copilot-api@latest start --account-type enterprise ``` ```sh # Rate limit to 30 seconds between requests; wait instead of error on breach npx copilot-api@latest start --rate-limit 30 --wait ``` ```sh # Provide pre-generated GitHub token (non-interactive / CI) npx copilot-api@latest start --github-token ghp_YOUR_TOKEN_HERE ``` ```sh # Interactive Claude Code setup: prompts for model selection, copies launch command to clipboard npx copilot-api@latest start --claude-code ``` ```sh # Enable manual per-request approval prompt in the terminal npx copilot-api@latest start --manual ``` ```sh # Route outbound requests through HTTP_PROXY / HTTPS_PROXY env vars npx copilot-api@latest start --proxy-env ``` ```sh # Show GitHub and Copilot tokens on fetch/refresh (debug) npx copilot-api@latest start --show-token ``` -------------------------------- ### Run Copilot API with npx Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Execute the Copilot API proxy directly using npx. This command starts the proxy with default settings. ```sh npx copilot-api@latest start ``` -------------------------------- ### Configure Claude Code via .claude/settings.json Source: https://context7.com/ericc-ch/copilot-api/llms.txt Persist Claude Code configuration by creating a `.claude/settings.json` file in the project root. This avoids re-running the interactive setup. ```json { "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-4o-mini", "ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-4o-mini", "DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1", "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1" }, "permissions": { "deny": ["WebSearch"] } } ``` -------------------------------- ### GET /usage — Get Copilot usage and quota Source: https://context7.com/ericc-ch/copilot-api/llms.txt Returns the raw GitHub Copilot usage response including quota snapshots for premium interactions, chat, and completions. ```APIDOC ## GET /usage ### Description Returns the raw GitHub Copilot usage response including quota snapshots for premium interactions, chat, and completions. Also accessible at the web dashboard URL printed on server start. ### Method GET ### Endpoint /usage ### Response #### Success Response (200) - **copilot_plan** (string) - The current Copilot plan. - **quota_reset_date** (string) - The date when the quota resets. - **quota_snapshots** (object) - Snapshots of quota usage. - **premium_interactions** (object) - Details about premium interactions quota. - **remaining** (integer) - The number of remaining premium interactions. - **chat** (object) - Details about chat quota. - **unlimited** (boolean) - Indicates if chat quota is unlimited. ### Response Example ```json { "plan": "copilot_for_individuals", "reset": "2025-06-01", "premium_remaining": 288, "chat_unlimited": true } ``` ``` -------------------------------- ### Docker Compose Configuration Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Example Docker Compose configuration for setting up and running the Copilot API proxy service. This includes port mapping, environment variables for authentication, and restart policy. ```yaml version: "3.8" services: copilot-api: build: . ports: - "4141:4141" environment: - GH_TOKEN=your_github_token_here restart: unless-stopped ``` -------------------------------- ### Authenticate with Copilot API using npx Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Initiate the authentication process for the Copilot API proxy using npx. This command is used for setting up authentication without starting the full proxy service. ```sh npx copilot-api@latest auth ``` -------------------------------- ### Start Copilot API with Claude Code Integration Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Launch the Copilot API server with the --claude-code flag to enable integration with Claude Code. This will prompt for model selection and copy a command to set environment variables. ```sh npx copilot-api@latest start --claude-code ``` -------------------------------- ### Check Copilot Usage Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Display your Copilot usage and quota directly in the terminal without needing to start the server. ```bash npx copilot-api@latest check-usage ``` -------------------------------- ### auth — Run authentication only Source: https://context7.com/ericc-ch/copilot-api/llms.txt Runs the GitHub device OAuth flow without starting the server. This command saves the resulting token to disk for later use with the `--github-token` flag. ```APIDOC ## auth ### Description Runs the GitHub device OAuth flow without starting the server. Saves the resulting token to disk for later use with `--github-token`. ### Usage ```sh # Interactive auth flow npx copilot-api@latest auth # Auth with verbose logging and token display npx copilot-api@latest auth --verbose --show-token # Output after success: # ✔ GitHub token written to /home/user/.local/share/copilot-api/github-token ``` ``` -------------------------------- ### Check Copilot Usage Source: https://context7.com/ericc-ch/copilot-api/llms.txt Authenticates and fetches current quota/usage from GitHub's Copilot API, then prints a formatted summary without starting the server. Displays quota resets and usage percentages for different plans. ```sh npx copilot-api@latest check-usage ``` ```sh # Example output: # ╭─────────────────────────────────────────────────╮ # │ Copilot Usage (plan: copilot_for_individuals) │ # │ Quota resets: 2025-06-01 │ # │ │ # │ Quotas: # │ Premium: 12/300 used (4.0% used, 96.0% ...) │ # │ Chat: 0/unlimited used (0.0% used, ...) │ # │ Completions: 0/unlimited used (...) │ # ╰─────────────────────────────────────────────────╯ ``` -------------------------------- ### Claude Code settings.json Configuration Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Configure Claude Code to use the Copilot API proxy by creating a .claude/settings.json file. This example sets environment variables for Anthropic API integration. ```json { "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" ] } } ``` -------------------------------- ### GET /token — Get current Copilot token Source: https://context7.com/ericc-ch/copilot-api/llms.txt Returns the active Copilot bearer token being used for upstream requests. Useful for debugging or direct Copilot API access. ```APIDOC ## GET /token ### Description Returns the active Copilot bearer token being used for upstream requests. Useful for debugging or direct Copilot API access. ### Method GET ### Endpoint /token ### Response #### Success Response (200) - **token** (string) - The current Copilot bearer token. ### Response Example ```json { "token": "tid=...;exp=...;..." } ``` ``` -------------------------------- ### check-usage — Display Copilot quota in the terminal Source: https://context7.com/ericc-ch/copilot-api/llms.txt Authenticates and fetches the current quota and usage from GitHub's Copilot API, then prints a formatted summary without starting the server. ```APIDOC ## check-usage ### Description Authenticates and fetches current quota/usage from GitHub's Copilot API, then prints a formatted summary without starting the server. ### Usage ```sh npx copilot-api@latest check-usage # Example output: # ╭─────────────────────────────────────────────────╮ # │ Copilot Usage (plan: copilot_for_individuals) │ # │ Quota resets: 2025-06-01 │ # │ │ # │ Quotas: # │ Premium: 12/300 used (4.0% used, 96.0% ...) │ # │ Chat: 0/unlimited used (0.0% used, ...) │ # │ Completions: 0/unlimited used (...) │ # ╰─────────────────────────────────────────────────╯ ``` ``` -------------------------------- ### Lint Staged Files Source: https://github.com/ericc-ch/copilot-api/blob/master/AGENTS.md Uses lint-staged to automatically lint and fix only the files that are currently staged for commit. Requires lint-staged to be installed. ```bash bunx lint-staged ``` -------------------------------- ### Authenticate Copilot API Proxy Source: https://context7.com/ericc-ch/copilot-api/llms.txt Runs the GitHub device OAuth flow without starting the server. Saves the resulting token to disk for later use with the --github-token flag. Use --verbose and --show-token for more details. ```sh # Interactive auth flow npx copilot-api@latest auth ``` ```sh # Auth with verbose logging and token display npx copilot-api@latest auth --verbose --show-token ``` ```sh # Output after success: # ✔ GitHub token written to /home/user/.local/share/copilot-api/github-token ``` -------------------------------- ### Get Copilot Usage and Quota Source: https://context7.com/ericc-ch/copilot-api/llms.txt Retrieves raw GitHub Copilot usage data, including quota snapshots for premium interactions, chat, and completions. This endpoint provides a detailed view of your current usage status. ```sh curl -s http://localhost:4141/usage | jq '{ plan: .copilot_plan, reset: .quota_reset_date, premium_remaining: .quota_snapshots.premium_interactions.remaining, chat_unlimited: .quota_snapshots.chat.unlimited }' # Expected: # { # "plan": "copilot_for_individuals", # "reset": "2025-06-01", # "premium_remaining": 288, # "chat_unlimited": true # } ``` -------------------------------- ### Build and Run Copilot API with Docker Source: https://context7.com/ericc-ch/copilot-api/llms.txt Instructions for building the Docker image and running the Copilot API service. Supports persistent token storage via volume mounts and pre-supplied GitHub tokens via environment variables. ```sh # Build the image docker build -t copilot-api . # Run with persistent token storage mkdir -p ./copilot-data docker run -p 4141:4141 \ -v $(pwd)/copilot-data:/root/.local/share/copilot-api \ copilot-api # Run with pre-supplied GitHub token (non-interactive) docker run -p 4141:4141 \ -e GH_TOKEN=ghp_YOUR_TOKEN_HERE \ copilot-api # Docker Compose cat > docker-compose.yml << 'EOF' version: "3.8" services: copilot-api: build: . ports: - "4141:4141" environment: - GH_TOKEN=ghp_YOUR_TOKEN_HERE restart: unless-stopped EOF docker compose up -d ``` -------------------------------- ### Initialize Application Source: https://github.com/ericc-ch/copilot-api/blob/master/pages/index.html Sets up the event listener for form submission and retrieves the endpoint from URL parameters on load. If no endpoint is found in the URL, it uses a default value. ```javascript function init() { endpointForm.addEventListener("submit", handleFormSubmit); // Get endpoint from URL param on load const urlParams = new URLSearchParams(window.location.search); const endpointFromUrl = urlParams.get("endpoint"); if (endpointFromUrl) { endpointUrlInput.value = endpointFromUrl; fetchData(); } else { endpointUrlInput.value = DEFAULT_ENDPOINT; render(); // Render initial welcome message } } // Start the app init(); ``` -------------------------------- ### Initialize Dashboard and Event Listeners Source: https://github.com/ericc-ch/copilot-api/blob/master/pages/index.html Sets up the dashboard by adding a DOMContentLoaded event listener to initialize UI elements, fetch data, and apply hover effects to the fetch button. ```javascript document.addEventListener("DOMContentLoaded", () => { const endpointForm = document.getElementById("endpoint-form"); const endpointUrlInput = document.getElementById("endpoint-url"); const contentArea = document.getElementById("content-area"); const fetchButton = document.getElementById("fetch-button"); // Apply hover effect for fetch button via JS fetchButton.addEventListener("mouseenter", () => { fetchButton.style.backgroundColor = "var(--color-blue-accent)"; }); fetchButton.addEventListener("mouseleave", () => { fetchButton.style.backgroundColor = "var(--color-blue)"; }); const DEFAULT_ENDPOINT = "http://localhost:4141/usage"; // --- State Management --- const state = { isLoading: false, error: null, data: null, }; // --- Rendering Logic --- /** * Safely calls lucide.createIcons() if the library is available. */ function createIcons() { if (typeof lucide !== "undefined") { lucide.createIcons(); } } /** * Renders the entire UI based on the current state. */ function render() { if (state.isLoading) { contentArea.innerHTML = renderSpinner(); return; } if (state.error) { contentArea.innerHTML = renderError(state.error); } else if (state.data) { contentArea.innerHTML = ` ${renderUsageQuotas(state.data.quota_snapshots)} ${renderDetailedData(state.data)} `; } else { contentArea.innerHTML = renderWelcomeMessage(); } // Replace placeholder icons with actual Lucide icons createIcons(); } /** * Renders the "Usage Quotas" section with progress bars. * @param {object} snapshots - The quota_snapshots object from the API response. * @returns {string} HTML string for the usage quotas section. */ function renderUsageQuotas(snapshots) { if (!snapshots) return ""; const quotaCards = Object.entries(snapshots) .map(([key, value]) => { return renderQuotaCard(key, value); }) .join(""); return `

Usage Quotas

${quotaCards}
`; } /** * Renders a single quota card. * @param {string} title - The name of the quota (e.g., 'chat'). * @param {object} details - The details object for the quota. * @returns {string} HTML string for a single card. */ function renderQuotaCard(title, details) { const { entitlement, remaining, percent_remaining, unlimited } = details; const percentUsed = unlimited ? 0 : 100 - percent_remaining; const used = unlimited ? "N/A" : (entitlement - remaining).toLocaleString(); let progressBarColor = "var(--color-green)"; if (percentUsed > 75) progressBarColor = "var(--color-yellow)"; if (percentUsed > 90) progressBarColor = "var(--color-red)"; if (unlimited) progressBarColor = "var(--color-blue)"; return `

Welcome!

Enter an API endpoint URL and click "Fetch" to see usage data.

`; } ``` -------------------------------- ### Get Current Copilot Token Source: https://context7.com/ericc-ch/copilot-api/llms.txt Returns the active Copilot bearer token used for upstream requests. This is useful for debugging or direct access to the Copilot API. ```sh curl -s http://localhost:4141/token | jq . # Expected: # { "token": "tid=...;exp=...;..." } ``` -------------------------------- ### List Available Models with Copilot API Source: https://context7.com/ericc-ch/copilot-api/llms.txt Retrieve a list of all available models accessible through the Copilot API. The response is formatted similarly to the OpenAI API. ```bash curl -s http://localhost:4141/v1/models \ -H "Authorization: Bearer dummy" | jq . ``` -------------------------------- ### Build Docker Image with GitHub Token Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Build a Docker image for the Copilot API proxy, embedding a GitHub token during the build process. Replace 'your_github_token_here' with your actual token. ```sh docker build --build-arg GH_TOKEN=your_github_token_here -t copilot-api . ``` -------------------------------- ### Lint Project with ESLint Source: https://github.com/ericc-ch/copilot-api/blob/master/AGENTS.md Applies linting rules defined in @echristian/eslint-config to check code quality and style. Run this to auto-fix many style issues. ```bash bun run lint ``` -------------------------------- ### Run Docker Container with Options Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Run the Copilot API proxy in a Docker container with additional command-line options, such as enabling verbose output and specifying the port. ```sh docker run -p 4141:4141 -e GH_TOKEN=your_token copilot-api start --verbose --port 4141 ``` -------------------------------- ### List available models Source: https://context7.com/ericc-ch/copilot-api/llms.txt Returns the list of Copilot models available to the authenticated account, in OpenAI list format. ```APIDOC ## GET /v1/models — List available models ### Description Returns the list of Copilot models available to the authenticated account, in OpenAI list format. ### Method GET ### Endpoint /v1/models ### Request Example ```sh curl -s http://localhost:4141/v1/models \ -H "Authorization: Bearer dummy" | jq . ``` ### Response #### Success Response (200) - **object** (string) - Type of the response object. - **data** (array) - List of available models. - **id** (string) - Model identifier. - **object** (string) - Type of the model object. - **type** (string) - Type of the model. - **created** (integer) - Model creation timestamp. - **owned_by** (string) - The organization that owns the model. - **display_name** (string) - User-friendly name for the model. - **has_more** (boolean) - Indicates if there are more models to list. ``` -------------------------------- ### POST /v1/chat/completions Source: https://context7.com/ericc-ch/copilot-api/llms.txt Accepts an OpenAI Chat Completions payload and proxies it to GitHub Copilot. Supports streaming via SSE, tool/function calling, and image inputs. ```APIDOC ## POST /v1/chat/completions ### Description Accepts an OpenAI Chat Completions payload and proxies it to GitHub Copilot. Supports streaming via SSE, tool/function calling, image inputs, and automatically sets `max_tokens` from the model's capabilities if omitted. ### Method POST ### Endpoint /v1/chat/completions ### Request Body - **model** (string) - Required - The model to use for generation. - **messages** (array) - Required - An array of message objects representing the conversation history. - **role** (string) - Required - The role of the message sender (e.g., "system", "user", "assistant"). - **content** (string) - Required - The content of the message. - **stream** (boolean) - Optional - Whether to stream the response. - **tools** (array) - Optional - A list of tools the model may call. - **tool_choice** (object) - Optional - Controls how the tools are called. ### Request Example ```sh # Non-streaming request curl -s http://localhost:4141/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer dummy" \ -d '{ \ "model": "gpt-4o", \ "messages": [ \ {"role": "system", "content": "You are a helpful assistant."}, \ {"role": "user", "content": "What is 2+2?"} \ ] \ }' | jq . ``` ### Response #### Success Response (200) - **id** (string) - Unique identifier for the completion. - **object** (string) - Type of object returned (e.g., "chat.completion"). - **created** (integer) - Unix timestamp of creation. - **model** (string) - The model used for the completion. - **choices** (array) - A list of completion choices. - **index** (integer) - Index of the choice. - **message** (object) - The message content. - **role** (string) - The role of the message sender. - **content** (string) - The content of the message. - **finish_reason** (string) - The reason the model stopped generating tokens. #### Response Example ```json { "id": "chatcmpl-abc123", "object": "chat.completion", "created": 1714000000, "model": "gpt-4o", "choices": [{ "index": 0, "message": { "role": "assistant", "content": "2+2 equals 4." }, "finish_reason": "stop" }] } ``` ``` -------------------------------- ### Build Docker Image Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Build the Docker image for the Copilot API proxy. This command creates a Docker image tagged as 'copilot-api'. ```sh docker build -t copilot-api . ``` -------------------------------- ### Run All Tests with Bun Source: https://github.com/ericc-ch/copilot-api/blob/master/AGENTS.md Executes all test files within the project using Bun's built-in test runner. Ensure tests are located in the 'tests/' directory and named with '*.test.ts'. ```bash bun test ``` -------------------------------- ### Test Single File with Bun Source: https://github.com/ericc-ch/copilot-api/blob/master/AGENTS.md Runs tests for a specific file. Useful for focused testing during development. Provide the relative path to the test file. ```bash bun test tests/claude-request.test.ts ``` -------------------------------- ### Run Docker Container with GitHub Token Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Run the Copilot API proxy in a Docker container, providing the GitHub token via an environment variable. This is an alternative to volume mounting for authentication. ```sh docker run -p 4141:4141 -e GH_TOKEN=your_github_token_here copilot-api ``` -------------------------------- ### Display Debug Information Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Show debug information for troubleshooting purposes. ```bash npx copilot-api@latest debug ``` -------------------------------- ### Run Copilot API with npx and Custom Port Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Run the Copilot API proxy using npx, specifying a custom port for the service. This allows you to avoid port conflicts. ```sh npx copilot-api@latest start --port 8080 ``` -------------------------------- ### Streaming Chat Completions with Copilot API Source: https://context7.com/ericc-ch/copilot-api/llms.txt Make a streaming request to the chat completions endpoint. The response will be in Server-Sent Events (SSE) format. ```bash curl -s http://localhost:4141/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer dummy" \ -d '{ "model": "gpt-4o", "messages": [{"role": "user", "content": "Count to 3"}], "stream": true }' ``` -------------------------------- ### Create Embeddings with Copilot API Source: https://context7.com/ericc-ch/copilot-api/llms.txt Generate embeddings for input text. This endpoint proxies requests to GitHub Copilot's embeddings service and returns results in OpenAI format. ```bash curl -s http://localhost:4141/v1/embeddings \ -H "Content-Type: application/json" \ -H "Authorization: Bearer dummy" \ -d '{ "model": "text-embedding-3-small", "input": ["Hello world", "Another sentence"] }' | jq '{model: .model, count: (.data | length), dims: (.data[0].embedding | length)}' ``` -------------------------------- ### Wait on Rate Limit Hit Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Instead of returning an error when the rate limit is hit, configure the server to wait using the --wait flag in conjunction with --rate-limit. ```bash npx copilot-api@latest start --rate-limit 30 --wait ``` -------------------------------- ### Tool Use with Anthropic Messages API Source: https://context7.com/ericc-ch/copilot-api/llms.txt Configure tool use for the Anthropic-compatible messages endpoint by providing tool definitions and specifying 'tool_choice'. ```bash curl -s http://localhost:4141/v1/messages \ -H "Content-Type: application/json" \ -H "x-api-key: dummy" \ -d '{ "model": "claude-sonnet-4", "max_tokens": 512, "messages": [{"role": "user", "content": "Search for news about AI"}], "tools": [{ "name": "web_search", "description": "Search the web", "input_schema": { "type": "object", "properties": { "query": { "type": "string" } }, "required": ["query"] } }], "tool_choice": {"type": "auto"} }' | jq .content ``` -------------------------------- ### Create embeddings Source: https://context7.com/ericc-ch/copilot-api/llms.txt Proxies an embedding request directly to GitHub Copilot's embeddings endpoint and returns the result in OpenAI format. ```APIDOC ## POST /v1/embeddings — Create embeddings ### Description Proxies an embedding request directly to GitHub Copilot's embeddings endpoint and returns the result in OpenAI format. ### Method POST ### Endpoint /v1/embeddings ### Parameters #### Request Body - **model** (string) - Required - The ID of the model to use for embedding. - **input** (array of strings) - Required - The input texts to embed. ### Request Example ```sh curl -s http://localhost:4141/v1/embeddings \ -H "Content-Type: application/json" \ -H "Authorization: Bearer dummy" \ -d { "model": "text-embedding-3-small", "input": ["Hello world", "Another sentence"] } | jq '{model: .model, count: (.data | length), dims: (.data[0].embedding | length)}' ``` ### Response #### Success Response (200) - **model** (string) - The ID of the model used for embedding. - **data** (array) - A list of embedding objects. - **object** (string) - Type of the object. - **embedding** (array of floats) - The embedding vector. - **index** (integer) - The index of the input text. - **usage** (object) - Usage statistics for the request. - **prompt_tokens** (integer) - The number of tokens in the prompt. - **total_tokens** (integer) - The total number of tokens processed. ``` -------------------------------- ### Render Loading Spinner Source: https://github.com/ericc-ch/copilot-api/blob/master/pages/index.html Generates HTML for a centered loading spinner. Uses Tailwind CSS classes for animation and styling. ```javascript function renderSpinner() { return `
`; } ``` -------------------------------- ### Proxy Chat Completions Request Source: https://context7.com/ericc-ch/copilot-api/llms.txt Accepts an OpenAI Chat Completions payload and proxies it to GitHub Copilot. Supports streaming via SSE, tool/function calling, and image inputs. Automatically sets max_tokens if omitted. ```sh # Non-streaming request curl -s http://localhost:4141/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer dummy" \ -d '{ "model": "gpt-4o", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is 2+2?"} ] }' | jq . ``` ```json # Expected response: # { # "id": "chatcmpl-abc123", # "object": "chat.completion", # "created": 1714000000, # "model": "gpt-4o", # "choices": [{ # "index": 0, ``` -------------------------------- ### Tool/Function Calling with Copilot API Source: https://context7.com/ericc-ch/copilot-api/llms.txt Utilize tool/function calling by defining tools in the request payload. The API will determine if a tool should be called based on the 'tool_choice' parameter. ```bash curl -s http://localhost:4141/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4o", "messages": [{"role": "user", "content": "What is the weather in Paris?"}], "tools": [{ "type": "function", "function": { "name": "get_weather", "description": "Get current weather", "parameters": { "type": "object", "properties": { "location": { "type": "string" } }, "required": ["location"] } } }], "tool_choice": "auto" }' | jq .choices[0].message.tool_calls ``` -------------------------------- ### Set Rate Limit for Copilot API Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Configure the rate limit to control the frequency of requests. Specify the time in seconds between requests using the --rate-limit flag. ```bash npx copilot-api@latest start --rate-limit 30 ``` -------------------------------- ### Display Debug Information in JSON Format Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Output debug information in JSON format for easier parsing and integration with other tools. ```bash npx copilot-api@latest debug --json ``` -------------------------------- ### OpenAI Compatible Endpoints Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md These endpoints mimic the OpenAI API structure for chat completions, model listing, and embeddings. ```APIDOC ## POST /v1/chat/completions ### Description Creates a model response for the given chat conversation. ### Method POST ### Endpoint /v1/chat/completions ### Request Body - **model** (string) - Required - The model to use for generating the response. - **messages** (array) - Required - A list of messages comprising the conversation so far. - **temperature** (number) - Optional - Controls randomness. Lower values make the output more focused and deterministic. - **stream** (boolean) - Optional - Whether to stream back partial progress. If set, messages will be sent as server-sent events. ### Response #### Success Response (200) - **id** (string) - Unique identifier for the response. - **object** (string) - Type of object returned, e.g., `chat.completion`. - **created** (integer) - Unix timestamp of when the response was created. - **model** (string) - The model used for the response. - **choices** (array) - A list of completion choices. - **usage** (object) - Usage statistics for the request. #### Response Example ```json { "id": "chatcmpl-123", "object": "chat.completion", "created": 1677652288, "model": "copilot-model", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Hello! How can I help you today?" }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 10, "completion_tokens": 20, "total_tokens": 30 } } ``` ``` ```APIDOC ## GET /v1/models ### Description Lists the currently available models. ### Method GET ### Endpoint /v1/models ### Response #### Success Response (200) - **data** (array) - A list of available models. #### Response Example ```json { "data": [ { "id": "copilot-model-1", "object": "model", "created": 1677652288, "owned_by": "copilot" }, { "id": "copilot-model-2", "object": "model", "created": 1677652288, "owned_by": "copilot" } ] } ``` ``` ```APIDOC ## POST /v1/embeddings ### Description Creates an embedding vector representing the input text. ### Method POST ### Endpoint /v1/embeddings ### Request Body - **model** (string) - Required - The model to use for generating embeddings. - **input** (string or array) - Required - The text or list of texts to generate embeddings for. - **encoding_format** (string) - Optional - The format of the embeddings to return. Can be `float` or `base64`. ### Response #### Success Response (200) - **data** (array) - A list of embedding objects. - **model** (string) - The model used for generating embeddings. - **usage** (object) - Usage statistics for the request. #### Response Example ```json { "data": [ { "embedding": [ 0.0023064255007047176, -0.009327298752632141, 0.014648332870542526, // ... more dimensions ], "index": 0, "object": "embedding" } ], "model": "copilot-embedding-model", "usage": { "prompt_tokens": 5, "total_tokens": 5 } } ``` ``` -------------------------------- ### Debug Copilot API Proxy Source: https://context7.com/ericc-ch/copilot-api/llms.txt Outputs diagnostic information for troubleshooting, including version, runtime, file paths, and token existence. Use the --json flag for scriptable output. ```sh npx copilot-api@latest debug ``` ```sh # Plain output: # copilot-api debug # Version: 0.7.0 # Runtime: bun 1.2.10 (linux x64) # Paths: # - APP_DIR: /home/user/.local/share/copilot-api # - GITHUB_TOKEN_PATH: /home/user/.local/share/copilot-api/github-token # Token exists: Yes ``` ```sh # JSON output (useful for scripting) npx copilot-api@latest debug --json # { # "version": "0.7.0", # "runtime": { "name": "bun", "version": "1.2.10", "platform": "linux", "arch": "x64" }, # "paths": { "APP_DIR": "...", "GITHUB_TOKEN_PATH": "..." }, # "tokenExists": true # } ``` -------------------------------- ### Configure Claude Code via CLI Flag Source: https://context7.com/ericc-ch/copilot-api/llms.txt Interactively prompts for model selection and generates a shell command to configure environment variables for Claude Code. The command is then copied to the clipboard. ```sh npx copilot-api@latest start --claude-code # Prompts: # ? Select a model to use with Claude Code › gpt-4o # ? Select a small model to use with Claude Code › gpt-4o-mini # ✔ Copied Claude Code command to clipboard! # # Paste into a new terminal (bash/zsh example): # export ANTHROPIC_BASE_URL=http://localhost:4141 ANTHROPIC_AUTH_TOKEN=dummy \ # ANTHROPIC_MODEL=gpt-4o ANTHROPIC_DEFAULT_SONNET_MODEL=gpt-4o \ # ANTHROPIC_SMALL_FAST_MODEL=gpt-4o-mini ANTHROPIC_DEFAULT_HAIKU_MODEL=gpt-4o-mini \ # DISABLE_NON_ESSENTIAL_MODEL_CALLS=1 CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 && claude ``` -------------------------------- ### debug — Print diagnostic information Source: https://context7.com/ericc-ch/copilot-api/llms.txt Outputs version, runtime, file paths, and token existence for troubleshooting purposes. Can output in plain text or JSON format. ```APIDOC ## debug ### Description Outputs version, runtime, file paths, and token existence for troubleshooting. ### Usage ```sh npx copilot-api@latest debug # Plain output: copilot-api debug Version: 0.7.0 Runtime: bun 1.2.10 (linux x64) Paths: - APP_DIR: /home/user/.local/share/copilot-api - GITHUB_TOKEN_PATH: /home/user/.local/share/copilot-api/github-token Token exists: Yes # JSON output (useful for scripting) npx copilot-api@latest debug --json # { # "version": "0.7.0", # "runtime": { "name": "bun", "version": "1.2.10", "platform": "linux", "arch": "x64" }, # "paths": { "APP_DIR": "...", "GITHUB_TOKEN_PATH": "..." }, # "tokenExists": true # } ``` ``` -------------------------------- ### Run Docker Container with Persistent Data Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Run the Copilot API proxy in a Docker container, mapping a host directory for persistent storage of authentication data. This ensures your GitHub token and related data survive container restarts. ```sh mkdir -p ./copilot-data docker run -p 4141:4141 -v $(pwd)/copilot-data:/root/.local/share/copilot-api copilot-api ``` -------------------------------- ### Usage Monitoring Endpoints Source: https://github.com/ericc-ch/copilot-api/blob/master/README.md Endpoints for monitoring your Copilot usage and quotas. ```APIDOC ## GET /usage ### Description Get detailed Copilot usage statistics and quota information. ### Method GET ### Endpoint /usage ### Response #### Success Response (200) - **usage** (object) - Object containing usage details. - **quota** (object) - Object containing quota information. #### Response Example ```json { "usage": { "requests": 150, "tokens": 30000 }, "quota": { "requests_limit": 500, "tokens_limit": 100000 } } ``` ``` ```APIDOC ## GET /token ### Description Get the current Copilot token being used by the API. ### Method GET ### Endpoint /token ### Response #### Success Response (200) - **token** (string) - The current Copilot token. #### Response Example ```json { "token": "gho_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" } ``` ``` -------------------------------- ### Fetch Data from API Source: https://github.com/ericc-ch/copilot-api/blob/master/pages/index.html Handles fetching data from a given URL, including error handling and state updates. Use this function to retrieve data asynchronously. ```javascript async function fetchData() { const url = endpointUrlInput.value.trim(); if (!url) { console.error("Endpoint URL cannot be empty."); state.isLoading = false; render(); return; } state.isLoading = true; state.error = null; render(); try { const response = await fetch(url); if (!response.ok) { throw new Error( `Request failed with status ${response.status}: ${response.statusText}` ); } const jsonData = await response.json(); state.data = jsonData; } catch (error) { console.error("Fetch error:", error); state.data = null; state.error = error.message; } finally { state.isLoading = false; render(); } } ``` -------------------------------- ### Render Detailed Data Section Source: https://github.com/ericc-ch/copilot-api/blob/master/pages/index.html Renders the detailed information section of the API response using the `formatObject` utility. Includes a heading with an icon and a bordered container for the formatted data. ```javascript function renderDetailedData(data) { const formattedDetails = formatObject(data); return `

Detailed Information

${formattedDetails}
`; } ```