Files API

Upload, list, retrieve, and delete files, and download their content. Files feed the Responses file_search and code-interpreter tools, the Batch API, and fine-tuning. OpenAI only.

Request Type

UniLM.FileUploadType
FileUpload(; file, purpose, service=OPENAIServiceEndpoint)

A file-upload request. file is a path on disk; purpose is one of "assistants", "batch", "fine-tune", "vision", "user_data", "evals".

source

Parsed Objects

UniLM.FileObjectType
FileObject

A file stored by the Files API: id, bytes, created_at, filename, purpose, and status; raw holds the unparsed JSON response.

source

Result Types

Request Functions

UniLM.upload_fileFunction
upload_file(path, purpose; service=OPENAIServiceEndpoint) -> LLMRequestResponse
upload_file(u::FileUpload) -> LLMRequestResponse

Upload a file (multipart/form-data). Returns FileSuccess, FileFailure, or FileCallError.

Pass config::Union{Nothing,RequestConfig} to override the timeout and retry budget for this call. Unlike the other Files verbs this one DOES retry: the multipart form is rebuilt for every attempt, so a transient 429/503 is retried rather than resent as an already-consumed form.

source
UniLM.list_filesFunction
list_files(; purpose=nothing, limit=nothing, after=nothing, service=OPENAIServiceEndpoint)

List uploaded files. Returns FileListSuccess, FileFailure, or FileCallError.

Pass config::Union{Nothing,RequestConfig} to override the timeout budget for this call (a single bounded attempt; max_attempts does not apply).

source
UniLM.retrieve_fileFunction
retrieve_file(file_id; service=OPENAIServiceEndpoint)

Retrieve a file's metadata. Returns FileSuccess, FileFailure, or FileCallError.

Pass config::Union{Nothing,RequestConfig} to override the timeout budget for this call (a single bounded attempt; max_attempts does not apply).

source
UniLM.delete_fileFunction
delete_file(file_id; service=OPENAIServiceEndpoint)

Delete a file. Returns FileDeleteSuccess, FileFailure, or FileCallError.

Pass config::Union{Nothing,RequestConfig} to override the timeout budget for this call (a single bounded attempt; max_attempts does not apply).

source
UniLM.file_contentFunction
file_content(file_id; service=OPENAIServiceEndpoint)

Download a file's raw bytes. Returns FileContentSuccess (.content::Vector{UInt8}), FileFailure, or FileCallError. Use save_file_content to write to disk.

Pass config::Union{Nothing,RequestConfig} to override the timeout budget for this call (a single bounded attempt; max_attempts does not apply).

source

Usage

# Upload a file for use with file_search / batch / fine-tuning
result = upload_file("data.jsonl", "batch")
result isa FileSuccess && println("Uploaded: ", result.response.id)

# List, download, delete
files = list_files(purpose="batch")
content = file_content("file-abc123")
content isa FileContentSuccess && save_file_content(content, "out.jsonl")
delete_file("file-abc123")