
Chat with an OpenAI-compatible model
Source:R/provider-openai-compatible.R
chat_openai_compatible.RdThis function is for use with OpenAI-compatible APIs, also known as the
chat completions API. If you want to use OpenAI itself, we recommend
chat_openai(), which uses the newer responses API.
Many providers offer OpenAI-compatible APIs, including:
Arguments
- base_url
The base URL to the endpoint. This parameter is required since there is no default for OpenAI-compatible APIs.
- name
The name of the provider; this is shown in
token_usage()and is used to compute costs.- system_prompt
A system prompt to set the behavior of the assistant.
- api_key
- credentials
Credentials to use for authentication. If not provided, will attempt to use the
OPENAI_API_KEYenvironment variable.- model
The model to use for chat. No default; depends on your provider.
- params
Common model parameters, usually created by
params().- api_args
Named list of arbitrary extra arguments appended to the body of every chat API call. Combined with the body object generated by ellmer with
modifyList().- api_headers
Named character vector of arbitrary extra headers appended to every chat API call.
- echo
One of the following options:
none: don't emit any output (default when running in a function).output: echo text and tool-calling output as it streams in (default when running at the console).all: echo all input and output.
Note this only affects the
chat()method.
Value
A Chat object.