To get more details, visit https://platform.openai.com/docs/api-reference/making-requests
request(
endpoint,
api_key = api_get_key(),
body = NULL,
query = NULL,
encode = "json",
method = "POST",
content_class = NULL
)
content of the httr response object or SimpleError (conditions) enhanced with two additional fields: `status_code` (response$status_code) and `message_long` (built on response content)
string, API endpoint url
string, OpenAI API key (see https://platform.openai.com/account/api-keys)
One of the following:
FALSE
: No body. This is typically not used with POST
,
PUT
, or PATCH
, but can be useful if you need to send a
bodyless request (like GET
) with VERB()
.
NULL
: An empty body
""
: A length 0 body
upload_file("path/")
: The contents of a file. The mime
type will be guessed from the extension, or can be supplied explicitly
as the second argument to upload_file()
A character or raw vector: sent as is in body. Use
content_type()
to tell the server what sort of data
you are sending.
A named list: See details for encode.
NULL/list, query string elements as list(name1 = value1, name2 = value2)
If the body is a named list, how should it be encoded? Can be one of form (application/x-www-form-urlencoded), multipart, (multipart/form-data), or json (application/json).
For "multipart", list elements can be strings or objects created by
upload_file()
. For "form", elements are coerced to strings
and escaped, use I()
to prevent double-escaping. For "json",
parameters are automatically "unboxed" (i.e. length 1 vectors are
converted to scalars). To preserve a length 1 vector as a vector,
wrap in I()
. For "raw", either a character or raw vector. You'll
need to make sure to set the content_type()
yourself.
string, request method
NULL/character vector, NULL or additional class name(s) (S3) appended to the response content