TheOpenAIR 0.2.0
A broad overhaul: safer helpers, classed errors, retries, stateful chats that no longer lose or corrupt history, tools and structured outputs, and fewer dependencies. Several changes break existing code; read “Breaking changes” before upgrading.
Breaking changes
- The default model is now
"gpt-5.4-mini"(was"gpt-3.5-turbo"). SetOPENAI_MODEL(an empty value counts as unset) or passmodelto use another one.gpt-5.4-minirejectsmax_tokens,stopandlogit_bias(the API answers 400, raised asopenair_api_error): usemax_completion_tokensinstead ofmax_tokens, or set another model. - R 4.1.0 or later and httr2 1.2.0 or later are required, because the HTTP layer now uses httr2 instead of httr (MOD-6).
-
chat_completion()never returnsNULL. A failed request raises a classed error instead:openair_api_errorfor an HTTP error (fieldsstatus,type,code,api_message),openair_network_errorfor a connection failure or timeout,openair_invalid_responsefor a body that is not JSON. All inheritopenair_error, sotryCatch(..., openair_error = function(e) ...)catches them all. - Helpers that write files no longer change their input:
refactor()writes<name>_refactored.<ext>andadd_roxygen()writes<name>_documented.<ext>next to the original. An existing output file is not replaced unless you passoverwrite = TRUE(checked before the API is called, so a refused write costs nothing);overwritecomes after...and must be named. Output that fails its check (R or Python that does not parse, documentation without#'lines, …) is never written; the error (openair_invalid_output) carries the text in itsoutputfield. - Given a string or URL, every helper returns its result visibly and writes nothing; given a file, it returns the output path invisibly.
java_to_r()no longer prints its result. -
write_test()writestests/testthat/test-<name>.Rfor a file in a package’sR/directory, otherwise a siblingtest-<name>.R(was<name>-test.R), and opens it in the editor only in interactive sessions. -
add_roxygen()documents each top-level function separately (one request per function) and skips functions that already have a roxygen block. -
extract_entities()returns a tibble of character columns and writes nothing. -
write_code()andedit_code()refuse to run outside an interactive session, keep one conversation per file by default (chatlog_id = NULL), and write only code: a fenced code block, or a reply that is entirely R code, never prose.write_code()no longer empties an existing file; it needsoverwrite = TRUEto replace one. The text around the code is shown as a message, whichsuppressMessages()silences. - A reply cut off by
max_completion_tokens,max_tokensor by a content filter (finish_reason"length"or"content_filter") is never written or returned by a helper: it raisesopenair_incomplete_response.chat()andregenerate()keep such a reply and warn. -
chat()andregenerate()refusen > 1; usechat_completion()for several completions. - Chatlogs store only the
roleandcontentof each message. Extra fields a provider sends (refusals, annotations, reasoning content, tool calls) are no longer stored or sent back with the next request. -
clear_chatlog()keeps the system message(s) and removes the rest. Looking up a chatlog that does not exist is a classed error naming the stored ids. -
stream = TRUEinchat_completion()is an error (streaming was never supported and silently returned a normal response); streaming is planned for a later release.best_ofis deprecated and ignored. -
functionsandfunction_callinchat_completion()are deprecated in favour oftoolsandtool_choice. They still work, with a warning, and are sent astools/tool_choice; they are no longer limited to the retired-0613models. Afunction_call(ortool_choice) without any tools is sent too, with a warning, since the OpenAI API rejects it. - No longer exported (they remain internal):
clean_output(),replace_file_extension(),extract_blocks(),extract_blocks_content(),extract_r_code(),contains_r_func(),contains_roxygen(),df_to_csv(),split_text(),read_text_batches()andinitialize_messages(). - The prompt templates (
python_to_r_promptand friends) are no longer package datasets, and thetrumpdataset is gone. - The tiktoken token counters and the reticulate dependency are removed, so installing the package no longer pulls in Python tooling.
count_tokens()remains as an offline approximation. -
clean_output(), used by every helper, keeps the text inside code blocks exactly as the model wrote it and joins several blocks with a blank line;python_to_r(),r_to_python()andjava_to_r()no longer strip words from the start of their output. - The helpers keep their input argument names (
py,r,java,file,filename,text,references); a later release may unify them.
Security
-
is_r()only parses its input andis_python()only checks the syntax with Python’sastmodule: neither runs the code any more. Before, checking a user’s script or a model’s reply executed it in your session (SEC-1, SEC-2). -
chat()prints replies verbatim. Text such as{Sys.getpid()}in a reply was evaluated by cli before (SEC-3). -
is_python()no longer passesOPENAI_API_KEYto the Python process. - The API key is redacted when a request is printed, and is never part of an error message.
- A key sent over plain
http(or a base URL without a scheme) to a host that is not local gives a warning, once per host and session. -
openai_api_key()trims and checks the key; its help and the README recommend~/.Renvironand show how to enter the key without typing it into a script.
New features
-
chat_completion()gainstoolsandtool_choice. A reply that calls tools is returned intact, and the newtool_calls()returns its calls as a data.frame (id,type,name,arguments).?tool_callsshows how to send the tools’ results back in a follow-up request.chat()stores such a reply as an empty message with a warning naming the tools. -
chat_completion()gainsresponse_format("json_object", or a JSON schema for structured outputs),seed,max_completion_tokens(needed by OpenAI’s reasoning models;max_tokensis still sent asmax_tokensfor other providers),reasoning_effort, andextra_body, a named list of request fields applied last, for any field the package has no argument for; each of its fields replaces the field of that name as a whole, andNULLremoves one. -
chat_completion()accepts a single string as a user message, sendslogit_biasas a JSON object, and sends numbers at full precision. - Requests time out (
options(TheOpenAIR.timeout = 120), in seconds) and are retried on rate limits (429), server errors (5xx) and connection failures with exponential backoff (options(TheOpenAIR.max_tries = 3)). ARetry-Afterheader is honoured, in seconds or as a date. - Any OpenAI-compatible provider works through
OPENAI_BASE_URL, including local servers such as Ollama or vLLM without a key; a full.../chat/completionsURL is accepted. -
list_chatlogs()lists the stored chatlogs anddelete_chatlog()removes one. Chatlogs print their id and messages.add_to_chatlog()can append one chatlog to another. -
read_text(),count_tokens()and the helpers decide in one way whether their input is text, a file or a URL, warn when text looks like a file path that does not exist, and stop on an HTTP error instead of reading the error page. -
NEWS.md(this file).
Bug fixes
-
python_to_r()sent the R-to-Python prompt; it now asks for R code. -
chat()no longer leaves an unanswered user message in the log when a request fails, andregenerate()no longer deletes history on failure: both change the stored log only after a valid reply. - A reply without text content no longer breaks
chat()’s console output. - Chatlog ids created in the same second no longer collide, and an id such as
"c"no longer finds a base R function. -
extract_entities()sends each batch (it sent the whole input every time), joins lines with newlines, and reads the model’s CSV reply as text. -
add_roxygen()places each block above its own function. -
refactor()no longer overwrites its input with commented-out old code. -
nested_to_pipe()counts its token limit on the text it actually sends. - Empty or blank input stops every helper before a paid request.
- The helpers report token usage only when the provider sends it.
-
read_text_batches(),split_text(),extract_r_code(),extract_roxygen2(),contains_r_func()andparse_response()handle vectors, CRLF line endings and edge cases correctly. -
is_json()andis_xml()judge their input as text and never read it as a path or URL. -
is_python()finds a working Python on Windows. It triespython3,pythonand thepylauncher, in that order, and skips a candidate that cannot run Python, such as the Microsoft Store alias Windows puts on thePATH; before, that alias madeis_python()returnNAfor every input even with Python installed. The interpreter is chosen once per session; a candidate that does not answer within 10 seconds (a slow first start) is tried again on the next call rather than ruled out. -
created()accepts any numeric timestamp and returns a UTC date-time. -
dplyr,readr,lubridate,stringr,R.utilsanddata.tableare no longer needed;jsonliteis now a declared dependency (installs without it used to fail at run time). - Help pages: return values documented, examples that run, links to the current OpenAI API reference.
