Authentication
The Copilot SDK supports multiple authentication methods. Choose one based on your use case.Authentication methods
For BYOK, see
custom-providers.md.
GitHub login (CLI)
If you are already logged in withcopilot or gh CLI, the SDK uses stored credentials by default.
OAuth GitHub App / PAT
Pass a user access token from OAuth, or a fine-grained PAT, togithub_token.
- Expected token prefixes:
gho_,ghu_,github_pat_ ghp_(classic PAT) is discouraged
github_token, use_logged_in_user is automatically set to false. To override explicitly:
github-token.md.
Both github_token and use_logged_in_user are only available in stdio mode. In TCP mode, the Copilot CLI must already be authenticated.
Environment variables
If you pass a token via environment variables, the CLI auto-detects it using this priority order:COPILOT_GITHUB_TOKENGH_TOKENGITHUB_TOKEN
Authentication priority
The SDK resolves credentials in this order:github_token(explicitly provided)- Environment variable tokens (
COPILOT_GITHUB_TOKEN→GH_TOKEN→GITHUB_TOKEN) - OAuth credentials stored by CLI
- Credentials from
ghCLI
Disable automatic login
If you do not want to use stored credentials, setuse_logged_in_user to false.
github_token, this is supported in stdio mode only. In TCP mode, the Copilot CLI must already be authenticated.
Check authentication status
You can read the result ofauth.getStatus.
Select an account for interactive login
EnumerateloginAccounts through the session RPC to get the stored identities you can reuse with a given provider. Each item’s label is for display, and active indicates whether the identity matches the current session’s active account. accountId is an opaque ID owned by the provider. Pass it to the login request as is, without parsing or modifying it.
mode: 'default' to reuse a stored identity with the provider’s normal behavior. Use mode: 'selectAccount' to explicitly show the provider’s account picker. In that case, don’t pass accountId. Existing calls such as begin(LoginProviderKind::ENTRA) continue to work.
For the latest updates, see the GitHub repository.