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 os
from openai import OpenAI
client = OpenAI(
base_url="https://opendunes.com/v1",
api_key=os.environ["OPENDUNES_API_KEY"],
)
uploaded = client.files.create(
file=open("report.pdf", "rb"),
purpose="user_data",
)
print(uploaded.id) # reference this id in chat requestsSend a file content part carrying the file_id — the server inlines the bytes for you:
completion = 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": uploaded.id}},
],
}
],
)client.files.list(), client.files.retrieve(id), and client.files.delete(id) manage stored files — see the Files guide for the full surface.