npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

cloud-code-ai-provider

v0.1.0

Published

Google Cloud Code provider for the AI SDK

Readme

Google Cloud Code Provider for AI SDK

The Google Cloud Code Provider enables you to use Google's Gemini models through the Cloud Code API with the AI SDK. This provider includes built-in OAuth authentication for free access to Gemini models, similar to the Vertex AI provider but optimized for development tools and IDE integrations.

Installation

pnpm add cloud-code-ai-provider

Provider Instance

You can import the default provider instance googleCloudCode from cloud-code-ai-provider:

import { googleCloudCode } from 'cloud-code-ai-provider';

Example

import { googleCloudCode } from 'cloud-code-ai-provider';
import { generateText } from 'ai';

const { text } = await generateText({
  model: googleCloudCode('gemini-2.5-flash'),
  prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});

Authentication

This provider supports multiple authentication methods:

1. Built-in OAuth (Default)

The provider includes built-in OAuth support using the same credentials as the official Gemini CLI:

import { createGoogleCloudCode } from 'cloud-code-ai-provider';

// Uses OAuth by default
const provider = createGoogleCloudCode();

2. Direct Access Token

If you have an access token from another source:

const provider = createGoogleCloudCode({
  accessToken: 'your-oauth-access-token',
  projectId: 'your-project-id',
  useOAuth: false, // Disable built-in OAuth
});

3. Pre-existing OAuth Credentials

Use credentials from a previous OAuth flow:

const provider = createGoogleCloudCode({
  credentials: {
    access_token: 'token',
    refresh_token: 'refresh-token',
    expiry_date: Date.now() + 3600000, // 1 hour
  },
});

Managing Authentication

The provider exports authentication utilities:

import { GoogleCloudCodeAuth } from 'cloud-code-ai-provider';

// Run the complete OAuth flow with browser authentication
await GoogleCloudCodeAuth.authenticate();

// Force re-authentication
await GoogleCloudCodeAuth.authenticate({ force: true });

// Use custom credential directory
await GoogleCloudCodeAuth.authenticate({ 
  credentialDirectory: '.myapp/credentials' 
});

// Check if authenticated
const isAuth = await GoogleCloudCodeAuth.isAuthenticated();

// Get user info
const userInfo = await GoogleCloudCodeAuth.getUserInfo();
console.log(`Authenticated as: ${userInfo.email}`);

// Check current authentication
const token = await GoogleCloudCodeAuth.getAccessToken();
const projectId = await GoogleCloudCodeAuth.getProjectId();

// Set credentials programmatically
await GoogleCloudCodeAuth.setCredentials({
  access_token: 'token',
  refresh_token: 'refresh',
  expiry_date: Date.now() + 3600000,
});

// Set custom credential directory (default: ~/.gemini)
GoogleCloudCodeAuth.setCredentialDirectory('.myapp/credentials');

// Clear cached credentials
await GoogleCloudCodeAuth.clearCache();

Credential Storage

By default, credentials are stored in ~/.gemini/oauth_creds.json. You can customize this:

// Option 1: Via provider settings
const provider = createGoogleCloudCode({
  credentialDirectory: '.myapp/auth', // Will use ~/.myapp/auth/oauth_creds.json
});

// Option 2: Via environment variable
// Set GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json

// Option 3: Programmatically
GoogleCloudCodeAuth.setCredentialDirectory('.custom-dir');

Language Models

You can create models that call the Google Cloud Code API using the provider instance:

const model = googleCloudCode('gemini-2.5-flash');

Available Models

Currently, only the following models work with Google Cloud Code:

  • gemini-2.5-flash - Fast, efficient model for most tasks
  • gemini-2.5-pro - More capable model for complex tasks

Model Capabilities

| Model | Image Input | Object Generation | Tool Usage | Tool Streaming | |-------|-------------|-------------------|------------|----------------| | gemini-2.5-flash | No* | Yes | Yes | Yes | | gemini-2.5-pro | No* | Yes | Yes | Yes |

*Note: Image input is not currently supported by the Cloud Code API

Model Settings

The models support various settings:

const model = googleCloudCode('gemini-2.5-flash', {
  safetySettings: [
    {
      category: 'HARM_CATEGORY_DANGEROUS_CONTENT',
      threshold: 'BLOCK_LOW_AND_ABOVE'
    }
  ],
  useSearchGrounding: false,
  topK: 40,
});

Integration with OpenCode

This provider is designed to work seamlessly with OpenCode and similar development tools:

// OpenCode handles the OAuth flow internally
const provider = createGoogleCloudCode();

// The provider automatically uses OpenCode's authentication
const result = await generateText({
  model: provider('gemini-2.5-flash'),
  prompt: 'Hello, world!',
});

Differences from Vertex AI Provider

| Feature | Cloud Code Provider | Vertex AI Provider | |---------|--------------------|--------------------| | Authentication | OAuth (built-in) | Service Account/ADC | | Cost | Free with OAuth | Standard API pricing | | Models | Gemini only | Gemini + Anthropic + Imagen | | Image Generation | No | Yes | | Text Embeddings | No | Yes | | Use Case | Development tools | Production apps |

Environment Variables

  • GOOGLE_CLOUD_PROJECT - Override the auto-detected project ID
  • CODE_ASSIST_ENDPOINT - Custom Cloud Code API endpoint

Changelog

0.1.0

  • Added built-in OAuth authentication support
  • Integrated with Code Assist API for automatic user onboarding
  • Support for multiple authentication methods
  • Export authentication utilities for advanced use cases

0.0.1

  • Initial release with support for Gemini models via Cloud Code API