Anthropic

Upload a file

Stream a document

POST /anthropic/v1/files● Supported

Official Anthropic docs ↗

Request body

  • filestring必填◐ Partially supported

    Body param: The file to upload. Only the final path component of the part's `filename` is kept; an absent or empty `filename` is replaced with `unnamed` plus the extension for the file's stored `mime_type`, when known.

    Text, PDF and PNG uploads are accepted. Types are detected from content; arbitrary binary data is not supported.

  • expires_in_secondsnumber可选◐ Partially supported

    Body param: Seconds from upload until the file expires and its bytes become permanently unavailable. Must be between 3600 (one hour) and 7776000 (ninety days).

    The form field supports 3600–7776000 seconds; as a query parameter it returns 400 asking you to send it in the form.

Returns

200

SDK 0.128.0 sends form file and optional form expires_in_seconds (3600–7776000 seconds). Any other form field, including purpose, returns 400 invalid_request_error such as "purpose: Extra inputs are not permitted". The only accepted query parameter is the SDK's beta; other query parameters return 400, and a query expires_in_seconds is told to move into the form. Uploads are stored as user_data. anthropic-workspace-id is not supported and returns 400.

Errors follow the Anthropic format — see error codes

Response

HTTP 200

File uploaded

application/json

NameTypeDescription
idstringUnique object identifier. The format and length of IDs may change over time.
created_atstringRFC 3339 datetime string representing when the file was created.
filenamestringOriginal filename of the uploaded file.
mime_typestringMIME type of the file.
size_bytesnumberSize of the file in bytes.
typestringObject type. For files, this is always `"file"`.
downloadablebooleanWhether the file can be downloaded.
expires_atnull | stringRFC 3339 datetime string representing when the file will expire and become unavailable for download. Null if the file does not expire. For files uploaded with `expires_in_seconds`, this is the upload time plus that value.
scopenull | objectThe scope of this file, indicating the context in which it was created (e.g., a session).
scope.idstringThe ID of the scoping resource (e.g., the session ID).
scope.typestringThe type of scope (e.g., `"session"`).