Files
The Files endpoints store files for two uses: model input such as PDFs and images (purpose user_data), and batch input files (purpose batch). They are OpenAI-compatible. You only ever see files uploaded with your Glexir organization, plus the output files of your own batches.
Upload a file
Response:
Then pass the ID to a model, for example as an input_file part with file_id in Responses. Uploading, listing and downloading files does not use credit.
Purposes and limits
Glexir accepts two purposes. Any other value returns 400 with param purpose, even though the FilePurpose type lists more of OpenAI's values.
| Purpose | Use | Max size |
|---|---|---|
user_data | PDFs, images and other model input | 50 MB |
batch | Batch input, must be a .jsonl file | 20 MB |
A file over its limit returns 413 with code file_too_large.
file is an Uploadable (File | Blob | Uint8Array | ArrayBuffer | ReadableStream<Uint8Array> | Response). Give it a filename with an extension: pass a File, or use toFile(data, "name.ext"). See Audio for toFile().
Batch input files
Glexir checks a batch file when you upload it, not when you start the batch. Every line must:
- be valid JSON with a string
custom_idthat is unique in the file, - use
"method": "POST"and aurlof/v1/responses,/v1/chat/completionsor/v1/embeddings, - use the same
urland the samebody.modelas every other line, - have an object
bodywithoutstream: true, - pass the same model and tool rules as a live request to that endpoint.
A batch file can have at most 50,000 lines. Lines can't reference stored responses, conversations or reasoning items (previous_response_id, conversation). A failing line returns 400 with param file and a message such as Batch line 3 needs a unique string custom_id.
Glexir rewrites each line before storing it, the same way it rewrites live requests (for example, the end-user identifier). toBatchJSONL() builds a valid file for you. See Batches.
List files
for await walks every page. To page by hand, await the call for a CursorPage<FileObject> and use hasNextPage() and getNextPage(). See Pagination.
The list comes from Glexir's own records. Batch output and error files are added when Glexir sees the batch finish, for example when you call batches.retrieve().
Retrieve, download and delete
files.content() returns the raw Response. Read it with .text(), .arrayBuffer() or .body. The timeout stops applying once headers arrive, so large downloads aren't cut off.
A file ID that doesn't belong to your organization returns 404.
Methods
All methods take options?: RequestOptions as the last argument. See Client configuration.
glexir.files.create()
POST /files, sent as multipart.
fileUploadablerequired- The file, with a filename. user_data at most 50 MB; batch must be .jsonl and at most 20 MB. The SDK type comment says 512 MB; the gateway limits apply.
purposeFilePurposerequired- user_data or batch on Glexir.
expires_after{ anchor: "created_at"; seconds: number }optional- When the file expires. Batch files expire after 30 days by default; other files stay until you delete them.
glexir.files.retrieve()
GET /files/{file_id}.
glexir.files.list()
GET /files.
afterstringoptional- Return files after this file ID. The SDK sets it for you when paging.
limitnumberoptionaldefault20- Page size.
order"asc" | "desc"optionaldefault"desc"- Sort by creation time.
purposestringoptional- Only files with this purpose, for example batch or batch_output.
glexir.files.delete()
DELETE /files/{file_id}. Returns { id, deleted, object: "file" }.
glexir.files.content()
GET /files/{file_id}/content. Returns the raw Response.
File object
idstringrequired- The file ID.
object"file"required- Always file.
bytesnumberrequired- Size in bytes.
created_atnumberrequired- Unix timestamp in seconds.
filenamestringrequired- The uploaded filename.
purposestringrequired- user_data, batch, or batch_output for batch results. The type also lists OpenAI's other values.
expires_atnumberoptional- Unix timestamp when the file expires.
status"uploaded" | "processed" | "error"optional- Deprecated.
status_detailsstringoptional- Deprecated.
_request_idstring | nulloptional- SDK only. The x-request-id header.
Errors
| Status | Code | When |
|---|---|---|
| 400 | none | purpose is not user_data or batch, file is missing, the body is not multipart, a batch file is not .jsonl, or a batch line fails a check. |
| 404 | none | The file doesn't exist or isn't yours. |
| 409 | cross_account_reference | A batch file references files stored in different Glexir regions. |
| 413 | file_too_large | The file is over its purpose's limit. |
See HTTP error codes for the full list.