# API key should be set in .Renviron before running
Sys.setenv(ART_GEMINI_KEY = ...)
# Verify your configuration with a health check:
artgemini_health_check()Introduction
artgemini provides a streamlined interface to Google’s Gemini API for R users. The package is designed to support two primary use cases:
- Interactive chat workflows - Multi-turn conversations with streaming support via {ellmer} Chat objects
- Single-turn structured output - Low-level API for pipeline tasks with JSON schemas
This guide walks you through the essential workflows to get you started with artgemini.
Installation
pak::pkg_install("artalytics/artgemini")
library(artgemini)Configuration
Before using artgemini, you need to configure your Google Gemini API key. Set the following environment variable:
Interactive Chat
The gemini_chat() function returns an ellmer Chat object for multi-turn conversations.
# Create chat object
chat <- gemini_chat()
# Send messages
chat$chat("Explain the difference between impressionism and expressionism in art.")
# Multi-turn conversation
chat$chat("Which movement came first?")
chat$chat("Name 3 famous impressionist painters.")System Prompts
Set behavioral context with system prompts:
chat <- gemini_chat(sys_prompt = "You are an art historian. Be concise.")
chat$chat("What is Baroque?")Temperature Control
Control output randomness with the temp parameter:
# Deterministic output
chat_det <- gemini_chat(temp = 0)
chat_det$chat("List 5 common art styles as a comma-separated list.")
# Creative output
chat_creative <- gemini_chat(temp = 1.5)
chat_creative$chat("Write a 50 word story about an artist.")Model Selection
Override the default model with the ml parameter:
# Fast responses
chat_fast <- gemini_chat(ml = "gemini-2.5-flash")
chat_fast$chat("Quick question")
# High-quality analysis
chat_pro <- gemini_chat(ml = "gemini-2.5-pro")
chat_pro$chat("Complex analysis task")Single-Turn Structured Output
For pipeline tasks requiring structured JSON output, use gemini_generate():
Vision: Describing Images
Use gemini_describe_image() for image analysis:
# Default prompt
gemini_describe_image(img_path, temp = 0.7)
# Custom analysis prompt
gemini_describe_image(
img_path,
prompt = "Describe the color palette and composition.",
temp = 0
)Tools & Function Calling
Enhance Gemini with tools for grounded search and code execution:
# Google Search grounding
gemini_with_tools(
"What are the latest trends in digital art for 2025?",
tools = list(tool_google_search())
)
# Code execution
gemini_with_tools(
"Calculate the Fibonacci sequence up to the 20th term.",
tools = list(tool_code_execution())
)Next Steps
- Quickstart - Detailed examples of tool usage and advanced patterns
- Function Reference - Complete API documentation
For questions and issues, visit the GitHub repository.
