DriftOSDriftOS
Quick Start

Custom Integration

Build your own integration with DriftOS SDK or REST API

Build your own integration with DriftOS routing and context management using the JavaScript SDK or REST API.

JavaScript SDK

Installation

npm install @driftos/client

Quick Start

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

// Create client (works with both Core and Embed)
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?' }
  ]
});

Choosing a Routing Engine

The SDK works with both routing engines. Just point it to the appropriate endpoint:

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

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

The API is identical—only the routing strategy differs.

Learn more about choosing a routing engine →


REST API

Authentication

DriftOS supports multiple authentication methods:

Option 1: x-api-key header (Recommended)

x-api-key: dft_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Option 2: Bearer token

Authorization: Bearer dft_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Option 3: JWT token

Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...

Route a Message

POST https://api.driftos.dev/api/v1/drift/route

Request Body:

{
  "conversationId": "conv-123",
  "message": "I want to plan a trip to Paris"
}

Response:

{
  "action": "BRANCH",
  "branchId": "branch-xyz789",
  "branchTopic": "Paris trip planning",
  "confidence": 0.923
}

Get Context

GET https://api.driftos.dev/api/v1/drift/context/:branchId

Response:

{
  "messages": [
    { "role": "user", "content": "I want to plan a trip to Paris" },
    { "role": "assistant", "content": "I'd be happy to help you plan your Paris trip!" }
  ],
  "systemPrompt": "You are a helpful travel assistant."
}

Next Steps


Need Help?

On this page