retrieveOpenAIFileContent

Retrieves the raw content of a file from the OpenAI Files API.

Warning: Loading large files directly into memory can cause an OutOfMemoryError. To stream large files safely, use streamOpenAIFileContent or for download content to file use downloadOpenAIFileContentTo.

Return

The file content as a byte array.

Parameters

fileId

The ID of the file to retrieve.

Throws

if the request fails.

if the OpenAI API returns an error.

Samples

// Returns the file's bytes as a ByteArray. Note that large files may cause an OutOfMemoryError.
// to stream the file, use the downloadOpenAIFileContentTo function.
val fileBytes: ByteArray = client.retrieveOpenAIFileContent(fileId)

println(fileBytes.contentToString())