| llm_config | R Documentation |
llm_config() builds a provider-agnostic configuration object that
call_llm() (and friends) understand. You can pass provider-specific
parameters via ...; LLMR forwards them as-is, with a few safe conveniences.
llm_config(
provider,
model,
api_key = NULL,
troubleshooting = FALSE,
base_url = NULL,
embedding = NULL,
no_change = FALSE,
...
)
provider |
Character scalar naming the backend. Known providers:
When |
model |
Character scalar. Model name understood by the chosen provider.
(e.g., |
api_key |
Provider API key. Preferred form is |
troubleshooting |
Logical. If |
base_url |
Optional character. Back-compat alias; if supplied it is
stored as |
embedding |
|
no_change |
Logical. If |
... |
Additional model parameters. LLMR understands a small canonical set spelled the OpenAI way and translates it per provider, so you can keep one vocabulary across backends:
|
An object of class c("llm_config", provider). Fields:
provider, model, api_key, troubleshooting, embedding,
no_change, and model_params (a named list of extras). print() masks
the API key.
Three optional functions in ... customize the HTTP exchange when a
provider needs something unusual (a gateway header, an exotic body field, a
nonstandard response envelope). All are applied on every request for every
provider:
request_modifier: function(body) -> body, edits the JSON body
before serialization (OpenAI-compatible chat paths).
req_builder: function(req) -> req, edits the httr2 request
(headers, URL, auth) just before it is performed.
response_modifier: function(content) -> content, edits the
parsed JSON before LLMR interprets it.
Anthropic temperatures must be in [0, 1]; others in [0, 2]. Out-of-range
values are clamped with a warning. Reasoning or thinking-oriented models may
reject custom temperature values; omit temperature unless the selected
model accepts it.
You can pass api_url (or base_url= alias) in ... to point to gateways
or compatible proxies.
Use provider = "gemini", vertex = TRUE for Gemini on Vertex AI. Supply
project and optionally location; when api_key is omitted, LLMR looks for
VERTEX_ACCESS_TOKEN and sends it as a Bearer token.
call_llm,
call_llm_robust,
llm_chat_session,
call_llm_par,
get_batched_embeddings
## Not run:
# Basic OpenAI config
cfg <- llm_config("openai", "gpt-4.1-nano",
temperature = 0.7, max_tokens = 300)
# Generative call returns an llmr_response object
r <- call_llm(cfg, "Say hello in Greek.")
print(r)
as.character(r)
# Embeddings (inferred from the model name)
e_cfg <- llm_config("gemini", "gemini-embedding-001")
# Force embeddings even if model name does not contain "embedding"
e_cfg2 <- llm_config("voyage", "voyage-3.5-lite", embedding = TRUE)
# Gemini through Vertex AI. VERTEX_ACCESS_TOKEN should contain a Bearer token.
v_cfg <- llm_config(
"gemini", "gemini-2.5-flash-lite",
vertex = TRUE,
project = "my-gcp-project",
location = "us-central1",
api_key = "VERTEX_ACCESS_TOKEN"
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.