Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Openai Openai python File Create Params

From Leeroopedia
Knowledge Sources
Domains API_Types, Python
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete type for file upload parameters provided by the openai-python SDK.

Description

The FileCreateParams TypedDict defines the parameters for uploading a file via client.files.create(). It requires a file (the actual file object, not just a name, of type FileTypes) and a purpose (a FilePurpose string such as "assistants", "batch", "fine-tune", "vision", "user_data", or "evals"). An optional expires_after field (the nested ExpiresAfter TypedDict) configures file expiration with a "created_at" anchor and seconds value. By default, batch files expire after 30 days while other files persist until manually deleted.

Usage

Import this type when constructing or type-hinting parameters for client.files.create() to upload files for batch processing, fine-tuning, assistants, or evaluations.

Code Reference

Source Location

Signature

class FileCreateParams(TypedDict, total=False):
    file: Required[FileTypes]
    purpose: Required[FilePurpose]
    expires_after: ExpiresAfter

class ExpiresAfter(TypedDict, total=False):
    anchor: Required[Literal["created_at"]]
    seconds: Required[int]

Import

from openai.types import FileCreateParams

I/O Contract

Fields

Name Type Required Description
file FileTypes Yes The file object to be uploaded (not just a filename)
purpose FilePurpose Yes Intended purpose: "assistants", "batch", "fine-tune", "vision", "user_data", or "evals"
expires_after ExpiresAfter No Expiration policy for the file

ExpiresAfter Fields

Name Type Required Description
anchor Literal["created_at"] Yes Anchor timestamp; only "created_at" supported
seconds int Yes Seconds after anchor before file expires (3600 to 2592000)

Usage Examples

from openai import OpenAI

client = OpenAI()

# Upload a file for batch processing
with open("requests.jsonl", "rb") as f:
    file_obj = client.files.create(
        file=f,
        purpose="batch",
    )
print(file_obj.id)

# Upload with custom expiration (7 days)
with open("training_data.jsonl", "rb") as f:
    file_obj = client.files.create(
        file=f,
        purpose="fine-tune",
        expires_after={
            "anchor": "created_at",
            "seconds": 604800,  # 7 days
        },
    )

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment