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 sk_live_ or sk_test_)
baseUrlstringNohttps://lightfast.aiAPI base URL
timeoutnumberNo30000Request timeout in milliseconds

Methods

Search through workspace memory for relevant documents and observations.

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

SearchInput

PropertyTypeRequiredDefaultDescription
querystringYes-Natural language search query
limitnumberNo10Number of results to return
offsetnumberNo0Pagination offset
mode"fast" | "balanced" | "quality"No"balanced"Search mode
includeContextbooleanNotrueInclude surrounding context
includeHighlightsbooleanNotrueInclude highlighted snippets
filtersSearchFiltersNo-Filter results

SearchFilters

PropertyTypeDescription
sourcesstring[]Filter by source (e.g., ["github"])
dateRangestringFilter by date (e.g., "30d", "7d")

V1SearchResponse

typescript
interface V1SearchResponse {
  results: V1SearchResult[];
  meta: {
    total: number;
    latency: { total: number };
  };
}

interface V1SearchResult {
  id: string;
  type: string;
  title: string;
  snippet: string;
  score: number;
  source: string;
  url: string;
  metadata: Record<string, unknown>;
}

contents()

Fetch full content for documents by their IDs.

typescript
const response = await client.contents(input: ContentsInput): Promise<V1ContentsResponse>

ContentsInput

PropertyTypeRequiredDescription
idsstring[]YesArray of document IDs to fetch

V1ContentsResponse

typescript
interface V1ContentsResponse {
  items: V1ContentItem[];
  missing: string[];
}

interface V1ContentItem {
  id: string;
  type: string;
  title: string;
  content: string;
  metadata: Record<string, unknown>;
}

findSimilar()

Find content semantically similar to a given document or URL.

typescript
const response = await client.findSimilar(input: FindSimilarInput): Promise<V1FindSimilarResponse>

FindSimilarInput

PropertyTypeRequiredDefaultDescription
idstringOne of id or url-Document ID to find similar content for
urlstringOne of id or url-URL to find similar content for
limitnumberNo10Number of results
thresholdnumberNo0.5Minimum similarity score (0-1)
sameSourceOnlybooleanNofalseOnly return results from same source
excludeIdsstring[]No-Document IDs to exclude

V1FindSimilarResponse

typescript
interface V1FindSimilarResponse {
  results: V1SimilarResult[];
  source: {
    id: string;
    title: string;
    type: string;
  };
}

interface V1SimilarResult {
  id: string;
  type: string;
  title: string;
  snippet: string;
  score: number;
  source: string;
  url: string;
}

Error Classes

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

typescript
import {
  AuthenticationError,
  ValidationError,
  NotFoundError,
  RateLimitError,
  NetworkError,
} 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
NetworkError-Connection or timeout error

Type Exports

All request and response types are exported:

typescript
import type {
  LightfastConfig,
  SearchInput,
  SearchFilters,
  V1SearchResponse,
  V1SearchResult,
  ContentsInput,
  V1ContentsResponse,
  V1ContentItem,
  FindSimilarInput,
  V1FindSimilarResponse,
  V1SimilarResult,
} from "lightfast";