Implementation:Openai Openai python Upload Model
| Knowledge Sources | |
|---|---|
| Domains | API_Types, Python |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete tool for representing an Upload object returned by the OpenAI Uploads API, provided by the openai-python SDK.
Description
Upload is a Pydantic BaseModel subclass that represents the Upload resource from the OpenAI API. The Upload object can accept byte chunks in the form of Parts. It tracks the lifecycle of a multi-part file upload including its status (pending, completed, cancelled, or expired), the intended purpose of the file, and an optional reference to the completed FileObject.
Usage
Import this type when you need to type-annotate or inspect the response from upload creation, retrieval, or completion endpoints. The model is returned by methods such as client.uploads.create(), client.uploads.complete(), and client.uploads.cancel().
Code Reference
Source Location
- Repository: openai-python
- File: src/openai/types/upload.py
Signature
class Upload(BaseModel):
"""The Upload object can accept byte chunks in the form of Parts."""
id: str
bytes: int
created_at: int
expires_at: int
filename: str
object: Literal["upload"]
purpose: str
status: Literal["pending", "completed", "cancelled", "expired"]
file: Optional[FileObject] = None
Import
from openai.types import Upload
I/O Contract
Fields
| Name | Type | Required | Description |
|---|---|---|---|
| id | str | Yes | The Upload unique identifier, which can be referenced in API endpoints. |
| bytes | int | Yes | The intended number of bytes to be uploaded. |
| created_at | int | Yes | The Unix timestamp (in seconds) for when the Upload was created. |
| expires_at | int | Yes | The Unix timestamp (in seconds) for when the Upload will expire. |
| filename | str | Yes | The name of the file to be uploaded. |
| object | Literal["upload"] | Yes | The object type, which is always "upload". |
| purpose | str | Yes | The intended purpose of the file. |
| status | Literal["pending", "completed", "cancelled", "expired"] | Yes | The status of the Upload. |
| file | Optional[FileObject] | No | The File object representing a document uploaded to OpenAI. |
Usage Examples
from openai import OpenAI
from openai.types import Upload
client = OpenAI()
# Create an upload
upload: Upload = client.uploads.create(
bytes=1024 * 1024,
filename="training_data.jsonl",
mime_type="application/jsonl",
purpose="fine-tune",
)
print(upload.id) # "upload_abc123"
print(upload.status) # "pending"
print(upload.expires_at) # Unix timestamp