R/setAPI.R

Defines functions setAPI

Documented in setAPI

#' @title Set API key
#' @description Set API key as an environment variable
#' @param api_key The API key to set
#' @return No return value, called for side effects.
#' @export
#' @examples
#' \dontrun{
#' setAPI("my_api_key")
#' }
#' @seealso https://makersuite.google.com/app/apikey
#' @note Please be aware you have to agree to the terms of service of the API provider.
#' Any app that uses the API key is subject to the terms of service.
#' Also, please be aware that the API key is a sensitive information.
#' @importFrom cli cli_alert_info cli_div cli_end cli_alert
#' @keywords internal

setAPI <- function(api_key) {
  last <- substr(api_key, nchar(api_key) - 3, nchar(api_key))
  Sys.setenv(GEMINI_API_KEY = api_key)

  cli_div(theme = list(span.str = list("background-color" = "blue")))
  cli_alert_info("API key {.str ...{last}} is set.")
  cli_end()

  cli_alert("You may try {.run gemini_chat('What is CRAN?')}")
  return(NULL)
}

Try the gemini.R package in your browser

Any scripts or data that you put into this service are public.

gemini.R documentation built on April 11, 2025, 6:11 p.m.