← Back to PRs

#4364: fix(github-copilot): use gho_ tokens directly without exchange

by RebelSyntax open 2026-01-30 04:23 View on GitHub →
docs
Tokens from the GitHub Copilot CLI (prefixed with `gho_`) can be used directly with the Copilot API without requiring a token exchange via /copilot_internal/v2/token (which returns HTTP 404 for these tokens). This fixes authentication for users who: - Installed the Copilot CLI (`npm install -g @github/copilot`) - Authenticated via `copilot auth login` - Set COPILOT_GITHUB_TOKEN or GH_TOKEN to their gho_ token The fix detects gho_ prefixed tokens and skips the exchange, caching them with an 8-hour TTL (matching typical OAuth token lifetimes). Also adds COPILOT_API_BASE_URL env var support for enterprise users whose proxy blocks api.individual.githubcopilot.com. Set this to your enterprise endpoint (e.g., https://api.business.githubcopilot.com). [AI-assisted] Tested with GitHub Copilot CLI 0.0.399 on WSL2. Related to #3437 <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR updates the GitHub Copilot token resolution flow to special-case `gho_` tokens (from the Copilot CLI) so they are used directly without calling GitHub’s `/copilot_internal/v2/token` exchange endpoint. It also introduces support for overriding the Copilot API base URL via `COPILOT_API_BASE_URL` (useful for enterprise/proxy scenarios), adds tests for the new behavior, and extends log redaction patterns to cover `gho_` tokens. The change primarily lives in `src/providers/github-copilot-token.ts`, which is used by provider discovery (`src/agents/models-config.providers.ts`) to resolve the correct Copilot base URL and token source, with docs updated to describe the new auth path. <h3>Confidence Score: 3/5</h3> - This PR is mostly safe to merge, but there’s a functional edge case around base URL selection for cached `gho_` tokens and a doc rendering issue. - The core change (skipping token exchange for `gho_` tokens) is small and covered by new unit tests, and log redaction is a straightforward addition. However, the cache-hit path currently ignores `COPILOT_API_BASE_URL`, which can break enterprise setups after the first run, and the docs appear to have escaped code fences which reduces usability. - src/providers/github-copilot-token.ts; docs/providers/github-copilot.md <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs