asa-api / Tests /example_API_call.R
cjerzak's picture
improvements
1dd1e45
Raw
History Blame Contribute Delete
616 Bytes
library(httr2)
library(jsonlite)
base_url <- "http://localhost:7860"
bearer_token <- trimws(Sys.getenv("ASA_API_BEARER_TOKEN", unset = ""))
if (!nzchar(bearer_token)) {
stop("Set ASA_API_BEARER_TOKEN before running this example.", call. = FALSE)
}
resp <- request(paste0(base_url, "/v1/run")) |>
req_headers(
`Content-Type` = "application/json",
Authorization = sprintf("Bearer %s", bearer_token)
) |>
req_body_json(list(prompt = "Return the single word OK."), auto_unbox = TRUE) |>
req_perform()
result <- resp_body_json(resp, simplifyVector = TRUE)
print(result$status)
print(result$message)