call_openai_chat: Call OpenAI API

View source: R/openai_api.R

call_openai_chatR Documentation

Call OpenAI API

Description

Sends messages to the OpenAI Chat Completions API and returns the assistant content. Temperature is not sent; models run with API defaults.

Usage

call_openai_chat(messages, model)

Arguments

messages

List of messages (each a list with 'role' and 'content').

model

OpenAI model to use.

Value

Character string with assistant reply, or NULL on unexpected response.

Examples

## Not run: 
  msgs <- list(
    list(role = "system", content = "You are concise."),
    list(role = "user", content = "What does httr do?")
  )
  call_openai_chat(messages = msgs, model = "gpt-5-mini")

## End(Not run)

PacketLLM documentation built on Aug. 23, 2025, 5:08 p.m.