GlexirDocs
Dashboard

API

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

import { readFile } from "node:fs/promises";
import Glexir, { toFile } from "@glexir/sdk";

const glexir = new Glexir({ apiKey: process.env.GLEXIR_API_KEY });

const file = await glexir.files.create({
  file: await toFile(await readFile("report.pdf"), "report.pdf"),
  purpose: "user_data",
});

console.log(file.id); // file-...

Response:

JSON
{
  "id": "file-abc123",
  "object": "file",
  "bytes": 182044,
  "created_at": 1761350400,
  "filename": "report.pdf",
  "purpose": "user_data"
}

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.

PurposeUseMax size
user_dataPDFs, images and other model input50 MB
batchBatch input, must be a .jsonl file20 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_id that is unique in the file,
  • use "method": "POST" and a url of /v1/responses, /v1/chat/completions or /v1/embeddings,
  • use the same url and the same body.model as every other line,
  • have an object body without stream: 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

TypeScript
import Glexir from "@glexir/sdk";

const glexir = new Glexir();

for await (const file of glexir.files.list({ purpose: "batch", limit: 50 })) {
  console.log(file.id, file.filename, file.bytes);
}

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

TypeScript
import Glexir from "@glexir/sdk";

const glexir = new Glexir();

const info = await glexir.files.retrieve("file-abc123");

const response = await glexir.files.content("file-abc123");
const text = await response.text();

const deleted = await glexir.files.delete("file-abc123");
console.log(deleted.deleted); // true

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.

TypeScript
import type { APIPromise, FileCreateParams, FileDeleted, FileListParams, FileObject, PagePromise, RequestOptions } from "@glexir/sdk";

// The methods on glexir.files
interface Files {
  create(body: FileCreateParams, options?: RequestOptions): APIPromise<FileObject>;
  retrieve(fileId: string, options?: RequestOptions): APIPromise<FileObject>;
  list(query?: FileListParams, options?: RequestOptions): PagePromise<FileObject>;
  delete(fileId: string, options?: RequestOptions): APIPromise<FileDeleted>;
  content(fileId: string, options?: RequestOptions): APIPromise<Response>;
}

glexir.files.create()

POST /files, sent as multipart.

FileCreateParams
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.

FileListParams
afterstringoptional
Return files after this file ID. The SDK sets it for you when paging.
limitnumberoptionaldefault 20
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

FileObject
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

StatusCodeWhen
400nonepurpose 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.
404noneThe file doesn't exist or isn't yours.
409cross_account_referenceA batch file references files stored in different Glexir regions.
413file_too_largeThe file is over its purpose's limit.

See HTTP error codes for the full list.