- Inline with the request — attach the file directly in the message. Best for one-off requests; nothing to pre-upload.
- Upload first, then reference by
file_id— callfiles.upload(...)once to get afile_id, then reference it on any number of later requests without re-sending the bytes. Best when you ask multiple questions about the same (especially large) file.
Quickstart
Attach a local file inline. Maitai reads the bytes, validates that the target model accepts that file type, and includes it in the request.File inputs require server-side inference (
server_side_inference=True), which
is the default. Maitai needs to run the request to upload and convert the file
for the provider.What’s supported
File support depends on the model. Maitai validates the file against the target model and returns a400 if the model does not accept that file type.
| Provider | Image | Video | Document (PDF) |
|---|---|---|---|
Gemini (e.g. gemini-3.5-flash) | ✓ | ✓ | ✓ |
OpenAI (e.g. gpt-4o) | ✓ | — | ✓ |
- Images — PNG, JPEG, GIF, WebP
- Video — MP4, WebM, MOV (Gemini)
- Documents — PDF
The file content part
A file is just another entry in a message’s content array. It has the shape:
Python
Build an inline file part from a local file path. Reads the file and
base64-encodes it. The MIME type is inferred from the file extension when not
provided.
Node
Build an inline file part from raw bytes (
Uint8Array or Buffer). The MIME
type is required; filename is optional but recommended for documents.Multiple files in one message
Combine text and several files in a single message. Order is preserved.Reuse a file across requests
When you’ll reference the same file in more than one request, upload it once withfiles.upload(...) to get a file_id, then pass that file_id with
file_content_part (Python) / fileContentPart (Node). This avoids re-sending
the bytes — and for video, avoids re-preparing it for the provider — on every
call.
Upload methods
Upload a file from a local path; returns the
file_id. MIME type is inferred
from the extension when not provided.Upload raw bytes; returns the
file_id.Upload a file from a local path; resolves to the
file_id.Upload raw bytes (
Uint8Array or Buffer); resolves to the file_id.maitai.file_content_part(file_id) (Python) / fileContentPart(fileId) (Node)
builds the content part that references an uploaded file.Image URLs
For images already hosted at a public URL, you can use the standard OpenAIimage_url content part instead of uploading bytes:
Errors
The target model does not support that file type. For example, sending a video
to an OpenAI model. Switch to a model that supports it (a Gemini model for
video), or remove the file.
Notes
- Video is uploaded once and prepared for the model, which can take a few seconds for larger files; this happens on the first request that references it.
- Files are scoped to your company and are not shared across accounts.
- File inputs work with the rest of the request as usual — combine them with Structured Output, Tool Calling, and streaming.