Skip to main content

Upload File

POST 

/files

Upload an image file that can later be referenced by its file_id in chat completion requests.

Supported formats: JPEG, PNG, GIF, and WebP. The format is detected from the file content. See the Files API guide for details.

To upload documents, set purpose to text_recognition or rich_layout_recognition and send it before the file field. See the File Parsing guide.

Request​

Body

required

    purpose stringrequired

    Possible values: user_data, text_recognition, rich_layout_recognition

    The intended purpose of the uploaded file. When uploading a document, send this field before file. See the Files API guide for the file types each purpose accepts.

    file binaryrequired

    The file to upload. The accepted file types depend on purpose.

    expires_after[anchor] string

    Possible values: created_at

    The anchor for the expiration. Must be created_at if provided, and is required together with expires_after[seconds].

    expires_after[seconds] integer

    Possible values: >= 3600 and <= 2592000

    The lifetime of the file in seconds, between 3600 (1 hour) and 2592000 (30 days). Required together with expires_after[anchor]. Omit both expires_after fields to keep the file permanently.

Responses​

OK, returns the uploaded file object.

Schema

    id stringrequired

    The file identifier, of the form file-api-..., which can be referenced in chat completion requests.

    object stringrequired

    Possible values: file

    The object type, which is always file.

    bytes integerrequired

    The size of the file in bytes.

    created_at integerrequired

    The Unix timestamp (in seconds) of when the file was created.

    filename stringrequired

    The name of the file.

    purpose stringrequired

    Possible values: user_data, text_recognition, rich_layout_recognition

    The intended purpose of the file.

    expires_at integer

    The Unix timestamp (in seconds) of when the file expires. Only present when an expiration was set at upload time.

Loading...