| OpenAILanguageModel | R Documentation |
Language model implementation for OpenAI's chat completions API. Exported so that OpenAI-compatible providers in companion packages (e.g. aisdk.providers) can inherit from it across package boundaries.
aisdk::LanguageModelV1 -> OpenAILanguageModel
new()Initialize the OpenAI language model.
OpenAILanguageModel$new(model_id, config, capabilities = list())
model_idThe model ID (e.g., "gpt-4o").
configConfiguration list with api_key, base_url, headers, etc.
capabilitiesOptional list of capability flags.
get_config()Get the configuration list.
OpenAILanguageModel$get_config()
A list with provider configuration.
build_payload()Build the request payload for non-streaming generation. Subclasses can override to customize payload construction.
OpenAILanguageModel$build_payload(params)
paramsA list of call options.
A list with url, headers, and body.
execute_request()Execute the API request.
OpenAILanguageModel$execute_request( url, headers, body, timeout_seconds = NULL, total_timeout_seconds = NULL, first_byte_timeout_seconds = NULL, connect_timeout_seconds = NULL, idle_timeout_seconds = NULL )
urlThe API endpoint URL.
headersA named list of HTTP headers.
bodyThe request body.
timeout_secondsLegacy alias for total_timeout_seconds.
total_timeout_secondsOptional total request timeout override in seconds.
first_byte_timeout_secondsOptional time-to-first-byte timeout override in seconds.
connect_timeout_secondsOptional connection timeout override in seconds.
idle_timeout_secondsOptional stall timeout override in seconds.
The parsed API response.
parse_response()Parse the API response into a GenerateResult. Subclasses can override to extract provider-specific fields (e.g., reasoning_content).
OpenAILanguageModel$parse_response(response)
responseThe parsed API response.
A GenerateResult object.
do_generate()Generate text (non-streaming). Uses template method pattern.
OpenAILanguageModel$do_generate(params)
paramsA list of call options including messages, temperature, etc.
A GenerateResult object.
build_stream_payload()Build the request payload for streaming generation. Subclasses can override to customize stream payload construction.
OpenAILanguageModel$build_stream_payload(params)
paramsA list of call options.
A list with url, headers, and body.
do_stream()Generate text (streaming).
OpenAILanguageModel$do_stream(params, callback)
paramsA list of call options.
callbackA function called for each chunk: callback(text, done).
A GenerateResult object.
format_tool_result()Format a tool execution result for OpenAI's API.
OpenAILanguageModel$format_tool_result(tool_call_id, tool_name, result_content)
tool_call_idThe ID of the tool call.
tool_nameThe name of the tool (not used by OpenAI but kept for interface consistency).
result_contentThe result content from executing the tool.
A list formatted as a message for OpenAI's API.
get_history_format()Get the message format for OpenAI.
OpenAILanguageModel$get_history_format()
clone()The objects of this class are cloneable with this method.
OpenAILanguageModel$clone(deep = FALSE)
deepWhether to make a deep clone.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.