Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

gemini-ai

> AI 编程
Open source

A Ruby Gem for interacting with Gemini through Vertex AI, Generative Language API, or AI Studio, Google's generative AI services.

188 stars0 likes1 views
WebsiteGitHub

About

A Ruby Gem for interacting with Gemini through Vertex AI, Generative Language API, or AI Studio, Google's generative AI services.

Gemini AI

A Ruby Gem for interacting with Gemini through Vertex AI, Generative Language API, or AI Studio, Google's generative AI services.

This Gem is designed to provide low-level access to Gemini, enabling people to build abstractions on top of it. If you are interested in more high-level abstractions or more user-friendly tools, you may want to consider Nano Bots .

TL;DR and Quick Start

ruby
gem 'gemini-ai', '~> 4.3.0'
…

Google now supports a global endpoint:

ruby
Gemini.new(credentials: { region: 'global' })

Result:

…

Index

  • TL;DR and Quick Start
  • Index
  • Setup
    • Installing
    • Credentials
      • Option 1: API Key (Generative Language API)
      • Option 2: Service Account Credentials File (Vertex AI API)
      • Option 3: Application Default Credentials (Vertex AI API)
      • Required Data
    • Custom Version
    • Global Endpoint
  • Available Models
  • Usage
    • Client
    • Methods
      • Chat
        • stream_generate_content
          • Receiving Stream Events
          • Without Events
        • generate_content
      • Embeddings
        • predict
        • embed_content
    • Modes
      • Text
      • Image
      • Video
    • Streaming vs. Server-Sent Events (SSE)
      • Server-Sent Events (SSE) Hang
      • Non-Streaming
    • Back-and-Forth Conversations
    • Safety Settings
    • System Instructions
    • Counting Tokens
    • JSON Format Responses
      • JSON Schema
      • Models That Support JSON
    • Tools (Functions) Calling
    • New Functionalities and APIs
    • Request Options
      • Adapter
      • Timeout
    • Error Handling
      • Rescuing
      • For Short
      • Errors
  • Development
    • Purpose
    • Publish to RubyGems
    • Updating the README
  • Resources and References
  • Disclaimer

Setup

Installing

bash
gem install gemini-ai -v 4.3.0
bash
gem 'gemini-ai', '~> 4.3.0'

Credentials

  • Option 1: API Key (Generative Language API)
  • Option 2: Service Account Credentials File (Vertex AI API)
  • Option 3: Application Default Credentials (Vertex AI API)
  • Required Data

⚠️ DISCLAIMER: Be careful with what you are doing, and never trust others' code related to this. These commands and instructions alter the level of access to your Google Cloud Account, and running them naively can lead to security risks as well as financial risks. People with access to your account can use it to steal data or incur charges. Run these commands at your own responsibility and due diligence; expect no warranties from the contributors of this project.

Option 1: API Key (Generative Language API)

You need a Google Cloud Project, and then you can generate an API Key through the Google Cloud Console here.

You also need to enable the Generative Language API service in your Google Cloud Console, which can be done here.

Alternatively, you can generate an API Key through Google AI Studio here. However, this approach will automatically create a project for you in your Google Cloud Account.

Option 2: Service Account Credentials File (Vertex AI API)

You need a Google Cloud Project and a Service Account to use Vertex AI API.

After creating them, you need to enable the Vertex AI API for your project by clicking Enable here: Vertex AI API.

You can create credentials for your Service Account here, where you will be able to download a JSON file named google-credentials.json that should have content similar to this:

json
{
  "type": "service_account",
  "project_id": "YOUR_PROJECT_ID",
  "private_key_id": "a00...",
  "private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
  "client_email": "PROJECT_ID@PROJECT_ID.iam.gserviceaccount.com",
  "client_id": "000...",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/..."
}

You need to have the necessary policies (roles/aiplatform.user and possibly roles/ml.admin) in place to use the Vertex AI API.

You can add them by navigating to the IAM Console and clicking on the "Edit principal" (✏️ pencil icon) next to your Service Account.

Alternatively, you can add them through the gcloud CLI as follows:

bash
gcloud projects add-iam-policy-binding PROJECT_ID \
  --member='serviceAccount:PROJECT_ID@PROJECT_ID.iam.gserviceaccount.com' \
  --role='roles/aiplatform.user'

