Minimal wrapper around the Generative Language API ':generateContent' endpoint for text prompts, with retries, exponential backoff, clearer errors, and optional output compilation (HTML/DOCX) with auto-open.
gemini_generate(
prompt,
model = "gemini-2.5-flash",
api_key = Sys.getenv("GEMINI_API_KEY"),
user_agent = NULL,
base_url = "https://generativelanguage.googleapis.com/v1beta",
temperature = NULL,
top_p = NULL,
top_k = NULL,
max_output_tokens = NULL,
stop_sequences = NULL,
system_instruction = NULL,
safety_settings = NULL,
seed = NULL,
timeout = 120,
verbose = FALSE,
max_tries = 5,
backoff_base = 0.8,
backoff_cap = 8,
force_markdown = TRUE,
compile_to = c("none", "html", "docx")
)If compile_to = "none": character scalar (raw text as returned by the API). If compile_to = "html": list(markdown = <string>, html_path = <path>), and opens the HTML. If compile_to = "docx": list(markdown = <string>, docx_path = <path>), and opens the DOCX.
Character scalar. The user prompt (plain text).
Character scalar. Gemini model id (e.g., "gemini-2.5-flash", "gemini-2.5-pro"). You may also pass "models/..." and it will be normalized.
Character scalar. API key. Defaults to env var 'GEMINI_API_KEY'.
Character scalar. If NULL, a dynamic value is used.
Character scalar. API base URL.
Optional numeric in [0, 2].
Optional numeric in (0, 1].
Optional integer >= 1.
Optional integer > 0.
Optional character vector.
Optional character scalar.
Optional list passed as-is to the API.
Optional integer seed.
Numeric seconds for request timeout (default 120).
Logical; if TRUE, prints URL/retries.
Integer. Max attempts (default 5).
Numeric. Initial backoff seconds (default 0.8).
Numeric. Max backoff seconds (default 8).
Logical. If TRUE, instructs the model to answer in Markdown.
Character scalar. One of c("none","html","docx").