Implementation:Openai Openai python File Object Model
| Knowledge Sources | |
|---|---|
| Domains | API_Types, Python |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete tool for representing an uploaded file object provided by the openai-python SDK.
Description
FileObject is a Pydantic BaseModel representing a document that has been uploaded to OpenAI. It contains metadata including the file id, bytes size, created_at timestamp, filename, purpose (one of several literal values such as "assistants", "batch", "fine-tune", etc.), and a deprecated status field. Optional fields include expires_at for expiration timestamps and status_details for validation error information.
Usage
Import FileObject when you need to type-annotate or inspect the response returned from file upload, retrieval, or listing API calls.
Code Reference
Source Location
- Repository: openai-python
- File: src/openai/types/file_object.py
Signature
class FileObject(BaseModel):
id: str
bytes: int
created_at: int
filename: str
object: Literal["file"]
purpose: Literal[
"assistants", "assistants_output", "batch", "batch_output",
"fine-tune", "fine-tune-results", "vision", "user_data",
]
status: Literal["uploaded", "processed", "error"]
expires_at: Optional[int] = None
status_details: Optional[str] = None
Import
from openai.types import FileObject
I/O Contract
Fields
| Name | Type | Required | Description |
|---|---|---|---|
| id | str | Yes | The file identifier, which can be referenced in API endpoints. |
| bytes | int | Yes | The size of the file, in bytes. |
| created_at | int | Yes | Unix timestamp (in seconds) for when the file was created. |
| filename | str | Yes | The name of the file. |
| object | Literal["file"] | Yes | The object type, always "file". |
| purpose | Literal["assistants", "assistants_output", "batch", "batch_output", "fine-tune", "fine-tune-results", "vision", "user_data"] | Yes | The intended purpose of the file. |
| status | Literal["uploaded", "processed", "error"] | Yes | (Deprecated) The current status of the file. |
| expires_at | Optional[int] | No | Unix timestamp (in seconds) for when the file will expire. |
| status_details | Optional[str] | No | (Deprecated) Details on why a fine-tuning training file failed validation. |
Usage Examples
from openai import OpenAI
from openai.types import FileObject
client = OpenAI()
# Upload a file and receive a FileObject
file_obj: FileObject = client.files.create(
file=open("training_data.jsonl", "rb"),
purpose="fine-tune",
)
print(f"File ID: {file_obj.id}")
print(f"Size: {file_obj.bytes} bytes")
print(f"Purpose: {file_obj.purpose}")
# Retrieve a file by ID
retrieved: FileObject = client.files.retrieve("file-abc123")
print(f"Filename: {retrieved.filename}")