Table of Contents

Class FilesEndpoint

Namespace
OpenAI.Files
Assembly
OpenAI-DotNet.dll

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

string

Methods

DeleteFileAsync(string, CancellationToken)

Delete a file.

public Task<bool> DeleteFileAsync(string fileId, CancellationToken cancellationToken = default)

Parameters

fileId string

The ID of the file to use for this request

cancellationToken CancellationToken

Optional, CancellationToken.

Returns

Task<bool>

True, if file was successfully deleted.

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 FileResponse

FileResponse to download.

directory string

The directory to download the file into.

deleteCachedFile bool

Optional, delete cached file. Default is false.

cancellationToken CancellationToken

Optional, CancellationToken.

Returns

Task<string>

The full path of the downloaded file.

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 string

The file id to download.

directory string

The directory to download the file into.

deleteCachedFile bool

Optional, delete cached file. Default is false.

cancellationToken CancellationToken

Optional, CancellationToken.

Returns

Task<string>

The full path of the downloaded file.

GetFileInfoAsync(string, CancellationToken)

Returns information about a specific file.

public Task<FileResponse> GetFileInfoAsync(string fileId, CancellationToken cancellationToken = default)

Parameters

fileId string

The ID of the file to use for this request.

cancellationToken CancellationToken

Optional, CancellationToken.

Returns

Task<FileResponse>

FileResponse.

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 string

List files with a specific purpose.

cancellationToken CancellationToken

Optional, 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 FileResponse

FileResponse to download.

cancellationToken CancellationToken

Optional, CancellationToken.

Returns

Task<Stream>

The file as a stream in an asynchronous operation.

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 FileUploadRequest

FileUploadRequest.

cancellationToken CancellationToken

Optional, CancellationToken.

Returns

Task<FileResponse>

FileResponse.

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 string

Local file path to upload.

purpose string

The 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 CancellationToken

Optional, CancellationToken.

Returns

Task<FileResponse>

FileResponse.

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.