Skip to main content
This guide walks you through everything you need to go from zero to a working AI response using the Gatelit gateway.
1

Install the SDK

Install @gatelit/sdk in your project:
The SDK is ESM-first and ships TypeScript types. It works in browsers, Node.js 18+, and edge runtimes (Cloudflare Workers, Vercel Edge, etc.).
2

Issue signed tokens from your backend

Gatelit uses short-lived signed tokens to authenticate client requests. Your backend signs each token with your GATELIT_SIGNING_SECRET — the token is never stored, and expires after a configurable TTL (default: 60 seconds).Import signToken from @gatelit/sdk/sign in a server-side handler:
The signToken function uses the Web Crypto API (available natively in Node 18+ and all edge runtimes) and returns a compact dot-separated string you pass directly to the client.
You can restrict a token to a specific model, cap its output tokens, and embed an org ID for provider key resolution. See the SignedTokenOptions type for the full set of options.
3

Create a GatelitClient

On the client side, instantiate GatelitClient with your gateway URL and a getToken function that fetches a fresh token from your backend endpoint:
getToken is called before every request. You should add token caching in your implementation to avoid an extra round-trip on every request.
4

Send your first chat request

Call client.chat() with a model in provider/model-name format and an array of messages:
Supported model formats:
5

Handle the response

client.chat() returns a ChatResponse with the following shape:
A complete example:
Every response includes an x-gatelit-request-id response header that matches response.meta.requestId. You can paste this ID into the Gatelit dashboard to look up the full request log, including token usage, latency, and model routing details.