Upload a file
Stream a document
/anthropic/v1/files● SupportedRequest body
filestring必填◐ Partially supportedBody 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 supportedBody 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
| Name | Type | Description |
|---|---|---|
| id | string | Unique object identifier. The format and length of IDs may change over time. |
| created_at | string | RFC 3339 datetime string representing when the file was created. |
| filename | string | Original filename of the uploaded file. |
| mime_type | string | MIME type of the file. |
| size_bytes | number | Size of the file in bytes. |
| type | string | Object type. For files, this is always `"file"`. |
| downloadable | boolean | Whether the file can be downloaded. |
| expires_at | null | string | RFC 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. |
| scope | null | object | The scope of this file, indicating the context in which it was created (e.g., a session). |
| scope.id | string | The ID of the scoping resource (e.g., the session ID). |
| scope.type | string | The type of scope (e.g., `"session"`). |