openai/gpt-4o-mini routed through the gateway.
1
Install the SDK
Install the Gatelit SDK from npm:The package includes
GatelitClient for sending requests and signToken for issuing signed tokens on your backend.2
Issue a signed token from your backend
signToken runs on your server (Node.js 18+, Next.js API routes, Nuxt server routes, or any edge runtime). It creates a short-lived HMAC token that authorizes a specific user to call a specific model.The signing secret must match the
GATELIT_SIGNING_SECRET configured on your gateway. Keep it server-side only — never expose it to the browser.3
Create a GatelitClient
Instantiate The
GatelitClient with your gateway URL and a getToken function. getToken is called automatically before each request — implement token caching here to avoid unnecessary fetches.scheme field tells the gateway which auth mode to expect. For tokens from signToken, use "GatelitSigned".4
Send a chat request
Call
client.chat() with a model and messages. Models use provider/model-name format:All models follow the
provider/model-name format. For example:openai/gpt-4oanthropic/claude-3-5-sonnet-20241022google/gemini-1.5-promistral/mistral-large-latest
5
Read the response
client.chat() returns a ChatResponse with the following shape:What’s next
Authentication
Learn when to use
GatelitSigned, Bearer, or GatelitKey — and how to configure each.SDK reference
Full reference for
chat(), stream(), chatJson(), and the Conversation helper.