OpenAI

上传文件

流式上传文档、媒体或 UTF-8 文本文件,单文件最多 100 MB。

POST /openai/v1/files◐ 部分支持

OpenAI 官方文档 ↗

请求体

  • filestring必填

    The File object (not file name) to be uploaded.

    已验证生效。

  • purposestring必填◐ 部分支持

    文件用途:user_data、assistants 或 vision(vision 只接受 PNG、JPEG、GIF、WebP 图片)。OpenAI 的 batch、fine-tune、evals 等其余用途不支持,返回 400 PURPOSE_UNSUPPORTED。

    支持 user_data、assistants、vision;batch、fine-tune、evals 等其余值返回 400。

    取值 user_dataassistantsvision
  • expires_afterobject可选

    The expiration policy for a file. By default, files with `purpose=batch` expire after 30 days and all other files are persisted until they are manually deleted.

    anchor=created_at,seconds=3600–2592000。

    ▸ 展开子字段(2)
    • anchorstring必填

      Anchor timestamp after which the expiration policy applies. Supported anchors: `created_at`.

      取值 created_at
    • secondsinteger必填

      The number of seconds after the anchor time that the file will expire. Must be between 3600 (1 hour) and 2592000 (30 days).

返回

200 file

单文件最多 100 MB(104857600 字节);按内容识别 PDF、Office、图片、音频、视频与 UTF-8 文本。purpose 支持 user_data / assistants / vision;其他用途、空文件、不支持类型和超限均返回 400。不支持 Uploads 分片。只接受表单 file、purpose、expires_after[anchor]、expires_after[seconds];其他表单字段或任何查询参数返回 400 invalid_request_error,消息为 "Unrecognized request argument supplied: <字段>",param 为该字段。

错误按 OpenAI 格式返回,参见 错误码

响应

HTTP 200

OK

application/json

名称类型说明
idstringThe file identifier, which can be referenced in the API endpoints.
bytesintegerThe size of the file, in bytes.
created_atintegerThe Unix timestamp (in seconds) for when the file was created.
expires_atintegerThe Unix timestamp (in seconds) for when the file will expire.
filenamestringThe name of the file.
objectstringThe object type, which is always `file`.
purposestringThe intended purpose of the file. Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results`, `vision`, and `user_data`.
statusstringDeprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`.
status_detailsstringDeprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`.