跳转到内容
EN

上传文件

POST/openai/v1/files◐ 部分支持

OpenAI 官方文档 ↗

请求体

  • filestring必填

    The File object (not file name) to be uploaded.

    已验证生效。

  • purposestring必填◐ 部分支持

    文件用途:user_data、assistants 或 vision(vision 只接受 PNG、JPEG、GIF、WebP 图片)。OpenAI 的 batch、fine-tune、evals 等其余用途不支持,返回 400 PURPOSE_UNSUPPORTED。

    支持 user_data、assistants、vision;batch、fine-tune、evals 等其余值返回 400。

    取值 user_dataassistantsvision
  • expires_afterobject可选

    The expiration policy for a file. By default, files with purpose=batch expire after 30 days and all other files are persisted until they are manually deleted.

    anchor=created_at,seconds=3600–2592000。

    展开子字段 (2)
    • anchorstring必填

      Anchor timestamp after which the expiration policy applies. Supported anchors: created_at.

      取值 created_at
    • secondsinteger必填

      The number of seconds after the anchor time that the file will expire. Must be between 3600 (1 hour) and 2592000 (30 days).

返回

200 file

单文件最多 100 MB(100000000 字节);按内容识别 PDF、Office、图片、音频、视频与 UTF-8 文本。purpose 支持 user_data / assistants / vision;其他用途、空文件、不支持类型和超限均返回 400。超过 100 MB 的文件使用 Uploads 分片上传。只接受表单 file、purpose、expires_after[anchor]、expires_after[seconds];其他表单字段或任何查询参数返回 400 invalid_request_error,消息为 "Unrecognized request argument supplied: <字段>",param 为该字段。

错误按 OpenAI 格式返回,参见 错误码

请求示例

curl
curl https://api.deepraxis.com/openai/v1/files \
  -H "Authorization: Bearer $PRAXIS_API_KEY" \
  -F "purpose=user_data" \
  -F "file=@pixel.png"
Python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.deepraxis.com/openai/v1",
    api_key="$PRAXIS_API_KEY",
)

file = client.files.create(
    file=open("pixel.png", "rb"),
    purpose="user_data",
)
TypeScript
import OpenAI from "openai";
import fs from "node:fs";

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

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

响应示例 200

{
  "id": "file_dp_01M41EAAEQ3N9T5T1D5Y6PYXNB",
  "object": "file",
  "bytes": 70,
  "created_at": 1791049935,
  "filename": "pixel.png",
  "purpose": "user_data",
  "status": "processed",
  "status_details": null
}

响应

HTTP 200

OK

application/json

名称 类型 说明
id string The file identifier, which can be referenced in the API endpoints.
bytes integer The size of the file, in bytes.
created_at integer The Unix timestamp (in seconds) for when the file was created.
expires_at integer The Unix timestamp (in seconds) for when the file will expire.
filename string The name of the file.
object string The object type, which is always file.
purpose string The intended purpose of the file. Supported values are assistants, assistants_output, batch, batch_output, fine-tune, fine-tune-results, vision, and user_data.
status string Deprecated. The current status of the file, which can be either uploaded, processed, or error.
status_details string Deprecated. For details on why a fine-tuning training file failed validation, see the error field on fine_tuning.job.