Overview
Several providers require OAuth authentication instead of static API keys:- Anthropic - Claude Pro/Max subscription
- OpenAI Codex - ChatGPT Plus/Pro subscription (access to GPT-5.x Codex models)
- GitHub Copilot - Copilot subscription
- Google Gemini CLI - Gemini 2.0/2.5 via Google Cloud Code Assist (free tier or paid)
- Antigravity - Free Gemini 3, Claude, GPT-OSS via Google Cloud
OAuth Providers
The toolkit includes built-in OAuth support for these providers.getOAuthProvider()
Get an OAuth provider by ID:OAuthProviderId
required
Provider identifier:
'anthropic', 'openai-codex', 'github-copilot', 'google-gemini-cli', or 'google-antigravity'.getOAuthProviders()
Get all registered OAuth providers:registerOAuthProvider()
Register a custom OAuth provider:OAuthProviderInterface
Interface for OAuth provider implementations:string
Unique provider identifier.
string
Human-readable provider name.
function
Initiate login flow and return credentials to persist.
boolean
Whether login uses a local callback server and supports manual code input.
function
Refresh expired credentials and return updated credentials to persist.
function
Convert credentials to API key string for the provider.
function
Optional: Modify models for this provider (e.g., update baseUrl).
Login Flow
Each provider has a dedicated login function.loginAnthropic()
loginOpenAICodex()
loginGitHubCopilot()
loginGeminiCli()
loginAntigravity()
OAuthLoginCallbacks
Callbacks for handling the login flow:(info: OAuthAuthInfo) => void
required
Called when authentication URL is ready. Display URL and instructions to user.
(prompt: OAuthPrompt) => Promise<string>
required
Called when user input is needed. Return the user’s response.
(message: string) => void
Optional progress updates during login.
() => Promise<string>
Optional callback for manual authorization code input (when callback server fails).
AbortSignal
Optional abort signal to cancel login.
Login Example
Token Management
OAuthCredentials
Credentials returned by login and refresh functions:getOAuthApiKey()
Get API key from credentials, automatically refreshing if expired:OAuthProviderId
required
The OAuth provider ID.
Record<string, OAuthCredentials>
required
Map of provider IDs to credentials.
{ newCredentials: OAuthCredentials; apiKey: string } | null
Returns updated credentials and API key, or
null if no credentials found.Error if refresh fails.
Example
refreshOAuthToken()
Manually refresh a token:Provider-Specific Functions
GitHub Copilot
getGitHubCopilotBaseUrl()
Get the base URL for GitHub Copilot API:proxy-ep field, or constructs from enterprise domain.
normalizeDomain()
Normalize domain input for enterprise GitHub:Google Cloud
refreshGoogleCloudToken()
Refresh Google Cloud OAuth tokens (Gemini CLI and Antigravity):CLI Tool
The quickest way to authenticate is via the CLI:auth.json in the current directory.
Environment Variables
Some providers support environment variable auth as an alternative to OAuth:Provider Notes
OpenAI Codex
Requires ChatGPT Plus or Pro subscription. Provides access to GPT-5.x Codex models with extended context windows and reasoning. The library automatically handles session-based prompt caching whensessionId is provided in stream options.
Set transport option to "sse", "websocket", or "auto" for transport selection. WebSocket connections with sessionId are reused per session and expire after 5 minutes of inactivity.
Azure OpenAI
Azure OpenAI uses API key auth, not OAuth. SetAZURE_OPENAI_API_KEY and either AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME.
Use AZURE_OPENAI_API_VERSION to override API version (defaults to v1).
Deployment names are treated as model IDs by default. Override with azureDeploymentName option or AZURE_OPENAI_DEPLOYMENT_NAME_MAP using comma-separated pairs like gpt-4o-mini=my-deployment,gpt-4o=prod.
GitHub Copilot
If you get “The requested model is not supported” error:- Open VS Code
- Open Copilot Chat
- Click the model selector
- Select the model (it will show a warning icon)
- Click “Enable”
Google Gemini CLI / Antigravity
These use Google Cloud OAuth. TheapiKey returned by getOAuthApiKey() is a JSON string containing both the token and project ID.
For paid Cloud Code Assist subscriptions, set GOOGLE_CLOUD_PROJECT or GOOGLE_CLOUD_PROJECT_ID to your project ID.