Skip to main content
The LLMGateway constructor accepts a configuration object that defines your backends, adapters, and environment settings.
import { LLMGateway } from '@betterdata/commerce-gateway';

const gateway = new LLMGateway(config);

Config Object

backends (Required)

An object containing implementations of the core commerce interfaces.
  • products: ProductBackend - Required.
  • cart: CartBackend - Optional.
  • orders: OrderBackend - Optional.
  • links: LinkGenerator - Optional.

session

Configuration for conversation state management.
  • redis: { url: string; token?: string } - Use for persistent sessions.
  • ttl: number - Session expiration in seconds (default: 86400).
  • keyPrefix: string - Prefix for Redis keys (default: bd-session:).

auth

Access control settings.
  • apiKeys: string[] - List of allowed API keys for the gateway.
  • secret: string - Secret for signing JWTs or webhooks.

llmProviders

List of LLM providers to optimize for. This influences the “personality” and formatting of tool responses.
  • anthropic
  • openai
  • grok
  • google (Gemini) - COMING SOON

logging

  • level: 'debug' | 'info' | 'warn' | 'error'
  • format: 'json' | 'pretty'
  • external: Function for custom log aggregation.

Environment Variables

The gateway also respects several environment variables for easy deployment on platforms like Vercel or Docker.
VariableDescription
REDIS_URLRedis connection string.
REDIS_TOKENAuth token for Redis (Upstash).
GATEWAY_API_KEYDefault API key for the gateway.
LOG_LEVELLogging verbosity.
PORTThe port to listen on (default: 3000).

Advanced: Programmatic Registration

You can also register backends and tools after initialization:
gateway.registerBackend('custom', myPrivateBackend);
gateway.enableTool('check_inventory');