Upload files once and reference them by id in chat requests.
The files endpoint stores a file once so you can reference it by id in any number of chat requests instead of re-encoding the bytes into every message. The upload takes the same multipart form as the OpenAI files endpoint, so client.files.create sends it as is. The file object that comes back carries OpenDunes' own fields (filename, mime_type, size_bytes, created_at, downloadable), listed in the Files guide; id is the one to keep. Uploads, storage and downloads are free.
import fs from "node:fs";
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://opendunes.com/v1",
apiKey: process.env.OPENDUNES_API_KEY,
});
const file = await client.files.create({
file: fs.createReadStream("report.pdf"),
purpose: "user_data",
});
console.log(file.id); // reference this id in chat requestsSend a file content part carrying the file_id — the server inlines the bytes for you:
const completion = await client.chat.completions.create({
model: "google/gemini-2.5-flash",
messages: [
{
role: "user",
content: [
{ type: "text", text: "Summarize this document." },
{ type: "file", file: { file_id: file.id } },
],
},
],
});