Class FilesEndpoint
Files are used to upload documents that can be used with features like Assistants, Fine-tuning, and Batch API.
https://platform.openai.com/docs/api-reference/files
public sealed class FilesEndpoint : OpenAIBaseEndpoint
- Inheritance
-
FilesEndpoint
- Inherited Members
Constructors
FilesEndpoint(OpenAIClient)
public FilesEndpoint(OpenAIClient client)
Parameters
client
OpenAIClient
Properties
Root
The root endpoint address.
protected override string Root { get; }
Property Value
Methods
DeleteFileAsync(string, CancellationToken)
Delete a file.
public Task<bool> DeleteFileAsync(string fileId, CancellationToken cancellationToken = default)
Parameters
fileId
stringThe ID of the file to use for this request
cancellationToken
CancellationTokenOptional, CancellationToken.
Returns
DownloadFileAsync(FileResponse, string, bool, CancellationToken)
Downloads the specified file.
public Task<string> DownloadFileAsync(FileResponse fileData, string directory, bool deleteCachedFile = false, CancellationToken cancellationToken = default)
Parameters
fileData
FileResponseFileResponse to download.
directory
stringThe directory to download the file into.
deleteCachedFile
boolOptional, delete cached file. Default is false.
cancellationToken
CancellationTokenOptional, CancellationToken.
Returns
DownloadFileAsync(string, string, bool, CancellationToken)
Downloads the specified file.
public Task<string> DownloadFileAsync(string fileId, string directory, bool deleteCachedFile = false, CancellationToken cancellationToken = default)
Parameters
fileId
stringThe file id to download.
directory
stringThe directory to download the file into.
deleteCachedFile
boolOptional, delete cached file. Default is false.
cancellationToken
CancellationTokenOptional, CancellationToken.
Returns
GetFileInfoAsync(string, CancellationToken)
Returns information about a specific file.
public Task<FileResponse> GetFileInfoAsync(string fileId, CancellationToken cancellationToken = default)
Parameters
fileId
stringThe ID of the file to use for this request.
cancellationToken
CancellationTokenOptional, CancellationToken.
Returns
ListFilesAsync(string, CancellationToken)
Returns a list of files that belong to the user's organization.
public Task<IReadOnlyList<FileResponse>> ListFilesAsync(string purpose = null, CancellationToken cancellationToken = default)
Parameters
purpose
stringList files with a specific purpose.
cancellationToken
CancellationTokenOptional, CancellationToken.
Returns
- Task<IReadOnlyList<FileResponse>>
List of FileResponse.
RetrieveFileStreamAsync(FileResponse, CancellationToken)
Gets the specified file as stream
public Task<Stream> RetrieveFileStreamAsync(FileResponse fileData, CancellationToken cancellationToken = default)
Parameters
fileData
FileResponseFileResponse to download.
cancellationToken
CancellationTokenOptional, CancellationToken.
Returns
UploadFileAsync(FileUploadRequest, CancellationToken)
Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB. Please contact us if you need to increase the storage limit.
public Task<FileResponse> UploadFileAsync(FileUploadRequest request, CancellationToken cancellationToken = default)
Parameters
request
FileUploadRequestcancellationToken
CancellationTokenOptional, CancellationToken.
Returns
UploadFileAsync(string, string, CancellationToken)
Upload a file that can be used across various endpoints. Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 100 GB.
public Task<FileResponse> UploadFileAsync(string filePath, string purpose, CancellationToken cancellationToken = default)
Parameters
filePath
stringLocal file path to upload.
purpose
stringThe intended purpose of the uploaded file. Use 'assistants' for Assistants and Message files, 'vision' for Assistants image file inputs, 'batch' for Batch API, and 'fine-tune' for Fine-tuning.
cancellationToken
CancellationTokenOptional, CancellationToken.
Returns
Remarks
- The Assistants API supports files up to 2 million tokens and of specific file types.
- The Fine-tuning API only supports .jsonl files.
- The Batch API only supports .jsonl files up to 100 MB in size.