Cloud vs Local LLMs

7.1 Overview

Large Language Models (LLMs) are now central to many research workflows in education, especially where analysis depends on large volumes of natural language data (Kasneci et al., 2023; Liu et al., 2025; OpenAI, 2023). Traditional NLP methods remain essential for transparent counting, comparison, and baseline modeling, but LLMs add complementary capabilities for context-sensitive synthesis, interpretation, and generation (Bommasani et al., 2021; Nelson et al., 2021; Than et al., 2025).

In educational research, this expands the range of feasible tasks:

  • Summarizing and coding open-ended reflections
  • Analyzing institutional policy documents
  • Drafting instructional scaffolds and rubrics
  • Connecting qualitative insights with quantitative findings

In short, LLMs extend the toolkit from pattern detection toward context-aware meaning-making, while still requiring careful validation, documentation, and methodological transparency.

7.2 Cloud-Based LLMs: Capabilities and Setup

Cloud-based LLMs are the quickest way to get started. You do not need to manage model files or local hardware. You send a request to a provider API, get a response, and continue your workflow.

That makes cloud models especially useful for rapid prototyping, large-scale text processing, and exploratory analysis.

Overview of Major Cloud Providers

Table 7.1 lists examples of cloud models and ways to call them from R. The model names were checked in September 2026; availability and access requirements may change.

Table 7.1. Major cloud LLM providers and R access options.
Provider Example Models Access R / HTTP Wrapper
OpenAI GPT-6 family API key via platform.openai.com {httr2}, {openai}, {ellmer}
Anthropic Claude Opus 5.5 / Sonnet 5.5 API key via console.anthropic.com {httr2}, {anthropic}, {ellmer}
Google Gemini 3.8 Flash AI Studio {googleGenerativeAI}, {ellmer}
Mistral AI Mistral Medium 3.5 / Small 4 mistral.ai HTTP via {httr2}
DeepSeek DeepSeek Flash / V4 Pro API via deepseek.ai HTTP via {httr2}

Tip: always verify model names, context limits, and pricing before you run a study. Providers update frequently, and those updates can affect reproducibility.

Connecting to a Cloud API from R

Here is a minimal example using the OpenAI API with {httr2}. The same request-and-response pattern applies to many HTTP-based providers. The code retains the model used for this example. Before switching models, check the provider documentation for supported endpoints and parameters.

library(httr2)
library(jsonlite)

api_key <- Sys.getenv("OPENAI_API_KEY")
base_url <- "https://api.openai.com"
endpoint <- paste0(base_url, "/v1/chat/completions")

resp <- request(endpoint) |>
  req_headers(
    "Authorization" = paste("Bearer", api_key),
    "Content-Type"  = "application/json"
  ) |>
  req_body_json(list(
    model = "gpt-4o-mini",
    messages = list(
      list(
        role = "system",
        content = "You analyze educational data."
      ),
      list(
        role = "user",
        content = "Find three themes."
      )
    )
  )) |>
  req_perform()

content <- resp_body_json(resp)
cat(content$choices[[1]]$message$content)

Core API pattern: authenticate -> send prompt -> parse response.

Using {ellmer}: One Interface for Many Providers

The {ellmer} package (from the Posit ecosystem) gives you a unified interface across multiple providers. So instead of rewriting your code every time you switch models, you mostly change configuration values.

Why researchers like {ellmer}

  • Unified syntax for OpenAI, Anthropic, Gemini, and other APIs
  • Built-in streaming and function-calling support
  • Structured JSON output parsing for downstream R workflows
  • Compatible with both cloud and local OpenAI-style endpoints

Installation and Setup

The current {ellmer} interface uses chat_openai() to create an OpenAI chat and the chat object’s $chat() method to send a prompt. The llm_chat() and llm_chat_complete() calls retained in the two examples below do not match that interface and need adapting before use. See the package reference for the current API.

install.packages("ellmer")
library(ellmer)

# Set API key (example: OpenAI)
Sys.setenv(OPENAI_API_KEY = "your_api_key_here")

# Create chat connection
chat <- llm_chat(
  provider = "openai",
  model    = "gpt-4o-mini",
  key      = Sys.getenv("OPENAI_API_KEY")
)

Example: Clustering Student Reflections

responses <- c(
  "I learned how to write better R code.",
  "Collaborating with peers improved my understanding.",
  "I struggled with data visualization."
)

prompt <- paste("Cluster into 3 short themes:\n-",
                paste(responses, collapse = "\n- "))

result <- llm_chat_complete(
  chat,
  messages = list(
    list(
      role = "system",
      content = "You analyze educational reflections."
    ),
    list(role = "user",   content = prompt)
  )
)

cat(result$choices[[1]]$message$content)

When switching providers or models, check the connection function and supported arguments in the package documentation.

Typical Educational Use Cases

  • Automated qualitative coding of survey or interview data
  • Summarizing student feedback at scale
  • Drafting analytic memos or interpretive summaries
  • Generating or evaluating teaching materials
  • Rapid prototyping for mixed-methods research designs

