The GitHub Copilot SDK supports multiple authentication methods to fit different use cases. Choose the method that best matches your deployment scenario.
| Method | Use Case | Copilot Subscription Required |
|---|---|---|
| GitHub Signed-in User | Interactive apps where users sign in with GitHub | Yes |
| OAuth GitHub App | Apps acting on behalf of users via OAuth | Yes |
| Environment Variables | CI/CD, automation, server-to-server | Yes |
| BYOK (Bring Your Own Key) | Using your own API keys (Azure AI Foundry, OpenAI, etc.) | No |
This is the default authentication method when running the Copilot CLI interactively. Users authenticate via GitHub OAuth device flow, and the SDK uses their stored credentials.
How it works:
copilot CLI and signs in via GitHub OAuthSDK Configuration:
import { CopilotClient } from "copilot-sdk-supercharged";
// Default: uses logged-in user credentials
const client = new CopilotClient();
from copilot import CopilotClient
# Default: uses logged-in user credentials
client = CopilotClient()
await client.start()
import copilot "github.com/jeremiahjordanisaacson/copilot-sdk-supercharged/go"
// Default: uses logged-in user credentials
client := copilot.NewClient(nil)
using GitHub.Copilot.SDK;
// Default: uses logged-in user credentials
await using var client = new CopilotClient();
When to use:
Use an OAuth GitHub App to authenticate users through your application and pass their credentials to the SDK. This enables your application to make Copilot API requests on behalf of users who authorize your app.
How it works:
gho_ or ghu_ prefix)githubToken optionSDK Configuration:
import { CopilotClient } from "copilot-sdk-supercharged";
const client = new CopilotClient({
githubToken: userAccessToken, // Token from OAuth flow
useLoggedInUser: false, // Don't use stored CLI credentials
});
from copilot import CopilotClient
client = CopilotClient({
"github_token": user_access_token, # Token from OAuth flow
"use_logged_in_user": False, # Don't use stored CLI credentials
})
await client.start()
import copilot "github.com/jeremiahjordanisaacson/copilot-sdk-supercharged/go"
client := copilot.NewClient(&copilot.ClientOptions{
GithubToken: userAccessToken, // Token from OAuth flow
UseLoggedInUser: copilot.Bool(false), // Don't use stored CLI credentials
})
using GitHub.Copilot.SDK;
await using var client = new CopilotClient(new CopilotClientOptions
{
GithubToken = userAccessToken, // Token from OAuth flow
UseLoggedInUser = false, // Don't use stored CLI credentials
});
Supported token types:
gho_ - OAuth user access tokensghu_ - GitHub App user access tokensgithub_pat_ - Fine-grained personal access tokensNot supported:
ghp_ - Classic personal access tokens (deprecated)When to use:
For automation, CI/CD pipelines, and server-to-server scenarios, you can authenticate using environment variables.
Supported environment variables (in priority order):
COPILOT_GITHUB_TOKEN - Recommended for explicit Copilot usageGH_TOKEN - GitHub CLI compatibleGITHUB_TOKEN - GitHub Actions compatibleHow it works:
SDK Configuration:
No code changes needed—the SDK automatically detects environment variables:
import { CopilotClient } from "copilot-sdk-supercharged";
// Token is read from environment variable automatically
const client = new CopilotClient();
from copilot import CopilotClient
# Token is read from environment variable automatically
client = CopilotClient()
await client.start()
When to use:
BYOK allows you to use your own API keys from model providers like Azure AI Foundry, OpenAI, or Anthropic. This bypasses GitHub Copilot authentication entirely.
Key benefits:
See the BYOK documentation for complete details, including:
When multiple authentication methods are available, the SDK uses them in this priority order:
githubToken - Token passed directly to SDK constructorCAPI_HMAC_KEY or COPILOT_HMAC_KEY environment variablesGITHUB_COPILOT_API_TOKEN with COPILOT_API_URLCOPILOT_GITHUB_TOKEN → GH_TOKEN → GITHUB_TOKENcopilot CLI logingh auth credentialsTo prevent the SDK from automatically using stored credentials or gh CLI auth, use the useLoggedInUser: false option:
const client = new CopilotClient({
useLoggedInUser: false, // Only use explicit tokens
});
client = CopilotClient({
"use_logged_in_user": False, # Only use explicit tokens
})
client := copilot.NewClient(&copilot.ClientOptions{
UseLoggedInUser: copilot.Bool(false), // Only use explicit tokens
})
await using var client = new CopilotClient(new CopilotClientOptions
{
UseLoggedInUser = false, // Only use explicit tokens
});
Can you improve this documentation? These fine people already did:
Jeremiah Isaacson & Patrick NikoletichEdit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |