Skip to contents

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"). Set OPENAI_MODEL (an empty value counts as unset) or pass model to use another one. gpt-5.4-mini rejects max_tokens, stop and logit_bias (the API answers 400, raised as openair_api_error): use max_completion_tokens instead of max_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 returns NULL. A failed request raises a classed error instead: openair_api_error for an HTTP error (fields status, type, code, api_message), openair_network_error for a connection failure or timeout, openair_invalid_response for a body that is not JSON. All inherit openair_error, so tryCatch(..., openair_error = function(e) ...) catches them all.
  • Helpers that write files no longer change their input: refactor() writes <name>_refactored.<ext> and add_roxygen() writes <name>_documented.<ext> next to the original. An existing output file is not replaced unless you pass overwrite = TRUE (checked before the API is called, so a refused write costs nothing); overwrite comes 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 its output field.
  • 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() writes tests/testthat/test-<name>.R for a file in a package’s R/ directory, otherwise a sibling test-<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() and edit_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 needs overwrite = TRUE to replace one. The text around the code is shown as a message, which suppressMessages() silences.
  • A reply cut off by max_completion_tokens, max_tokens or by a content filter (finish_reason "length" or "content_filter") is never written or returned by a helper: it raises openair_incomplete_response. chat() and regenerate() keep such a reply and warn.
  • chat() and regenerate() refuse n > 1; use chat_completion() for several completions.
  • Chatlogs store only the role and content of 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 = TRUE in chat_completion() is an error (streaming was never supported and silently returned a normal response); streaming is planned for a later release. best_of is deprecated and ignored.
  • functions and function_call in chat_completion() are deprecated in favour of tools and tool_choice. They still work, with a warning, and are sent as tools/tool_choice; they are no longer limited to the retired -0613 models. A function_call (or tool_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() and initialize_messages().
  • The prompt templates (python_to_r_prompt and friends) are no longer package datasets, and the trump dataset 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() and java_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 and is_python() only checks the syntax with Python’s ast module: 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 passes OPENAI_API_KEY to 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 ~/.Renviron and show how to enter the key without typing it into a script.

New features

  • chat_completion() gains tools and tool_choice. A reply that calls tools is returned intact, and the new tool_calls() returns its calls as a data.frame (id, type, name, arguments). ?tool_calls shows 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() gains response_format ("json_object", or a JSON schema for structured outputs), seed, max_completion_tokens (needed by OpenAI’s reasoning models; max_tokens is still sent as max_tokens for other providers), reasoning_effort, and extra_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, and NULL removes one.
  • chat_completion() accepts a single string as a user message, sends logit_bias as 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)). A Retry-After header 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/completions URL is accepted.
  • list_chatlogs() lists the stored chatlogs and delete_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, and regenerate() 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() and parse_response() handle vectors, CRLF line endings and edge cases correctly.
  • is_json() and is_xml() judge their input as text and never read it as a path or URL.
  • is_python() finds a working Python on Windows. It tries python3, python and the py launcher, in that order, and skips a candidate that cannot run Python, such as the Microsoft Store alias Windows puts on the PATH; before, that alias made is_python() return NA for 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.utils and data.table are no longer needed; jsonlite is 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.