跳转到内容
EN

上传文件

POST/anthropic/v1/files● 支持

Anthropic 官方文档 ↗

请求体

  • 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 格式返回,参见 错误码

请求示例

curl
curl https://api.deepraxis.com/anthropic/v1/files \
  -H "x-api-key: $PRAXIS_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -F "file=@pixel.png"
Python
from anthropic import Anthropic

client = Anthropic(
    base_url="https://api.deepraxis.com/anthropic",
    api_key="$PRAXIS_API_KEY",
)

file = client.files.upload(
    file=open("pixel.png", "rb"),
)
TypeScript
import Anthropic from "@anthropic-ai/sdk";
import fs from "node:fs";

const client = new Anthropic({
  baseURL: "https://api.deepraxis.com/anthropic",
  apiKey: "$PRAXIS_API_KEY",
});

const file = await client.files.upload({
  file: fs.createReadStream("pixel.png"),
});

响应示例 200

{
  "id": "file_dp_01M42FVDJD8QGPRQ0059E7V056",
  "type": "file",
  "filename": "pixel.png",
  "mime_type": "image/png",
  "size_bytes": 70,
  "created_at": "2026-10-04T03:38:18.651Z",
  "expires_at": null,
  "downloadable": false
}

响应

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").