上传文件
流式上传文档、媒体或 UTF-8 文本文件,最多 100 MB。
/anthropic/v1/files● 支持请求体
filestring必填◐ 部分支持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.
支持文本、PDF 和 PNG;按文件内容识别类型,不支持任意二进制。
expires_in_secondsnumber可选◐ 部分支持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).
表单字段支持 3600–7776000 秒;作为查询参数传入返回 400,提示改放表单。
返回
200
SDK 0.128.0 上传参数为表单 file 和可选的表单 expires_in_seconds(3600–7776000 秒)。其他表单字段(包括 purpose)返回 400 invalid_request_error,消息形如 "purpose: Extra inputs are not permitted";查询参数只接受 SDK 自带的 beta,其他查询参数返回 400,查询参数 expires_in_seconds 会提示改放表单。平台将上传文件记为 user_data;不支持 anthropic-workspace-id,请求携带该头时返回 400。
错误按 Anthropic 格式返回,参见 错误码
响应
HTTP 200
File uploaded
application/json
| 名称 | 类型 | 说明 |
|---|---|---|
| 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"`). |