GlexirDocs
Dashboard

Guides

Use any OpenAI SDK

The Glexir API is OpenAI-compatible. You can use the official openai packages for Node and Python, or any other OpenAI-compatible client, by changing two settings: the API key and the base URL.

  • API key: your Glexir key (glx_live_...).
  • Base URL: https://api.glexir.com/v1.

Model IDs, request bodies, response bodies, streaming events and the error shape are the same as OpenAI's.

Minimal example

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.GLEXIR_API_KEY,
  baseURL: "https://api.glexir.com/v1",
});

const response = await client.responses.create({
  model: "gpt-5.4-mini",
  input: "Name three planets.",
});
console.log(response.output_text);

Configure with environment variables

Both official SDKs read OPENAI_API_KEY and OPENAI_BASE_URL when you pass nothing to the constructor. This lets you switch existing code to Glexir without editing it:

Shell
export OPENAI_API_KEY="glx_live_..."
export OPENAI_BASE_URL="https://api.glexir.com/v1"

If you also set OPENAI_ORG_ID or OPENAI_PROJECT_ID, the SDK sends OpenAI-Organization and OpenAI-Project headers. Glexir ignores them.

What works

Every endpoint below accepts the same parameters as OpenAI, apart from the restrictions in What is rejected.

SDK method (Node)EndpointNotes
responses.create, .retrieve, .delete, .cancel, .compact, .inputItems.list, .inputTokens.count/v1/responses...Streaming, background mode, previous_response_id, structured outputs, reasoning, image and PDF input, function and custom tools.
conversations.create, .retrieve, .update, .delete, .items.*/v1/conversations...
chat.completions.create, .retrieve, .update, .list, .delete, .messages.list/v1/chat/completions...Streaming, tools, structured outputs. Stored completions (store: true) allow up to 15 metadata keys.
embeddings.create/v1/embeddingsThe SDK's default base64 encoding is passed through unchanged.
audio.transcriptions.create, audio.translations.create/v1/audio/...Files up to 25 MB. Translations shut down on 2027-02-26.
files.create, .retrieve, .list, .delete, .content/v1/files...purpose must be user_data or batch.
batches.create, .retrieve, .list, .cancel/v1/batches...Endpoints /v1/responses, /v1/chat/completions and /v1/embeddings; completion_window: "24h".
models.list, models.retrieve/v1/models...Lists only models Glexir sells. owned_by is "glexir".

Only models in Glexir's price book can be called. Check models.list() or Pricing.

What is rejected

The gateway checks every request before it goes upstream. Rejected requests are not charged.

You callResult
Image generation and editing (/v1/images/...), text-to-speech (/v1/audio/speech), moderations, fine-tuning, vector stores, Assistants and Threads, uploads, realtime, videos, containers, evals, the legacy /v1/completions, or any other endpoint not in the table above404 unknown_endpoint
Any tool type in tools other than function, custom or namespace. This covers every OpenAI-hosted tool: web search, file search, code interpreter, MCP, image generation, computer use, shell, apply patch and tool search.400 unsupported_on_glexir
A tool_choice that targets a hosted tool400 unsupported_on_glexir
Input items produced by hosted tools (for example web_search_call, mcp_call)400 unsupported_on_glexir
Audio input (input_audio parts), audio output (audio, modalities: ["audio"]), or web_search_options400 unsupported_on_glexir
A dashboard prompt template (prompt) on the Responses API400 unsupported_on_glexir. Send instructions instead.
An image, TTS, realtime, moderation or fine-tuned model ID400 model_not_found
A -pro model on Chat Completions400 model_not_found. Use the Responses API.
A model without a Glexir price, including dated snapshot names403 model_not_priced
A file purpose other than user_data or batch400

Supported tools are function, custom, and namespace groups of those two.

Differences to know about

Retries and idempotency

The official SDKs retry connection errors and 408, 409, 429 and 5xx responses twice by default. They do not send an Idempotency-Key, so a POST retried after a dropped connection can run, and be billed, twice.

Glexir honours Idempotency-Key on every POST. Send one per logical request and reuse it on retries:

import { randomUUID } from "node:crypto";
import OpenAI from "openai";

const client = new OpenAI({ apiKey: process.env.GLEXIR_API_KEY, baseURL: "https://api.glexir.com/v1" });

const response = await client.responses.create(
  { model: "gpt-5.4-mini", input: "Summarize this ticket." },
  { headers: { "Idempotency-Key": randomUUID() } },
);

@glexir/sdk does this for you on every non-GET request. See Best practices for how keys behave.

End-user identifiers and prompt caching

  • safety_identifier (and the older user field) is replaced by a stable, non-reversible identifier derived from your organization and the value you sent. Keep sending a per-end-user value so abuse is attributed to that user, not your whole organization.
  • prompt_cache_key is prefixed with a value unique to your organization, so cache entries are never shared with other customers. Caching still works across your own requests.

Lists are scoped to you

files.list, batches.list and chat.completions.list return only objects your organization created through Glexir. Objects you created directly on OpenAI are not visible, and their IDs return 404.

Headers

  • x-request-id is Glexir's request ID (req_...). Both SDKs expose it as _request_id on responses and as request_id (Python) or requestID (Node) on errors.
  • Glexir does not send x-ratelimit-* headers. A 429 from the per-minute limit carries retry-after, which both SDKs honour.

Webhooks

Glexir does not forward OpenAI webhooks to you. For background responses and batches, poll responses.retrieve or batches.retrieve.

Error handling

Errors use OpenAI's shape, so the SDKs raise their usual classes. Glexir adds two statuses the SDKs have no class for: 402 (credit or spend limit) and 413 (too large). They arrive as the base status error class.

import OpenAI from "openai";

const client = new OpenAI({ apiKey: process.env.GLEXIR_API_KEY, baseURL: "https://api.glexir.com/v1" });

try {
  await client.responses.create({ model: "gpt-5.4-mini", input: "Hello" });
} catch (err) {
  if (err instanceof OpenAI.APIError && err.status === 402) {
    console.error("Add credits or raise your spend limit:", err.code, err.requestID);
  } else {
    throw err;
  }
}

See HTTP error codes for every code.

Other clients

Any client that lets you set the base URL and a bearer token works the same way: set the base URL to https://api.glexir.com/v1 and the key to your glx_live_... key. Clients that call endpoints Glexir does not serve get 404 unknown_endpoint for those calls.