This guide has an independently written Vietnamese edition. Đọc bằng Tiếng Việt
Upload and reference a file
Upload a file once with POST /v1/files. The examples expect a supported file named notes.pdf in the current directory. Use its returned id in a Chat Completions message part instead of resending the bytes. Keep the gateway behavior in mind: uploaded attachments go through text extraction/OCR and are supplied to the model as analyzed text. This is not a claim of full original-image vision support.
import os
from uuid import uuid4
from openai import OpenAI
client = OpenAI(
api_key=os.environ["TASKWAY_API_KEY"],
base_url=os.environ["TASKWAY_BASE_URL"],
)
with open("notes.pdf", "rb") as document:
uploaded = client.files.create(file=document, purpose="user_data")
completion = client.chat.completions.create(
model="auto",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "Summarize this file."},
{"type": "file", "file": {"file_id": uploaded.id}},
],
}],
extra_headers={"Idempotency-Key": str(uuid4())},
)
print(completion.choices[0].message.content)
import { createReadStream } from "node:fs";
import { randomUUID } from "node:crypto";
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.TASKWAY_API_KEY,
baseURL: process.env.TASKWAY_BASE_URL,
});
const uploaded = await client.files.create({
file: createReadStream("notes.pdf"),
purpose: "user_data",
});
const completion = await client.chat.completions.create(
{
model: "auto",
messages: [{
role: "user",
content: [
{ type: "text", text: "Summarize this file." },
{ type: "file", file: { file_id: uploaded.id } },
],
}],
},
{ headers: { "Idempotency-Key": randomUUID() } },
);
console.log(completion.choices[0]?.message.content);
Endpoints and application scope
| Operation | Endpoint |
|---|---|
| Upload | POST /v1/files |
| List | GET /v1/files |
| Retrieve metadata | GET /v1/files/{file_id} |
| Download content | GET /v1/files/{file_id}/content |
| Delete | DELETE /v1/files/{file_id} |
Files belong to the application that uploaded them. A key for another application cannot list, read, download, delete, or reference them. GET /v1/files supports limit, after, order, and purpose; check has_more and use the returned cursor to fetch another page if needed.
Size, expiry, and media support
- Default maximum file size: 50 MiB. The default application storage quota is 1 GiB.
- Files expire after one day by default. Set
expires_after[anchor]=created_atandexpires_after[seconds]to choose an expiry from one hour through seven days. - Allowed
purposevalues areuser_data,vision, andassistants. This gateway’s profile and retention behavior differ from OpenAI’s full Files service. - Supported MIME types are limited to PDF, supported image formats, and analyzable text formats. Unsupported types fail during upload.
- Remote image URLs are rejected. Attachments are analyzed into text surrogates; the gateway does not pass an original image through as a vision payload.
- An individual attachment can have a lower 20 MiB analysis limit. OCR availability depends on deployment configuration. If attachment analysis is disabled or fails, the request may fail before model execution.
Defaults come from the current source configuration; a deployment can set stricter limits.
Delete a file
Use client.files.delete(file_id). Deletion is scoped to the owning application, removes the file from public access, and releases its active quota. Expired or deleted content is not restored by retrying an older generation request.