Skip to main content

OAuth Authentication

Several providers require OAuth authentication instead of static API keys:
  • OpenAI Codex - ChatGPT Plus/Pro subscription (GPT-5.x models with extended reasoning)
  • GitHub Copilot - Copilot subscription (GPT-4o, Claude via GitHub)
  • Google Gemini CLI - Google Cloud Code Assist (Gemini 2.0/2.5, free tier or paid)
  • Antigravity - Free Gemini 3, Claude, GPT-OSS via Google Cloud
  • Vertex AI - Google Cloud Vertex AI (uses Application Default Credentials)
  • Anthropic - Claude Pro/Max subscription (optional, alternative to API key)

Quick Start (CLI)

The fastest way to authenticate:
Credentials are saved to auth.json in the current directory.

OpenAI Codex

Requirements: ChatGPT Plus or Pro subscription Models: gpt-5-mini, gpt-5-nano, gpt-5.1-omni Features: Extended reasoning, session-based caching, WebSocket support

CLI Login

Programmatic Login

Using OpenAI Codex

Session-Based Caching

OpenAI Codex supports automatic prompt caching when using session IDs:

WebSocket vs SSE

OpenAI Codex supports two transport modes:
WebSocket connections with sessionId are reused and expire after 5 minutes of inactivity.

GitHub Copilot

Requirements: GitHub Copilot subscription Models: gpt-4o, claude-3.5-sonnet (via GitHub)

CLI Login

Programmatic Login

Using GitHub Copilot

If you get “model not supported” error, enable the model manually in VS Code:
  1. Open Copilot Chat
  2. Click model selector
  3. Select the model (warning icon)
  4. Click “Enable”

Google Gemini CLI

Requirements: Google account (free tier or paid Cloud Code Assist) Models: gemini-2.0-flash-thinking, gemini-2.5-flash, gemini-2.5-pro

CLI Login

Programmatic Login

Using Google Gemini CLI

For paid Cloud Code Assist subscriptions, set your project ID:

Antigravity

Requirements: Google account Models: Free Gemini 3, Claude, GPT-OSS models via Google Cloud

CLI Login

Programmatic Login

Using Antigravity

Version Override

If Google updates their requirements, override the Antigravity version:

Vertex AI

Requirements: Google Cloud account with Vertex AI enabled Models: Gemini models via Vertex AI Authentication: Application Default Credentials (ADC)

Local Development

Production (Service Account)

Using Vertex AI

Official docs: Application Default Credentials

Anthropic (OAuth)

Requirements: Claude Pro or Max subscription Alternative to: ANTHROPIC_API_KEY

CLI Login

Programmatic Login

Using Anthropic OAuth

You can also use ANTHROPIC_API_KEY environment variable instead of OAuth for standard API access.

Credential Management

The library provides helpers for credential management:

Refresh Expired Tokens

Get API Key (Auto-Refresh)

Environment Variables

For OAuth providers, you can also set tokens via environment variables:

Complete Example

Full OAuth workflow:

Troubleshooting

Token Expired

Use getOAuthApiKey - it automatically refreshes:

Model Not Available

GitHub Copilot: Enable model in VS Code Copilot Chat settings Google Gemini CLI: Ensure you’re logged in with correct account OpenAI Codex: Requires ChatGPT Plus/Pro subscription

Invalid Credentials

Delete auth.json and re-login:

Next Steps

Providers

Explore all supported providers

Streaming

Learn about streaming API