Sends a message history to the OpenRouter API, which provides access to hundreds of models from different providers through a single OpenAI-compatible endpoint.
openrouter_chat(
.llm,
.model = "anthropic/claude-sonnet-5",
.max_tokens = 2048,
.temperature = NULL,
.top_p = NULL,
.frequency_penalty = NULL,
.presence_penalty = NULL,
.stop = NULL,
.stream = FALSE,
.json_schema = NULL,
.tools = NULL,
.tool_choice = NULL,
.reasoning = NULL,
.provider = NULL,
.route = NULL,
.models = NULL,
.api_url = "https://openrouter.ai",
.timeout = 60,
.verbose = FALSE,
.dry_run = FALSE,
.max_tries = 3,
.max_tool_rounds = 10
)A new LLMMessage object containing the original messages plus the assistant's response.
An LLMMessage object containing the conversation history.
The model identifier to use (default: "google/gemini-3.6-flash").
Any model available on OpenRouter can be used.
Maximum number of tokens in the response (default: 2048).
Controls randomness (0–2, optional).
Nucleus sampling parameter (0–1, optional).
Penalizes repeated tokens (-2 to 2, optional).
Encourages new topics (-2 to 2, optional).
One or more stop sequences (optional).
Logical; if TRUE, streams the response (default: FALSE).
A JSON schema object for structured output (default: NULL).
Either a single TOOL object or a list of TOOL objects for tool calls.
Tool-calling behavior: "none", "auto", or "required" (optional).
A named list controlling reasoning token behavior (optional). Supported fields vary by model family:
effort: one of "xhigh", "high", "medium", "low", "minimal", "none" (OpenAI/Grok)
max_tokens: integer specifying the reasoning token budget (Anthropic/Gemini/Alibaba)
exclude: logical; if TRUE, reasoning is used internally but not returned in the response
enabled: logical; if TRUE, activates reasoning at default settings
Example: list(effort = "high") or list(max_tokens = 4000, exclude = FALSE).
A named list of OpenRouter provider preferences, e.g.
list(order = c("Anthropic", "AWS Bedrock"), allow_fallbacks = TRUE) (optional).
OpenRouter routing strategy; "fallback" routes to the next model if
the primary is unavailable (optional).
A character vector of model IDs to use as fallbacks when the primary
model is unavailable (optional). Used together with .route = "fallback".
Base URL for the OpenRouter API (default: "https://openrouter.ai").
Request timeout in seconds (default: 60).
If TRUE, displays additional information after the API call (default: FALSE).
If TRUE, returns the request object without executing it (default: FALSE).
Maximum retries (default: 3).
Maximum number of tool use iterations (default: 10).