DriftOSDriftOS
JavaScript SDK

JavaScript SDK

Official TypeScript/JavaScript SDK for DriftOS

Official JavaScript SDK for DriftOS - conversation routing and context management for AI applications.

Overview

The @driftos/client SDK provides a simple, type-safe interface for working with both DriftOS Core and DriftOS Embed servers.

Features

  • Type-safe - Full TypeScript support
  • Simple API - Intuitive methods for routing and context management
  • Universal - Works with both DriftOS Core and DriftOS Embed
  • Lightweight - Minimal dependencies

Installation

npm install @driftos/client

Quick Start

import { createDriftClient } from '@driftos/client';

// Embedding-based routing (fast, local)
const drift = createDriftClient(
  'https://api.driftos.dev/api/v1/embed',
  'YOUR_API_KEY'
);

// Route a message
const result = await drift.route('conv-123', 'I want to plan a trip to Paris');
console.log(result.branchTopic); // "Paris trip planning"

// Get context for LLM
const { system, messages } = await drift.buildPrompt(result.branchId);

// Use with OpenAI
const response = await openai.chat.completions.create({
  model: 'gpt-4',
  messages: [
    { role: 'system', content: system },
    ...messages,
    { role: 'user', content: 'What hotels do you recommend?' }
  ]
});

Usage with DriftOS Core or Embed

The SDK works with both routing engines and supports self-hosted instances. Just point it to the appropriate endpoint:

// Hosted API - Embedding-based routing (fast, local, free)
const embedClient = createDriftClient(
  'https://api.driftos.dev/api/v1/embed',
  'YOUR_API_KEY'
);

// Hosted API - LLM-based routing (more accurate, requires API credits)
const coreClient = createDriftClient(
  'https://api.driftos.dev/api/v1/llm',
  'YOUR_API_KEY'
);

// Self-hosted instance
const selfHostedClient = createDriftClient(
  'https://your-driftos-server.com',
  'YOUR_API_KEY'
);

The API is identical across all options - only the endpoint and routing strategy differ.

Learn about choosing a routing engine →

Next Steps

On this page