Creates an OpenAIConfig object which can be passed to create_agent()
Usage
config_OpenAI(
model_name,
temperature = TEMPERATURE_DEFAULT,
base_url = OPENAI_URL_DEFAULT,
api_key = NULL,
api_key_env = OPENAI_API_KEY_ENV_DEFAULT,
keychain_service = NULL,
organization = NULL,
project = NULL,
timeout = OPENAI_TIMEOUT_DEFAULT,
extra_headers = NULL,
extra_body = NULL,
zero_data_retention = NULL,
enable_thinking = NULL,
validate_model = FALSE
)Arguments
- model_name
Character: The name of the LLM model to use.
- temperature
Numeric [0, 2]: The temperature for the model.
- base_url
Character: Base URL of the OpenAI-compatible server.
- api_key
Optional character: API key.
- api_key_env
Character: Environment variable containing the API key.
- keychain_service
Optional character: macOS Keychain service containing the API key.
- organization
Optional character: OpenAI organization id.
- project
Optional character: OpenAI project id.
- timeout
Numeric (0, Inf): Request timeout in seconds.
- extra_headers
Optional list: Additional HTTP headers.
- extra_body
Optional list: Additional request body fields.
- zero_data_retention
Optional logical: Whether to require OpenRouter to route each request only to a zero-data-retention endpoint. Supported only with an OpenRouter base URL.
- enable_thinking
Optional logical: Whether to enable model thinking for compatible local servers.
- validate_model
Logical: Whether to validate model availability using the models endpoint.
Details
With zero_data_retention = TRUE, each OpenRouter request includes
provider.zdr = true. OpenRouter will then consider only endpoints with a ZDR policy. This
option does not activate account-level ZDR at OpenAI, Anthropic, or other providers.
Examples
cfg <- config_OpenAI(
model_name = "local-model",
temperature = 0.4,
base_url = "http://localhost:1234/v1/",
validate_model = FALSE
)
# Require an OpenRouter endpoint that does not retain prompts or responses:
openrouter_cfg <- config_OpenAI(
model_name = "inclusionai/ling-3.0-flash-fin:free",
base_url = "https://openrouter.ai/api/v1",
api_key_env = "OPENROUTER_API_KEY",
zero_data_retention = TRUE,
validate_model = FALSE
)