@gatelit/sdk.
GatelitClientConfig
interface GatelitClientConfig {
gatewayUrl: string
getToken: () => Promise<{
token: string
scheme: TokenScheme
}>
}
| Field | Type | Description |
|---|---|---|
gatewayUrl | string | Base URL of your deployed gateway |
getToken | () => Promise<{ token, scheme }> | Called before each request to get a fresh auth token |
TokenScheme
type TokenScheme = "Bearer" | "GatelitSigned" | "GatelitKey"
ChatOptions
interface ChatOptions {
model: string // "provider/model-id"
messages: ChatMessage[] // At least one message
maxTokens?: number // Max output tokens
temperature?: number // 0–2
signal?: AbortSignal // For cancellation
outputSchema?: { // Structured output config
mode: "json_object" | "json_schema"
[key: string]: unknown
} | null
promptId?: string // Link to a saved prompt (UUID)
endUserId?: string // End-user ID for log filtering (header only)
user?: string // End-user ID forwarded to the provider (OpenAI-standard `user` field)
metadata?: Record<string, string | number | boolean> // Arbitrary tags — stored on the log, filterable in the dashboard
requestSource?: "api" | "dashboard" | "eval"
cache?: boolean | { ttl: number } // Opt-in exact-match response cache (deterministic requests only)
}
ChatMessage
type ChatMessageContent =
| string
| ChatMessageContentPart[]
interface ChatMessage {
role: "system" | "user" | "assistant"
content: ChatMessageContent
}
content may be plain text, a string of block JSON, or an array of content parts for multimodal requests:
type ChatMessageContentPart =
| { type: "text"; text: string }
| { type: "image_url"; image_url: { url: string } }
| { type: "file"; file: {
mime_type?: string
file_data?: string
file_id?: string
url?: string
} }
ChatResponse
interface ChatResponse {
content: string
model: string
usage: Usage | null
finishReason: string | null
meta: GatelitMeta
}
StreamChunk
interface StreamChunk {
delta: string
model: string | undefined
finishReason: string | null
usage: Usage | null
usedFallback?: boolean // true when a fallback model handled the request
fallbackReason?: string // provider_error | rate_limit | timeout | refusal_detected | cache
fallbackModel?: string // the fallback model that responded
clampedParams?: Record<string, string> // present when the gateway clamped a param
}
Usage
interface Usage {
inputTokens: number
outputTokens: number
totalTokens: number
}
GatelitMeta
interface GatelitMeta {
requestId: string
model: string
usedFallback?: boolean // true when a fallback model handled the request
fallbackReason?: string // provider_error | rate_limit | timeout | refusal_detected | cache
fallbackModel?: string // the fallback model that responded
clampedParams?: Record<string, string> // e.g. { max_tokens: "10000->4096" } when the gateway clamped a param
cacheHit?: boolean // true when the response was served from the gateway cache
}
GatelitError
class GatelitError extends Error {
code: string // "unauthorized" | "gateway_error" | "provider_error" | "invalid_json"
message: string
status: number // HTTP status
}
ConversationOptions
interface ConversationOptions {
model: string
systemPrompt?: string
maxTokens?: number
temperature?: number
tools?: Tool[]
toolChoice?: ToolChoice
endUserId?: string
metadata?: RequestMetadata
user?: string
cache?: boolean | { ttl: number } // Opt-in exact-match response cache
}