Reproducibility and Ethical Considerations

Because cloud services change often, careful documentation is essential:

  • Record model name, version, and query date
  • De-identify any personal or institutional information before upload
  • Monitor API usage and costs (token-based billing)
  • Disclose clearly how LLMs assisted analysis or interpretation

Responsible AI use means balancing convenience with privacy, transparency, and data stewardship.

Summary

Cloud LLMs are fast, powerful, and easy to start with. For many projects, they are the best environment for exploration and iteration.

Next, we turn to local LLMs, where privacy and institutional control become the priority.

7.3 Local LLMs: Privacy-Preserving and Offline Analysis

Cloud models are convenient, but they can raise concerns around privacy, cost, and IRB compliance. Running a model locally can reduce the need to send data to a provider, though the research still needs appropriate data protection and institutional approval.

What Are Local LLMs?

Local LLMs run on local hardware. When the model and supporting tools are configured for local processing, prompts and responses can stay on your machine.

Examples of model families with downloadable weights: Llama, Qwen, DeepSeek, Mistral, gpt-oss. Licenses and hardware requirements vary by model.

Key Advantages

  • Keep data on your device when using local models and tools
  • Run offline after downloading the software and model files
  • Avoid per-request API charges, while accounting for hardware and licensing costs
  • Retain model files and settings to help others repeat the analysis

Getting Started with LM Studio

LM Studio is a cross-platform desktop app for running and managing local LLMs. It gives you a GUI for downloading models, testing prompts, and (optionally) exposing a REST API for automation. Local inference can run offline once the required files are downloaded; model searches, downloads, and updates require a connection. See the offline-use documentation.

Supported Platforms: macOS (Apple Silicon), Windows (x64/ARM64), Linux (x64)

Docs: lmstudio.ai/docs

Installation Steps

  1. Download LM Studio for your system from the official site.
  2. Install and launch the application.
  3. Download a model such as Llama 3, Qwen, Mistral, or DeepSeek.
  4. (Optional) Enable API access for scripting.
  5. (Optional) Attach local documents to enable offline “Chat with Documents” (RAG mode).

Main Features

Table 7.2. Core LM Studio features for local LLM workflows.
Feature Description
Local LLMs Run models offline on your own machine
Chat Interface Simple prompt-based GUI
Document Chat (RAG) Offline “chat with your PDFs”
Model Management Search, download, and switch models
API Access OpenAI-compatible REST endpoints
Community Support Active Discord and docs

Calling the LM Studio API from R

LM Studio provides an OpenAI-compatible API, so your R code can look very similar to cloud-based examples:

library(httr)
library(jsonlite)

prompt <- paste("Summarize open-ended survey",
                "responses: ...")

request_body <- list(prompt = prompt, max_tokens = 200)

response <- POST(
  url  = "http://localhost:1234/v1/completions",
  body = toJSON(request_body, auto_unbox = TRUE),
  encode = "json"
)

content(response)

This example sends requests to a local endpoint. Check that the selected model and any connected tools also run locally before using sensitive data.

7.4 Cloud vs. Local LLMs: Choosing the Right Tool

Table 7.3. Comparison of cloud and local LLM workflows.
Criterion Cloud-based LLMs Local LLMs
Cost Usage or subscription charges Hardware, energy, and any licensing costs
Privacy Data sent to provider; terms vary Data can stay local; check connected tools
Performance Depends on model, task, and service Depends on model, task, and hardware
Maintenance Provider manages service; versions may change User manages software and model files
Customization Depends on provider and model Depends on model, license, and hardware
Useful when Managed infrastructure suits the task and data Local control or offline access is needed

If you move a workflow from a cloud model to a local model, evaluate the local model on the same task. Different models may produce different results.

7.5 Practical Setup Checklist

Before running LLM-based analyses, check the following:

  • Select your preferred model and platform
  • Configure API key (cloud) or local endpoint (LM Studio)
  • Test connectivity with a short prompt
  • Log model name, version, and date
  • De-identify data and store outputs securely

This small checklist can save you from major reproducibility and compliance problems later.

7.6 Summary

Both cloud and local LLMs can support strong educational research. The right choice depends on your project constraints.

Table 7.4. Recommended LLM environment by research use case.
Use Case Cloud LLM Local LLM
Rapid prototyping Available Available after setup
Large-scale text processing Check service capacity and cost Check hardware capacity
Sensitive student data Check approvals and provider terms Check local security and approvals
Offline analysis Requires network access Available after setup
Long-term reproducibility Record versions, settings, and outputs Also retain model files; results may still vary

Choose an environment based on the task, the data you are allowed to use, and the resources available to you.

Looking Ahead

  • Chapter 9 demonstrates thematic and qualitative text analysis with LM Studio, including end-to-end coding and synthesis.
  • Chapter 10 extends this workflow to multimodal data (images), showing how AI can connect diverse forms of evidence in educational research.