Skip to contents

License: MIT CRAN Status

tidyllm is an R package for working with large language model APIs in data analysis workflows. It supports Anthropic Claude, OpenAI, Google Gemini, Mistral, Groq, DeepSeek, OpenRouter, TypeSafe (decision models), local models via Ollama and llama.cpp, and more, all through a single consistent interface.

Features

  • Multiple providers: Switch between cloud and local models using the same verb + provider pattern.
  • Unified media system: Send images, audio, video, and PDFs to any provider that supports them via .media. Upload files to provider servers for reuse via .files and upload_file().
  • Closed questions with probabilities: decide() puts yes/no, choice and score questions to a text or an image and returns a tibble with one row per question and the probability of each answer. It works with jev(), openai(), gemini() and ollama().
  • Interactive message history: Manage multi-turn conversations with structured history automatically formatted for each API.
  • Batch processing: Handle large workloads with Anthropic, OpenAI, Mistral, Groq, and Gemini batch APIs, reducing costs by up to 50%.
  • Tidy workflow: Pipeline-oriented, side-effect-free design that integrates naturally with tidyverse data workflows.

Installation

To install tidyllm from CRAN, use:

install.packages("tidyllm")

Or for the development version from GitHub:

devtools::install_github("edubruell/tidyllm")

Basic Example

library(tidyllm)

# Describe an image with Claude, continue with a local model
conversation <- llm_message("Describe this image.",
                             .media = img("photo.jpg")) |>
  chat(claude())

conversation |>
  llm_message("Based on that description, what research topic could this figure relate to?") |>
  chat(ollama(.model = "qwen3.5:4b"))

For more examples and advanced usage, see the Get Started vignette.

Please note: To use tidyllm you need either a local Ollama or llama.cpp installation, or an active API key for one of the supported cloud providers. See the Get Started vignette for setup instructions.

What’s new in 0.8.0

Closed questions with probabilities. decide() puts yes/no, choice and score questions to a text, an image, a recording or a PDF. It returns a tibble with one row per question, the answer and its probability. You write the questions once as a tidyllm_schema() and switch between jev(), openai(), gemini() and ollama().

questions <- tidyllm_schema(
  late = field_lgl("Was the payment late?"),
  tone = field_fct("Tone of the message", .levels = c("polite", "angry"))
)

decide("Your invoice is two weeks overdue and I am furious.", questions, jev())

Pass a character vector to code many texts in parallel. field_box() asks where something is in a picture (experimental, jev() only). The decision models article walks through it.

Read many replies at once. get_reply(), get_reply_data() and get_metadata() accept the list that parallel_chat() and fetch_batch() return.

Current provider defaults. mistral() defaults to mistral-large-4, which always reasons (.reasoning_effort of "low", "medium" or "high"). openai() accepts every reasoning effort the API names, and gemini() accepts .thinking_level = "xhigh". llamacpp() looks for the server on port 9931.

Perplexity removed. perplexity() is gone. Use Perplexity models through openrouter() and web search through websearch_tool().

Read the Changelog for the full list of changes.

Learn More

Get Started with tidyllm covers setup, your first chat and the basic verbs. Read it first, then pick the article that matches your task. The Changelog lists every change, and the documentation holds the function reference.

Start here: the common research tasks, simplest first

Go deeper: setup choices and larger builds

Similar packages

  • ellmer keeps conversation state in objects and concentrates on chat providers, which suits interactive agents, chatbots in Shiny and tool-calling workflows. tidyllm keeps its verbs as stateless as possible, so they fit data pipelines and batch work, and it covers API features beyond chat, such as batch jobs, embeddings, file uploads and web search. The two packages work together: chat(ellmer(.ellmer_chat = ...)) runs a tidyllm message through any ellmer chat object.
  • rollama is purpose-built for the Ollama API with specialized model management features not currently in tidyllm.

Contributing

Contributions are welcome. Open an issue or a pull request on GitHub.

License

This project is licensed under the MIT License; see the LICENSE file for details.