终端用户上传文件(扩展)
/agent/v1/uploads● 支持请求体
agentstring可选要运行的智能体:智能体 ID 字符串,或对象 {type, id, version?}(见子字段);版本与覆盖规则见操作说明。
filenamestring必填The file's name, its extension included; the extension decides which blocked executable and script types are refused. 1 to 255 characters.
bytesinteger必填The exact byte length of the file to upload; refused with 413 FILE_TOO_LARGE when it exceeds the agent's uploads.max_file_bytes.
content_typestring必填The file's MIME type, such as image/png, stored on the file; not used to refuse the upload. 1 to 255 characters.
返回
201
仅在 /agent/v1 提供,只给终端用户令牌(绑定单个智能体的 end_user 令牌,或组织级的 customer 令牌;customer 令牌必须在请求体带 agent)。请求体:filename(1–255 字符)、bytes(正整数,字节数)、content_type(1–255 字符),customer 令牌另加 agent。返回 File 的签名上传回答:upload_id、expires_at,以及小文件的 url,或大文件的 part_size、parts、complete_url、status_url;签名地址只在本次响应里返回,不落库、不写日志,浏览器拿到后直接把字节 PUT 到该地址,得到 File 对象与 file_id。之后用 file_id 把文件挂到自己的会话(作为会话资源),再在消息的 attachments 里引用它。校验顺序:智能体不存在或其上的上传被关返回 403 UPLOADS_DISABLED;bytes 超过智能体的 uploads.max_file_bytes 返回 413 FILE_TOO_LARGE;扩展名在黑名单(可执行与脚本)返回 400 FILE_TYPE_REFUSED;同一用户对同一智能体过去一小时内未挂会话的上传达到 30 条返回 429 UPLOAD_RATE_LIMITED。成员、robot、user_key 令牌用 /file/v1,不走这里(404)。
错误按 Anthropic 错误格式返回(type / message / request_id),参见 错误码
请求示例
curl
curl https://api.deepraxis.com/agent/v1/uploads \
-H "Authorization: Bearer $CUSTOMER_ACCESS_TOKEN" \
-H "Origin: https://docs.example.com" \
-H "Content-Type: application/json" \
-d '{"filename":"sample.txt","bytes":11,"content_type":"text/plain"}'Python
import requests
opts = dict(
base_url="https://api.deepraxis.com/agent",
api_key="$PRAXIS_API_KEY",
)
# /agent 是我们自己的 Managed Agents 形状,直接发 HTTP 请求(Bearer 认证)
resp = requests.post(
f"{opts['base_url']}/v1/uploads",
headers={"Authorization": f"Bearer {customer_access_token}", "Origin": "https://docs.example.com"},
json={"filename":"sample.txt","bytes":11,"content_type":"text/plain"},
)
print(resp.status_code, resp.json())TypeScript
const opts = {
baseURL: "https://api.deepraxis.com/agent",
apiKey: "$PRAXIS_API_KEY",
};
// /agent 是我们自己的 Managed Agents 形状,直接发 HTTP 请求(Bearer 认证)
const resp = await fetch(`${opts.baseURL}/v1/uploads`, {
method: "POST",
headers: { Authorization: `Bearer ${customerAccessToken}`, Origin: "https://docs.example.com", "Content-Type": "application/json" },
body: JSON.stringify({"filename":"sample.txt","bytes":11,"content_type":"text/plain"}),
});
console.log(resp.status, await resp.json());响应示例 201
{
"url": "<redacted>",
"upload_id": "su_rbmKmgLWFsksiSOAseui76OW",
"expires_at": "2026-11-18T11:05:52.000Z"
}响应
HTTP 201
The upload started; put the file body to the returned signed address.
application/json
| 名称 | 类型 | 说明 |
|---|---|---|
| upload_id | string | Upload id (upl_…) that identifies this upload to the File service; not a file id. |
| expires_at | string | RFC 3339 time the signed address stops working; start a new upload after it. / RFC 3339 time the signed addresses stop working; start a new upload after it. |
| url | string | Address to PUT the whole file body to in one request; that request finishes the upload. |
| part_size | integer | Recommended byte length of each part; PUT every part at this size, except the last. |
| parts | array<object> | The part addresses in order; use them instead of url when the file exceeds the single-request limit. |
| parts[].part_number | integer | The part's 1-based position, in order. |
| parts[].url | string | Address to PUT this part's bytes to; keep the answer's ETag for the complete call. |
| complete_url | string | Address to POST the collected part ETags to, which assembles the file and answers the File object. |
| status_url | string | Read-only address answering the same shape as the File upload status, for a client with no API key. |