Alpha API

This API is currently in alpha. Breaking changes may occur between releases. We recommend pinning to a specific version and monitoring the changelog for updates.

TypeScript SDK Reference

The lightfast npm package provides a type-safe client for the Lightfast API.

Installation

bash
npm install lightfast

Client Configuration

typescript
import { Lightfast } from "lightfast";

const client = new Lightfast(config: LightfastConfig);

LightfastConfig

PropertyTypeRequiredDefaultDescription
apiKeystringYes-API key (starts with lf_)
baseUrlstringNohttps://lightfast.aiAPI base URL
timeoutnumberNo30000Request timeout in milliseconds

Methods

Search through your organization's knowledge — decisions, observations, and documents.

typescript
const response = await client.search(input: SearchInput): Promise<SearchResponse>

SearchInput & Response

SearchInput accepts a natural-language query, optional pagination, optional search mode, and optional filters. SearchResponse returns ranked results, metadata, and a request id for support.

SearchFilters

PropertyTypeDescription
observationTypesstring[]Observation types to include (e.g., ["decision", "incident"])
entityTypesstring[]Entity types to filter by (e.g., ["service", "repository"])
dateRange{ start?: string; end?: string }Date range filter with ISO datetime strings

Example

typescript
const results = await client.search({
  query: "authentication implementation",
  limit: 10,
  mode: "balanced",
  filters: {
    entityTypes: ["service", "repository"],
    dateRange: {
      start: "2024-01-01T00:00:00Z",
      end: "2024-12-31T23:59:59Z",
    },
  },
});

console.log(results.data); // Array of search results
console.log(results.meta.total); // Total matching documents

Error Classes

The SDK exports typed error classes for handling specific error conditions.

typescript
import {
  AuthenticationError,
  ValidationError,
  NotFoundError,
  RateLimitError,
  NetworkError,
  ServerError,
} from "lightfast";
Error ClassHTTP StatusDescription
AuthenticationError401Invalid or expired API key
ValidationError400Invalid request parameters. Access error.details for field-specific errors
NotFoundError404Resource not found
RateLimitError429Too many requests. Access error.retryAfter for retry delay in seconds
ServerError500, 502, 503, 504Internal server error or service unavailable
NetworkError-Connection or timeout error

Type Exports

All request and response types are exported:

typescript
import type {
  LightfastConfig,
  SearchInput,
  SearchFilters,
  SearchRequest,
  SearchResponse,
  SearchResult,
  RerankMode,
  SearchContext,
  SearchLatency,
  ProxySearchResponse,
  ProxyConnection,
  ProxyAction,
  ProxyResource,
  ProxyCall,
  ProxyCallResponse,
} from "lightfast";