Overview & installation
@glexir/sdk is the official TypeScript SDK for the Glexir API. It sends the same requests and returns the same objects as OpenAI's API, so code written for OpenAI's SDK ports over with few changes. It has no runtime dependencies.
Install
Make a request
Get a key (it starts with glx_live_) from the dashboard and put it in GLEXIR_API_KEY.
The client calls https://api.glexir.com/v1 by default. To use a local gateway or another deployment, see Base URL.
Requirements and runtimes
- Node.js 20 or later. The package declares
"engines": { "node": ">=20" }. - ES modules only. The package exports an
importentry and norequireentry. Useimport, notrequire(). - Web platform globals. The SDK uses
fetch,Headers,Request/Response,FormData,File,Blob,ReadableStream,TextDecoder,AbortControllerandURL. Node 20+, Deno, Bun, edge runtimes and browsers all provide them. - A
fetchyou can swap. It usesglobalThis.fetchunless you pass your ownfetchoption.
The client reads GLEXIR_API_KEY and GLEXIR_BASE_URL from process.env only when a global process exists. On runtimes without it (browsers, most edge runtimes), pass apiKey and baseURL to the constructor yourself.
Keep keys on the server
Anyone who can read your page's JavaScript can read a key you ship to a browser. Call Glexir from your server and send results to the browser instead.
Imports
The client is both the default export and a named export:
Every request and response type is exported too; Type reference lists them all. Response (the Responses API object) has the same name as the global Response, so alias it:
Resources
Each API area is a property on the client. Every method takes request options as its last argument (see per-request options).
| Property | Methods | Page |
|---|---|---|
glexir.responses | create, stream, parse, retrieve, cancel, delete, compact | Responses |
glexir.responses.inputItems | list | Responses |
glexir.responses.inputTokens | count | Responses |
glexir.conversations | create, retrieve, update, delete | Conversations |
glexir.conversations.items | create, retrieve, list, delete | Conversations |
glexir.chat.completions | create, stream, parse, retrieve, update, list, delete | Chat Completions |
glexir.chat.completions.messages | list | Chat Completions |
glexir.audio.transcriptions | create | Audio |
glexir.audio.translations | create (deprecated, shuts down 2027-02-26) | Audio |
glexir.embeddings | create | Embeddings |
glexir.files | create, retrieve, list, delete, content | Files |
glexir.batches | create, retrieve, list, cancel | Batches |
glexir.models | list, retrieve | Models |
The list methods return pages you can walk with for await. See Pagination.
Helpers and classes
These are also exported from @glexir/sdk:
| Export | What it is | Page |
|---|---|---|
toFile(data, name?, { type? }) | Wraps bytes, a Blob, a stream or a Response in a File with a filename. | Audio, Files |
toBatchJSONL(lines) | Builds a batch.jsonl File for files.create({ purpose: "batch" }). | Batches |
toStrictJsonSchema(schema) | Rewrites a JSON Schema for strict structured outputs. Throws StrictSchemaError. | Responses |
Stream | The raw event stream returned by create({ stream: true }). | Streaming |
ResponseStream, ChatCompletionStream | The helpers returned by responses.stream() and chat.completions.stream(). | Streaming |
APIPromise | The value every method returns. Adds withRawResponse() and asResponse(). | Client configuration |
CursorPage, PagePromise | Pages returned by list methods. | Pagination |
GlexirError, APIError and subclasses | Errors the SDK throws. | Errors & retries |
VERSION | The SDK version string, e.g. "0.2.0". Sent as x-glexir-sdk: js/<VERSION>. | Client configuration |
DEFAULT_BASE_URL | The built-in base URL, https://api.glexir.com/v1. | Client configuration |
Built in
- Retries. Connection errors and
408,409,429and5xxresponses are retried twice by default, with exponential backoff. - Idempotency keys. Every non-GET request sends an
Idempotency-Key. Retries reuse it, so the gateway never runs (or bills) a retried POST twice. - Request IDs. Every parsed JSON object carries the gateway's
x-request-idas_request_id. Quote it when you contact support.
Details are in Errors & retries.
Not included
Glexir covers text models, embeddings and speech-to-text. The SDK has no methods for images, text-to-speech, realtime or WebSocket, video, assistants, fine-tuning, vector stores or uploads.