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.FileUpload — Type
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".
Parsed Objects
UniLM.FileObject — Type
FileObjectA file stored by the Files API: id, bytes, created_at, filename, purpose, and status; raw holds the unparsed JSON response.
UniLM.FileList — Type
FileListA page of FileObjects from list_files; has_more signals that further pages are available.
Result Types
UniLM.FileSuccess — Type
Successful upload/retrieve result wrapping a FileObject.
UniLM.FileListSuccess — Type
Successful list_files result wrapping a FileList.
UniLM.FileContentSuccess — Type
Successful file_content result; content holds the raw file bytes.
UniLM.FileDeleteSuccess — Type
Successful delete_file result; deleted confirms removal of id.
UniLM.FileFailure — Type
Files API error result: HTTP status and the raw response body.
UniLM.FileCallError — Type
Local/transport error from a Files API call (the request never completed).
Request Functions
UniLM.upload_file — Function
upload_file(path, purpose; service=OPENAIServiceEndpoint) -> LLMRequestResponse
upload_file(u::FileUpload) -> LLMRequestResponseUpload 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.
UniLM.list_files — Function
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).
UniLM.retrieve_file — Function
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).
UniLM.delete_file — Function
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).
UniLM.file_content — Function
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).
UniLM.save_file_content — Function
save_file_content(r::FileContentSuccess, path) -> pathWrite downloaded file bytes to path.
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")