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

@izumiapi/gemini-api

v1.0.2

Published

A module to connect to gemini api.

Readme

@izumiapi/gemini-api

🚧 This package is currently in testing/maintenance phase 🚧

A simple and lightweight wrapper for Google's Gemini AI API that provides session-based chat functionality with automatic conversation history management.

Features

  • 💬 Session-based chat conversations
  • 📝 Automatic conversation history tracking
  • 🔒 Secure API key handling
  • 🚀 Easy to use and integrate
  • 📦 Lightweight with minimal dependencies

Installation

npm install @izumiapi/gemini-api

Quick Start

import { ConnectToGemini } from '@izumiapi/gemini-api';

// Initialize with your Google AI API key
const gemini = new ConnectToGemini({
    apiKey: 'your-google-ai-api-key'
});

// Start chatting with session management
const response = await gemini.chatSession({
    idSesi: 'user123',
    chat: 'Hello, how are you?'
});

console.log(response.result);

API Reference

Constructor

new ConnectToGemini({ apiKey })

Parameters:

  • apiKey (string, required): Your Google AI API key

Methods

chatSession({ idSesi, chat })

Send a message and get a response while maintaining conversation history.

Parameters:

  • idSesi (string, required): Unique session identifier for conversation tracking
  • chat (string, required): The message to send to Gemini

Returns:

{
    success: true,
    result: "AI response text",
    sessions: [...] // Complete conversation history
}

Usage Examples

Basic Chat

const gemini = new ConnectToGemini({
    apiKey: process.env.GOOGLE_AI_API_KEY
});

try {
    const response = await gemini.chatSession({
        idSesi: 'session-001',
        chat: 'Explain quantum computing in simple terms'
    });
    
    console.log('AI Response:', response.result);
    console.log('Conversation History:', response.sessions);
} catch (error) {
    console.error('Error:', error.message);
}

Multiple Sessions

// Different users with separate conversation histories
const user1Response = await gemini.chatSession({
    idSesi: 'user-1',
    chat: 'What is JavaScript?'
});

const user2Response = await gemini.chatSession({
    idSesi: 'user-2', 
    chat: 'How to cook pasta?'
});

// Continue user-1's conversation
const user1Followup = await gemini.chatSession({
    idSesi: 'user-1',
    chat: 'Can you give me an example?'
});

Environment Variables

Create a .env file:

GOOGLE_AI_API_KEY=your_actual_api_key_here
import dotenv from 'dotenv';
dotenv.config();

const gemini = new ConnectToGemini({
    apiKey: process.env.GOOGLE_AI_API_KEY
});

Getting Your API Key

  1. Visit Google AI Studio
  2. Sign in with your Google account
  3. Create a new API key
  4. Copy the key and use it in your application

⚠️ Security Note: Never expose your API key in client-side code or commit it to version control. Always use environment variables.

Error Handling

The package includes built-in error handling for common scenarios:

try {
    const response = await gemini.chatSession({
        idSesi: 'test-session',
        chat: 'Hello world!'
    });
    console.log(response.result);
} catch (error) {
    if (error.message.includes('session ID')) {
        console.error('Session ID is required');
    } else if (error.message.includes('message')) {
        console.error('Chat message is required');
    } else {
        console.error('Unexpected error:', error.message);
    }
}

Model Information

This package uses the gemini-2.0-flash-001 model, which provides:

  • Fast response times
  • High-quality text generation
  • Multi-turn conversation support

Limitations

  • Currently in testing/maintenance phase
  • Requires valid Google AI API key
  • Internet connection required
  • Subject to Google AI API rate limits and quotas

Development Status

🚧 Testing/Maintenance Phase

This package is actively being tested and maintained. Features may change, and we recommend:

  • Testing thoroughly in development environments
  • Checking for updates regularly
  • Reporting issues on our repository

Support

For questions, issues, or feature requests, please open an issue on our GitHub repository.


Note: This package is not officially affiliated with Google. Google AI and Gemini are trademarks of Google LLC.