opencode-antigravity-auth

raw JSON →
1.6.0 verified Sat Apr 25 auth: no javascript

opencode-antigravity-auth v1.6.0 is an OAuth authentication plugin for the OpenCode IDE, providing access to Google Antigravity services including Gemini 3 Pro and Claude 4.6 models. It handles credential management, token refresh, and request signing. Released in 2025, it follows a monthly release cadence with beta releases for testing. Key differentiators are its deep integration with OpenCode's plugin system and support for the latest Google Antigravity API features. Requires Node >=20 and TypeScript ^5 as a peer dependency. Ships bundled TypeScript definitions.

error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/opencode-antigravity-auth/index.mjs not supported.
cause Trying to require() an ESM-only package in a CommonJS project.
fix
Use dynamic import: const antigravityAuth = await import('opencode-antigravity-auth');
error TypeError: auth.generateAuthUrl is not a function
cause configureAuth was called without clientId or redirectUri, causing generateAuthUrl to not be attached.
fix
Ensure the config object includes both clientId and redirectUri.
error Error: Cannot find module 'opencode-antigravity-auth'
cause The package is not installed or is not in node_modules.
fix
Run npm install opencode-antigravity-auth
error TypeError: Cannot destructure property 'accessToken' of 'tokens' as it is undefined.
cause exchangeCode was called without a valid authorization code, or the code expired.
fix
Verify the authorization code is fresh and passed correctly.
breaking Since v1.6.0, the configureAuth function requires an explicit scopes array; previously it defaulted to ['openid']. Scripts relying on the default will fail at runtime.
fix Pass a scopes array explicitly: configureAuth({ scopes: ['openid', 'email'] })
breaking In v1.6.0, generateAuthUrl now throws if clientId or redirectUri is missing (was previously ignored).
fix Ensure both clientId and redirectUri are provided in the configuration object.
deprecated The getToken method is deprecated in v1.6.0; use exchangeCode instead.
fix Replace getToken(code) with exchangeCode(code).
gotcha The package uses a .mjs extension for ESM. If your project is CJS, you must use dynamic import() or switch to ESM.
fix Use import() syntax: const antigravityAuth = await import('opencode-antigravity-auth');
gotcha User tokens are stored in ~/.cache/opencode by default. Clearing this cache will log out the user.
fix To avoid logout, do not delete the cache directory unless intentionally resetting credentials.
npm install opencode-antigravity-auth
yarn add opencode-antigravity-auth
pnpm add opencode-antigravity-auth

Shows standard OAuth flow: initialize plugin, generate auth URL, exchange code, and make authenticated API request.

import antigravityAuth from 'opencode-antigravity-auth';

// Initialize the auth plugin with required configuration
const auth = antigravityAuth({
  clientId: process.env.GOOGLE_CLIENT_ID ?? '',
  clientSecret: process.env.GOOGLE_CLIENT_SECRET ?? '',
  redirectUri: 'http://localhost:3000/callback',
  scopes: ['openid', 'email', 'profile'],
});

// Generate the authorization URL
const authUrl = auth.generateAuthUrl();
console.log('Open the following URL in your browser:', authUrl);

// After redirect, exchange the code for tokens
const tokens = await auth.exchangeCode('authorization-code-from-query');
console.log('Access token:', tokens.accessToken);

// Use the tokens to make authenticated requests
const response = await auth.request('/api/gemini', {
  method: 'POST',
  body: JSON.stringify({ prompt: 'Hello' }),
});
console.log('API response:', await response.json());