GlexirDocs
Dashboard

SDK

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

pnpm add @glexir/sdk

Make a request

TypeScript
import Glexir from "@glexir/sdk";

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

const response = await glexir.responses.create({
  model: "gpt-5.4",
  input: "Say hello in one word.",
});

console.log(response.output_text);

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 import entry and no require entry. Use import, not require().
  • Web platform globals. The SDK uses fetch, Headers, Request/Response, FormData, File, Blob, ReadableStream, TextDecoder, AbortController and URL. Node 20+, Deno, Bun, edge runtimes and browsers all provide them.
  • A fetch you can swap. It uses globalThis.fetch unless you pass your own fetch option.

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:

TypeScript
import Glexir from "@glexir/sdk";
// or: import { Glexir } from "@glexir/sdk";

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:

TypeScript
import type { ChatCompletion, RequestOptions, Response as GlexirResponse } from "@glexir/sdk";

const summarize = (r: GlexirResponse): string => r.output_text;
const firstChoice = (c: ChatCompletion): string | null => c.choices[0]?.message.content ?? null;
const opts: RequestOptions = { timeout: 30_000 };

Resources

Each API area is a property on the client. Every method takes request options as its last argument (see per-request options).

PropertyMethodsPage
glexir.responsescreate, stream, parse, retrieve, cancel, delete, compactResponses
glexir.responses.inputItemslistResponses
glexir.responses.inputTokenscountResponses
glexir.conversationscreate, retrieve, update, deleteConversations
glexir.conversations.itemscreate, retrieve, list, deleteConversations
glexir.chat.completionscreate, stream, parse, retrieve, update, list, deleteChat Completions
glexir.chat.completions.messageslistChat Completions
glexir.audio.transcriptionscreateAudio
glexir.audio.translationscreate (deprecated, shuts down 2027-02-26)Audio
glexir.embeddingscreateEmbeddings
glexir.filescreate, retrieve, list, delete, contentFiles
glexir.batchescreate, retrieve, list, cancelBatches
glexir.modelslist, retrieveModels

The list methods return pages you can walk with for await. See Pagination.

Helpers and classes

These are also exported from @glexir/sdk:

ExportWhat it isPage
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
StreamThe raw event stream returned by create({ stream: true }).Streaming
ResponseStream, ChatCompletionStreamThe helpers returned by responses.stream() and chat.completions.stream().Streaming
APIPromiseThe value every method returns. Adds withRawResponse() and asResponse().Client configuration
CursorPage, PagePromisePages returned by list methods.Pagination
GlexirError, APIError and subclassesErrors the SDK throws.Errors & retries
VERSIONThe SDK version string, e.g. "0.2.0". Sent as x-glexir-sdk: js/<VERSION>.Client configuration
DEFAULT_BASE_URLThe built-in base URL, https://api.glexir.com/v1.Client configuration

Built in

  • Retries. Connection errors and 408, 409, 429 and 5xx responses 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-id as _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.