Skip to main content
This guide walks you through installing the SDK, issuing an auth token, and sending your first chat request. By the end you’ll have a working call to 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.
In a real application, expose this as an API route that your frontend calls before each request:
3

Create a GatelitClient

Instantiate GatelitClient with your gateway URL and a getToken function. getToken is called automatically before each request — implement token caching here to avoid unnecessary fetches.
The 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-4o
  • anthropic/claude-3-5-sonnet-20241022
  • google/gemini-1.5-pro
  • mistral/mistral-large-latest
5

Read the response

client.chat() returns a ChatResponse with the following shape:
Full example putting it all together:

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.