Skip to main content
The Episodes API is an interface for recording and retrieving episodes (events) chronologically. Track Q&A history, knowledge change history, user actions, and more.

Overview

const client = new NdxClient({
  apiKey: process.env.NEURADEX_API_KEY,
  projectId: 'your-project-id',
});

// Access Episodes API
const episodes = await client.episodes.list({ timeRange: 'today' });
await client.episodes.create({ ... });

Method List

MethodDescription
list(options?)Get episode list
get(id)Get specific episode
create(input)Record new episode
getChildren(id)Get child episodes
getBySession(sessionId)Get episodes in a session
getRecent(limit?)Get recent episodes
getToday()Get today’s episodes
getThisWeek()Get this week’s episodes
search(query, options?)Vector search episodes

list()

Get episode list with specified conditions.

Parameters

options.timeRange
string
Time range preset: 'today' | 'this_week' | 'this_month'
options.from
string
Start datetime (ISO 8601 format)
options.to
string
End datetime (ISO 8601 format)
options.episodeType
string
Filter by episode type: 'question' | 'answer' | 'knowledge_created' etc.
options.actorType
string
Filter by actor type: 'user' | 'agent' | 'system'
options.actorId
string
Filter by actor ID
options.sessionId
string
Filter by session ID
options.channel
string
Filter by channel: 'widget' | 'api' | 'mcp'
options.limit
number
default:"50"
Maximum number of items to retrieve
options.page
number
default:"1"
Page number

Return Value

interface EpisodeListResponse {
  data: Episode[];
  total: number;
  page: number;
  limit: number;
}

interface Episode {
  id: string;
  episodeType: string;
  content: string;
  actorType: string;
  actorId: string | null;
  actorName: string | null;
  scopeType: string;
  scopeId: string;
  channel: string | null;
  sessionId: string | null;
  parentEpisodeId: string | null;
  relatedKnowledgeIds: string[];
  changeReason: string | null;
  previousValue: object | null;
  occurredAt: string;
  createdAt: string;
}

Usage

// Today's episodes
const result = await client.episodes.list({ timeRange: 'today' });

// Episodes for a specific user
const result = await client.episodes.list({
  actorType: 'user',
  actorId: 'user-123',
  limit: 100,
});

// Get by date range
const result = await client.episodes.list({
  from: '2025-01-01T00:00:00Z',
  to: '2025-01-07T23:59:59Z',
});

// Question episodes only
const result = await client.episodes.list({
  episodeType: 'question',
});

get()

Get a specific episode.

Parameters

id
string
required
Episode ID

Usage

const episode = await client.episodes.get('episode-123');

console.log(episode.content);
console.log(episode.actorName);
console.log(episode.occurredAt);

create()

Record a new episode.

Parameters

actorType
string
required
Actor type: 'user' | 'agent' | 'system'
episodeType
string
required
Episode type: 'question' | 'answer' | 'feedback' etc.
content
string
required
Episode content
scopeType
string
required
Scope type: 'project' | 'organization'
scopeId
string
required
Scope ID (project ID or organization ID)
actorId
string
Actor ID
actorName
string
Actor name (for display)
channel
string
Channel: 'widget' | 'api' | 'mcp'
sessionId
string
Session ID (to group conversations)
parentEpisodeId
string
Parent episode ID (to link answers to questions, etc.)
IDs of related knowledge

Usage

// Record user question
const question = await client.episodes.create({
  actorType: 'user',
  actorId: 'user-123',
  actorName: 'John Doe',
  episodeType: 'question',
  content: 'How do I reset my password?',
  scopeType: 'project',
  scopeId: 'project-abc',
  channel: 'widget',
  sessionId: 'session-xyz',
});

// Record agent answer
const answer = await client.episodes.create({
  actorType: 'agent',
  actorName: 'Support Bot',
  episodeType: 'answer',
  content: 'You can reset your password by clicking the "Forgot Password" link on the login screen.',
  scopeType: 'project',
  scopeId: 'project-abc',
  channel: 'widget',
  sessionId: 'session-xyz',
  parentEpisodeId: question.id,  // Link to question
  relatedKnowledgeIds: ['knowledge-1', 'knowledge-2'],
});

getChildren()

Get child episodes (replies, etc.) of a specified episode.

Parameters

id
string
required
Parent episode ID

Usage

// Get answers to a question
const children = await client.episodes.getChildren('question-episode-id');

for (const child of children) {
  console.log(`Answer: ${child.content}`);
}

getBySession()

Get all episodes in a session. Useful for retrieving conversation history.

Parameters

sessionId
string
required
Session ID

Usage

// Get conversation history
const result = await client.episodes.getBySession('session-123');

for (const episode of result.data) {
  const prefix = episode.episodeType === 'question' ? 'Q' : 'A';
  console.log(`${prefix}: ${episode.content}`);
}

getRecent()

Get recent episodes.

Parameters

limit
number
default:"10"
Number of items to retrieve

Usage

// Recent 10
const result = await client.episodes.getRecent();

// Recent 50
const result = await client.episodes.getRecent(50);

getToday() / getThisWeek()

Shortcut methods to get today’s or this week’s episodes.

Usage

// Today's episodes
const today = await client.episodes.getToday();

// This week's episodes
const thisWeek = await client.episodes.getThisWeek();

Search episodes using vector search. Find related episodes even with vague queries like “password reset” or “last week’s error.”

Parameters

query
string
required
Search query
options.limit
number
Maximum number of results

Return Value

interface EpisodeSearchResponse {
  results: EpisodeSearchResult[];
  query: string;
}

interface EpisodeSearchResult {
  id: string;
  episodeType: string;
  content: string;
  actorType: string;
  actorName: string | null;
  occurredAt: string;
  channel: string | null;
  score: number;
}

Usage

// Search episodes
const result = await client.episodes.search('password reset');

for (const episode of result.results) {
  console.log(`${episode.actorName}: ${episode.content} (score: ${episode.score})`);
}

// Specify limit
const result = await client.episodes.search('deploy error', { limit: 5 });

Episode Types

TypeDescription
questionUser question
answerAgent answer
feedbackUser feedback
knowledge_createdKnowledge creation
knowledge_updatedKnowledge update
knowledge_deletedKnowledge deletion
searchSearch execution

Use Cases

Saving Conversation History

async function recordConversation(
  sessionId: string,
  question: string,
  answer: string,
  userId: string,
) {
  // Record question
  const questionEpisode = await client.episodes.create({
    actorType: 'user',
    actorId: userId,
    episodeType: 'question',
    content: question,
    scopeType: 'project',
    scopeId: projectId,
    channel: 'api',
    sessionId,
  });

  // Record answer
  await client.episodes.create({
    actorType: 'agent',
    actorName: 'Assistant',
    episodeType: 'answer',
    content: answer,
    scopeType: 'project',
    scopeId: projectId,
    channel: 'api',
    sessionId,
    parentEpisodeId: questionEpisode.id,
  });
}

Activity Dashboard

async function getActivityStats() {
  const today = await client.episodes.getToday();

  const stats = {
    questions: today.data.filter(e => e.episodeType === 'question').length,
    answers: today.data.filter(e => e.episodeType === 'answer').length,
    uniqueUsers: new Set(
      today.data
        .filter(e => e.actorType === 'user')
        .map(e => e.actorId)
    ).size,
  };

  console.log(`Today's questions: ${stats.questions}`);
  console.log(`Today's answers: ${stats.answers}`);
  console.log(`Unique users: ${stats.uniqueUsers}`);

  return stats;
}

Next Steps

Knowledge API

Knowledge management

Memory API

Context assembly