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

@microfox/ai-provider-google

v1.3.2

Published

A Wrapped Google AI Provider for Vercels AI SDK

Readme

Note: This package is deprecated and will no longer be maintained. Please consider using an alternative.

Google AI Provider for Vercel's AI SDK

A comprehensive TypeScript SDK for interacting with Google AI's REST API endpoints, enabling seamless integration with various AI models for text generation, embeddings, and image creation.

Installation

npm install @microfox/ai-provider-google

Usage

Text Generation

import { GoogleAiProvider } from '@microfox/ai-provider-google';
import { generateText } from 'ai';

// Initialize the provider
const provider = new GoogleAiProvider({
  apiKey: process.env.GOOGLE_API_KEY!,
});

const { text } = await generateText({
  model: provider.languageModel('gemini-1.5-pro'),
  prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});

console.log(text);

Text Embedding

import { GoogleAiProvider } from '@microfox/ai-provider-google';
import { embed } from 'ai';

const provider = new GoogleAiProvider({
  apiKey: process.env.GOOGLE_API_KEY!,
});

const { embedding } = await embed({
  model: provider.textEmbeddingModel('text-embedding-004'),
  value: 'Hello, world!',
});

console.log(embedding);

Image Generation

import { GoogleAiProvider } from '@microfox/ai-provider-google';
import { generateImage } from 'ai';

const provider = new GoogleAiProvider({
  apiKey: process.env.GOOGLE_API_KEY!,
});

const { imageUrl } = await generateImage({
  model: provider.imageModel('imagen-3.0-generate-002'),
  prompt: 'A comic book style cat dreaming of code.',
});

console.log(imageUrl);

Configuration Options

GoogleAiProvider Options

interface GoogleAiProviderConfig {
  apiKey: string;
  headers?: Record<string, string>;
}

Model Options

You can pass model-specific options to the generateText and generateImage functions.

Language Models

  • gemini-2.5-pro-preview-05-06
  • gemini-1.5-pro
  • gemini-1.5-flash
  • and others.

Additional settings like temperature, maxOutputTokens, topP, topK, safetySettings can be passed.

Embedding Models

  • text-embedding-004
  • embedding-001

Image Generation Models

  • imagen-3.0-generate-002
  • gemini-2.0-flash-preview-image-generation

Error Handling

The provider includes built-in error handling for common API issues.

try {
  const { text } = await generateText({
    model: provider.languageModel('gemini-1.5-pro'),
    prompt: 'Hello, world!',
  });
} catch (error) {
  if (error instanceof Error) {
    console.error('Google AI API Error:', error.message);
  }
}

Best Practices

  1. Security: Always store your API key in environment variables.
  2. Error Handling: Implement proper error handling for API calls.
  3. Model Selection: Use appropriate model versions for your use case.
  4. Rate-limiting: Be mindful of rate limits and potential costs.
  5. Caching: Implement caching strategies for production environments to improve performance and reduce costs.

License

MIT