Errors and limits

Versión en español: vignette("errors-and-limits-es", package = "ellmercodex").

library(ellmercodex)

ChatGPT plan usage is not the same as the OpenAI API: it is a preview with its own limits, and some API features are not available. This article lists what is not supported and shows how to handle errors in code that runs unattended, such as scheduled scripts or Shiny apps.

What is not supported

ellmercodex supports interactive use of one conversation at a time through ellmer’s Chat object (ellmer 0.5.1 or later). These are not supported:

Plan limits and supported features may change while the preview lasts.

Handle errors

ellmercodex signals structured conditions, so your code can react to the kind of error without parsing messages:

tryCatch(
  chat$chat("Hello"),
  codex_auth_error = function(error) {
    message("Authentication failed; run codex_login() again.")
  },
  codex_usage_limit_error = function(error) {
    message("The ChatGPT plan's usage limit was reached; try again later.")
  },
  codex_network_error = function(error) {
    message("Network error; check your connection and retry.")
  },
  codex_protocol_changed_error = function(error) {
    message("The upstream protocol may have changed; update ellmercodex.")
  },
  error = function(error) {
    message("The request failed: ", conditionMessage(error))
  }
)

Handle the most specific condition first. The main classes are:

The full list is in ?ellmercodex-conditions.

What error messages contain

Messages are sanitized before they are signaled. They do not intentionally include raw response bodies, bearer tokens, authorization codes, OAuth state, account identifiers, or credential-store contents, so it is safe to log them.