Learn R Programming

openaiRtools (version 0.2.2)

image_from_url: Create Image Content from a URL

Description

Builds a content part object that tells the model to fetch and analyze an image from a public web URL. The URL must be directly accessible (no login required).

Usage

image_from_url(url, detail = "auto")

Value

A named list (content part) to be placed inside a message's content list. Use with create_multimodal_message

or construct messages manually.

Arguments

url

Character. A publicly accessible image URL. Supported formats: JPEG, PNG, GIF (static), WebP. Example: "https://example.com/chart.png"

detail

Character. Controls how the model perceives the image, trading off between cost/speed and accuracy:

  • "auto" (default) — model chooses based on image size

  • "low" — 85 tokens flat; fast and cheap; good for simple images, icons, or when spatial detail is unimportant

  • "high" — tiles the image at 512px squares (up to 1105 extra tokens); use for charts with small text, detailed figures, or when precise spatial understanding is needed

See Also

image_from_file, image_from_plot, create_multimodal_message

Examples

Run this code
if (FALSE) {
library(openaiRtools)
client <- OpenAI$new(api_key = "sk-xxxxxx")

# Build an image part from a URL
img <- image_from_url(
  url    = "https://example.com/photo.jpg",
  detail = "low"
)

# Assemble a message manually
messages <- list(
  list(
    role = "user",
    content = list(
      list(type = "text", text = "What painting is this?"),
      img
    )
  )
)

response <- client$chat$completions$create(
  messages = messages,
  model    = "gpt-4o"
)
cat(response$choices[[1]]$message$content)
}

Run the code above in your browser using DataLab