Implementation:Openai Openai python Upload Create Params
| Knowledge Sources | |
|---|---|
| Domains | API_Types, Python |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete tool for specifying parameters when creating an Upload via the OpenAI API, provided by the openai-python SDK.
Description
UploadCreateParams is a TypedDict that defines the required and optional parameters for creating a new multi-part Upload. Required fields include bytes (the total file size), filename, mime_type, and purpose. An optional expires_after nested ExpiresAfter TypedDict allows specifying an expiration policy with an anchor timestamp and a duration in seconds.
Usage
Import this type when you need to type-annotate the keyword arguments passed to client.uploads.create(), or when building parameter dictionaries programmatically for upload creation requests.
Code Reference
Source Location
- Repository: openai-python
- File: src/openai/types/upload_create_params.py
Signature
class UploadCreateParams(TypedDict, total=False):
bytes: Required[int]
filename: Required[str]
mime_type: Required[str]
purpose: Required[FilePurpose]
expires_after: ExpiresAfter
class ExpiresAfter(TypedDict, total=False):
anchor: Required[Literal["created_at"]]
seconds: Required[int]
Import
from openai.types import UploadCreateParams
I/O Contract
Fields (UploadCreateParams)
| Name | Type | Required | Description |
|---|---|---|---|
| bytes | int | Yes | The number of bytes in the file you are uploading. |
| filename | str | Yes | The name of the file to upload. |
| mime_type | str | Yes | The MIME type of the file. Must fall within supported MIME types for the file purpose. |
| purpose | FilePurpose | Yes | The intended purpose of the uploaded file. |
| expires_after | ExpiresAfter | No | The expiration policy for the file. Defaults to 30 days for batch files; others persist until deleted. |
Fields (ExpiresAfter)
| Name | Type | Required | Description |
|---|---|---|---|
| anchor | Literal["created_at"] | Yes | Anchor timestamp after which the expiration policy applies. |
| seconds | int | Yes | The number of seconds after the anchor time that the file will expire (3600 to 2592000). |
Usage Examples
from openai import OpenAI
from openai.types import UploadCreateParams
client = OpenAI()
params: UploadCreateParams = {
"bytes": 2048,
"filename": "data.jsonl",
"mime_type": "application/jsonl",
"purpose": "fine-tune",
"expires_after": {
"anchor": "created_at",
"seconds": 86400, # 1 day
},
}
upload = client.uploads.create(**params)