创建分片上传
/file/v1/uploads◐ 部分支持请求体
purposestring必填Use user_data for conversation attachments, assistants for assistant files, or vision for PNG, JPEG, GIF and WebP images.
expires_afterobject可选Optional expiry policy for the resulting file; omission retains the file until deletion.
展开子字段 (2)
anchorstring可选Expiry is measured from file creation; created_at is the only supported anchor.
secondsinteger必填Resulting file lifetime in seconds; omit expires_after to retain it until deletion.
bytesinteger必填Exact complete file length in bytes, from 1 through 21474836480 (20 GiB); the sum of completed parts must match.
filenamestring必填Filename for the resulting file, at most 255 UTF-8 bytes.
mime_typestring必填Declared MIME type; validated against the assembled content.
part_sizeinteger可选Optional fixed part size in bytes, 5242880–64000000. Requires part_number on every part; retries of identical bytes at the same number return the same part. Omit to use arbitrary-sized parts.
返回
200 upload
每片最多 64 MB,总量最多 20 GiB。仅支持 user_data、assistants、vision;未完成上传 7 天后过期。可用 GET /file/v1/uploads/{upload_id} 查询已收到的分片,只补传缺失的分片再完成。流程:创建 → 传片 → 查询 → 补传 → 完成;完成后须等文件处理完成才能使用。
错误按 OpenAI 格式返回,参见 错误码
请求示例
curl
curl https://api.deepraxis.com/file/v1/uploads \
-H "Authorization: Bearer $PRAXIS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"bytes":11534336,"filename":"document.txt","mime_type":"text/plain","purpose":"user_data","part_size":5242880}'Python
from openai import OpenAI
client = OpenAI(
base_url="https://api.deepraxis.com/file/v1",
api_key="$PRAXIS_API_KEY",
)
upload = client.uploads.create(bytes=11534336, filename="document.txt", mime_type="text/plain", purpose="user_data", extra_body={"part_size": 5242880})
print(upload.id)TypeScript
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.deepraxis.com/file/v1",
apiKey: "$PRAXIS_API_KEY",
});
const upload = await client.uploads.create({ bytes: 11534336, filename: "document.txt", mime_type: "text/plain", purpose: "user_data", ...{ part_size: 5242880 } });
console.log(upload.id);响应示例 200
{
"id": "upload_XTVtShoLFqNNohPQSkj7RVrz",
"object": "upload",
"bytes": 11534336,
"created_at": 1792684714,
"expires_at": 1792688314,
"filename": "document.txt",
"purpose": "user_data",
"status": "pending",
"mime_type": "text/plain",
"file": null,
"error": null
}响应
HTTP 200
The upload state and, after completion, the resulting file.
application/json
| 名称 | 类型 | 说明 |
|---|---|---|
| id | string | Upload identifier returned by create. Use this value for parts, complete and cancel. |
| object | string | Object type; upload identifies an upload session. |
| bytes | integer | Declared size of the complete file in bytes. |
| created_at | integer | Creation time as Unix seconds. |
| expires_at | integer | Expiry time as Unix seconds; unfinished uploads expire after 7 days. |
| filename | string | Filename supplied when creating the upload. |
| purpose | string | File purpose: user_data for conversation attachments, assistants for assistant files, vision for images. |
| status | string | Upload state: pending accepts parts; completed has a file; cancelled was cancelled; expired exceeded its seven-day lifetime. |
| file | object | null | Present after complete. A file with status uploaded is still processing; poll files.retrieve until processed before use. |
| file.id | string | File identifier: file- followed by 24 base62 characters. Use the ID returned by upload or list. |
| file.bytes | integer | The size of the file, in bytes. |
| file.created_at | integer | The Unix timestamp (in seconds) for when the file was created. |
| file.expires_at | integer | null | The Unix timestamp (in seconds) for when the file will expire. |
| file.filename | string | The name of the file. |
| file.object | string | The object type, which is always file. |
| file.purpose | string | Upload purpose. Image references in conversations require user_data. |
| file.status | string | Deprecated. The current status of the file, which can be either uploaded, processed, or error. |
| file.mime_type | string | Content-detected MIME type. |
| file.scope | object | null | Session scope for session outputs; null for other files. |
| file.relative_path | string | Path within the session output directory; present for session outputs. |
| file.revision | integer | Session output revision; present for session outputs. |
| file.state | string | processing is not yet usable; active is ready; expired cannot be read. |
| file.source | string | upload is user-provided, generated is platform-produced, session is a session output. |
| file.sha256 | string | Content digest, prefixed sha256:. Available after processing completes. |
| part_size | integer | null | Fixed part length in bytes for a fixed-size upload, or null for a general upload. Send exactly this many bytes per numbered part except for the final remainder. |
| received_parts | array<object> | Parts the upload already holds, in resume order: numbered parts by number, then a general upload's parts by arrival. Query GET /file/v1/uploads/{upload_id} after a break and resend only the numbers missing here. |
| received_parts[].part_number | integer | null | Fixed part number, or null for a part of a general upload. |
| received_parts[].id | string | Part identifier to pass to complete for this content. |
| received_parts[].bytes | integer | Accepted length of this part in bytes. |
| received_parts[].sha256 | string | Part content digest prefixed sha256:. |
| mime_type | string | Declared MIME type, verified during assembly. |
| error | object | null | Assembly failure, or null if no failure is recorded. |
| error.code | string | File service error code identifying the assembly failure. |
| error.message | string | Explanation of why assembly failed. |
自动分片上传
TypeScript helper 接受 Blob 或 File,上限 2 GiB;自动重试、取消和轮询,返回时文件已可用。
import { Praxis } from "@deepraxis/sdk";import { readFile } from "node:fs/promises";const praxis = new Praxis({ apiKey: process.env.PRAXIS_API_KEY });const file = await praxis.file.uploadFile(new File([await readFile("document.txt")], "document.txt", { type: "text/plain" }), { purpose: "user_data" });console.log(file.id, file.state); // active