Skip to content

CopilotTokenManager

Category: Providers

Source: copilot_token_manager.dart

Exchanges long-lived GitHub OAuth tokens for short-lived Copilot tokens, caches the result in [CredentialStore], and refreshes on expiry.

GitHub Copilot issues a ~30-minute token that authorizes requests against api.githubcopilot.com. This module is the single source of truth for "give me a valid Copilot bearer" — every LLM request funnels through it.

Classes

abstract CopilotFields

Field keys stored under providers.copilot in credentials.json.

Properties

PropertyTypeDescription
githubTokenconst
copilotTokenconst
expiresAtconst

CopilotAuthException

Constructor

dart
CopilotAuthException(this.message)

Properties

PropertyTypeDescription
messageString

Methods

String toString()

CopilotTokenExchange

Constructor

dart
const CopilotTokenExchange({required this.token, required this.expiresAt})

Properties

PropertyTypeDescription
tokenString
expiresAtDateTime

Functions

`Future<CopilotTokenExchange> exchangeGithubTokenForCopilotToken(

String githubToken, { http.Client? client, })`

POST the Copilot token endpoint with the user's GitHub token. Returns the short-lived Copilot bearer plus its expiry timestamp.

Constants

NameTypeDescription
copilotClientIdStringMatches OpenCode / VS Code / LiteLLM / copilot-api. It's the public GitHub OAuth app id for the Copilot CLI; everyone uses it.

Released under the MIT License.