Some people reported having trouble accessing the API, and adding the role roles/ml.admin fixed it:

bash
gcloud projects add-iam-policy-binding PROJECT_ID \
  --member='serviceAccount:PROJECT_ID@PROJECT_ID.iam.gserviceaccount.com' \
  --role='roles/ml.admin'

If you are not using a Service Account:

bash
gcloud projects add-iam-policy-binding PROJECT_ID \
  --member='user:[email protected]' \
  --role='roles/aiplatform.user'

gcloud projects add-iam-policy-binding PROJECT_ID \
  --member='user:[email protected]' \
  --role='roles/ml.admin'

Option 3: Application Default Credentials (Vertex AI API)

Similar to Option 2, but you don't need to download a google-credentials.json. Application Default Credentials automatically find credentials based on the application environment.

For local development, you can generate your default credentials using the gcloud CLI as follows:

bash
gcloud auth application-default login

For more details about alternative methods and different environments, check the official documentation: Set up Application Default Credentials

Required Data

After choosing an option, you should have all the necessary data and access to use Gemini.

Option 1, for API Key:

ruby
{
  service: 'generative-language-api',
  api_key: 'GOOGLE_API_KEY'
}

Remember that hardcoding your API key in code is unsafe; it's preferable to use environment variables:

ruby
{
  service: 'generative-language-api',
  api_key: ENV['GOOGLE_API_KEY']
}

Option 2: For the Service Account, provide a google-credentials.json file and a REGION:

ruby
{
  service: 'vertex-ai-api',
  file_path: 'google-credentials.json',
  region: 'us-east4'
}

Alternatively, you can pass the file contents instead of the path:

ruby
{
  service: 'vertex-ai-api',
  file_contents: File.read('google-credentials.json'),
  region: 'us-east4'
}
ruby
{
  service: 'vertex-ai-api',
  file_contents: ENV['GOOGLE_CREDENTIALS_FILE_CONTENTS'],
  region: 'us-east4'
}

Option 3: For Application Default Credentials, omit both the api_key and the file_path:

ruby
{
  service: 'vertex-ai-api',
  region: 'us-east4'
}

As of the writing of this README, the following regions support Gemini:

Iowa (us-central1)
Las Vegas, Nevada (us-west4)
Montréal, Canada (northamerica-northeast1)
Northern Virginia (us-east4)
Oregon (us-west1)
Seoul, Korea (asia-northeast3)
Singapore (asia-southeast1)
Tokyo, Japan (asia-northeast1)

You can follow here if new regions are available: Gemini API

You might want to explicitly set a Google Cloud Project ID, which you can do as follows:

ruby
{
  service: 'vertex-ai-api',
  project_id: 'PROJECT_ID'
}

Custom Version

By default, the gem uses the v1 version of the APIs. You may want to use a different version:

…

Global Endpoint

Google now supports a global endpoint:

ruby
Gemini.new(credentials: { region: 'global' })

Available Models

These models are accessible to the repository author as of June 2025 in the us-east4 region. Access to models may vary by region, user, and account. All models here are expected to work, if you can access them. This is just a reference of what a "typical" user may expect to have access to right away:

Model Vertex AI Generative Language
gemini-pro-vision ✅
gemini-pro ✅ ✅
gemini-1.5-pro-preview-0514 ✅
gemini-1.5-pro-preview-0409 ✅
gemini-1.5-pro ✅ ✅
gemini-1.5-flash-preview-0514 ✅
gemini-1.5-flash ✅ ✅
gemini-1.0-pro-vision-latest
gemini-1.0-pro-vision-001 ✅
gemini-1.0-pro-vision ✅
gemini-1.0-pro-latest ✅
gemini-1.0-pro-002 ✅
gemini-1.0-pro-001 ✅ ✅
gemini-1.0-pro ✅ ✅
gemini-ultra
gemini-1.0-ultra
gemini-1.0-ultra-001

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyaideepmindgeminigemini-ai

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
CategoryAI 编程
PricingOpen source

> Related tools

G
GitHub Copilot
GitHub 官方 AI 编程助手,覆盖补全、Chat 与 Agent 模式。
C
Cursor
AI 原生代码编辑器,对话改代码、多文件 Agent 与规则体系是其核心。
S
skills
Skills for Real Engineers. Straight from my .agents directory.