An unofficial Ruby package for Google Gemini. Easily generate text and images, analyze web content, and integrate Google Search—all with a simple Ruby API.
Add to your Gemfile:
gem 'genai-rb'Then run:
bundle installOr install directly:
gem install genai-rbGet your Gemini API key from Google AI Studio.
Set your API key:
export GEMINI_API_KEY="api_key"Or pass it directly:
require 'genai'
client = Genai.new(api_key: "api_key")response = client.generate_content(contents: "Hello, how are you?")
puts responseresponse = client.generate_content(model_id: "gemini-2.5-flash", contents: "Explain quantum computing.")response = client.generate_content(contents: "Summarize: https://example.com/article", tools: [:url_context])response = client.generate_content(contents: "Latest AI news?", tools: [:google_search, :url_context])client = Genai.new(api_key: "api_key", timeout: 120, max_retries: 5)
response = client.model("gemini-2.0-flash").generate_content(
contents: "Write a creative story about a robot learning to paint",
config: { temperature: 0.8, max_output_tokens: 1000 }
)model = client.model("gemini-2.5-flash")
response = model.generate_content(contents: "Explain the benefits of renewable energy")- All Gemini models
- Text and image generation
- URL context analysis
- Google Search integration
- Multiple model support
- Customizable generation config
- Robust error handling and retry logic
- Simple, intuitive Ruby API
Pull requests are always welcome.
Open source under the MIT License.