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
clientOpenAIClient
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
fileIdstringThe ID of the file to use for this request
cancellationTokenCancellationTokenOptional, 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
fileDataFileResponseFileResponse to download.
directorystringThe directory to download the file into.
deleteCachedFileboolOptional, delete cached file. Default is false.
cancellationTokenCancellationTokenOptional, 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
fileIdstringThe file id to download.
directorystringThe directory to download the file into.
deleteCachedFileboolOptional, delete cached file. Default is false.
cancellationTokenCancellationTokenOptional, CancellationToken.
Returns
GetFileInfoAsync(string, CancellationToken)
Returns information about a specific file.
public Task<FileResponse> GetFileInfoAsync(string fileId, CancellationToken cancellationToken = default)
Parameters
fileIdstringThe ID of the file to use for this request.
cancellationTokenCancellationTokenOptional, 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
purposestringList files with a specific purpose.
cancellationTokenCancellationTokenOptional, 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
fileDataFileResponseFileResponse to download.
cancellationTokenCancellationTokenOptional, 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
requestFileUploadRequestcancellationTokenCancellationTokenOptional, 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
filePathstringLocal file path to upload.
purposestringThe 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.
cancellationTokenCancellationTokenOptional, 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.