Skip to Content

Files API

Preview
Copy Page as Markdown

Use the Files API to upload and manage documents and images for your organization. Files are org-scoped — a file is only visible to the organization that created it.

After uploading a document, pass its file_id in an input_file part on the Responses API. For PDFs, you can also pass the ID in a nested file part on Chat Completions. Uploaded images are supported through flat Chat Completions file parts and Responses input_image parts. See Sending files for examples.

Endpoints

MethodPathDescription
POST/v1/filesUpload a file (multipart)
GET/v1/filesList the org's files
GET/v1/files/{file_id}Retrieve one file
DELETE/v1/files/{file_id}Delete a file

Limits

  • Max size: 50 MiB per file, or 10 MiB for an image.
  • Purpose: assistants (only value accepted today).
  • Supported types: plain text (.txt, .md, .csv, .tsv), JSON / JSONL, XML, PDF, Word (.doc, .docx), and PNG, JPEG, or WebP images. Images are stored as-is, with no text extraction.

File object

FieldTypeDescription
idstringFile identifier (file_…). Use as file_id in Chat Completions or Responses.
objectstringAlways "file".
bytesnumberSize in bytes.
created_atnumberUnix timestamp (seconds) when the file was created.
expires_atnumber or nullExpiration timestamp, if any.
filenamestringOriginal file name.
purposestringIntended purpose (assistants).
statusstring or nullLifecycle status (see below).

Statuses

StatusMeaning
uploadedBytes stored and validated. Non-text files may still be extracting text.
processedContent available for Chat Completions and Responses. Text and image files reach this immediately.
errorText extraction failed. A later retry can flip it back to processed.

Upload file

POST /v1/files

Upload bytes through the API as multipart/form-data.

FieldRequiredDescription
fileYesThe file part.
purposeYesMust be assistants.

Setting the part's Content-Type is optional. A part sent with no type, text/plain, or application/octet-stream gets the type SubQ detects from the file's bytes and filename. Any other type must be one of the supported types. Either way, a file whose bytes don't match a supported type returns 400; see Errors. Word files need a .doc or .docx filename.

cURLTypeScriptPython

Response

{
  "id": "file_abc123",
  "object": "file",
  "bytes": 12345,
  "created_at": 1753742400,
  "expires_at": null,
  "filename": "report.pdf",
  "purpose": "assistants",
  "status": "uploaded"
}

Uploading multiple files

Each request uploads one file — call the endpoint once per file and run the calls concurrently rather than looping with await one at a time:

TypeScriptPython

List files

GET /v1/files
ParamTypeDefaultDescription
limitinteger20Page size (1–10000).
orderstringdescSort by creation time: asc or desc.
afterstring—Keyset cursor; start after this file id.
purposestring—Optional filter (assistants).
cURLTypeScriptPython

Response

{
  "object": "list",
  "data": [
    {
      "id": "file_abc123",
      "object": "file",
      "bytes": 12345,
      "created_at": 1753742400,
      "expires_at": null,
      "filename": "report.pdf",
      "purpose": "assistants",
      "status": "processed"
    }
  ],
  "first_id": "file_abc123",
  "last_id": "file_abc123",
  "has_more": false
}

Paginate with last_id as the next after value until has_more is false.

Retrieve file

GET /v1/files/{file_id}
cURLTypeScriptPython

Returns the File object, or 404 if missing or owned by another org.

Delete file

DELETE /v1/files/{file_id}

Removes stored bytes and metadata.

cURLTypeScriptPython

Response

{
  "id": "file_abc123",
  "object": "file",
  "deleted": true
}

Errors

Errors use the OpenAI-compatible shape:

{
  "error": {
    "message": "No such File object: file_abc123",
    "type": "invalid_request_error",
    "code": "not_found",
    "param": null
  }
}
HTTPcodeWhen
400validation_errorMissing or invalid params
400unsupported_file_typeThe bytes and filename don't identify a supported type
400invalid_file_contentDeclared or named as a PNG, JPEG, or WebP image, but the bytes aren't that format
401invalid_api_keyMissing or invalid API key
403org_suspendedOrganization is suspended or inactive
404not_foundFile missing or owned by another org
413file_too_largeUpload exceeds 50 MiB, or 10 MiB for an image

On this page