OpenAI

Upload a file

Stream a document, media or UTF-8 text file, up to 100 MB.

POST /openai/v1/files◐ Partial

Official OpenAI docs ↗

Request body

  • filestring必填

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

    Verified to take effect.

  • purposestring必填◐ Partially supported

    The file purpose: user_data, assistants or vision (vision accepts only PNG, JPEG, GIF or WebP images). Other OpenAI purposes such as batch, fine-tune and evals are not supported and return 400 PURPOSE_UNSUPPORTED.

    Supports user_data, assistants and vision; batch, fine-tune, evals and other values return 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 and 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).

Returns

200 file

Upload one file, up to 100 MB (104857600 bytes), using streaming multipart/form-data. Supported content-detected types: PDF; DOCX, XLSX, PPTX; PNG, JPEG, GIF, WebP; MP3, WAV, FLAC, OGG, M4A; MP4, WebM; UTF-8 JSON, NDJSON, CSV, Markdown and plain text. Purposes: user_data, assistants, vision. Other purposes and empty/unsupported/oversized files return 400. OpenAI Uploads chunking is not supported. expires_after accepts anchor created_at and seconds 3600–2592000. Only form file, purpose, expires_after[anchor] and expires_after[seconds] are accepted; any other form field or any query parameter returns 400 invalid_request_error "Unrecognized request argument supplied: <name>" with param naming it.

Errors follow the OpenAI format — see error codes

Response

HTTP 200

OK

application/json

NameTypeDescription
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`.