Bold VideoDocs

AI Methods

Chat, semantic search, and recommendations, grounded in your videos

The ai namespace is how your app talks to Bold's AI. Chat, search, and recommendations stream by default (see Streaming) and accept stream: false for plain JSON. Conversation history methods return JSON.

ai.chat(options)

Library-wide Q&A, or scoped to one video by passing videoId.

// Streaming (default)
const stream = await bold.ai.chat({ prompt: 'How do I price my SaaS?' });
for await (const event of stream) {
  if (event.type === 'text_delta') process.stdout.write(event.delta);
  if (event.type === 'sources') console.log('Sources:', event.sources);
}

// Non-streaming
const response = await bold.ai.chat({
  prompt: 'What are the best closing techniques?',
  stream: false
});
console.log(response.content);

Scoped to one video (uses only that video's transcript as context):

const stream = await bold.ai.chat({
  videoId: 'video-id',
  prompt: 'What is discussed at the 5 minute mark?',
  currentTime: 300   // optional playback position
});

Continue a conversation:

const stream = await bold.ai.chat({
  prompt: 'Tell me more about that',
  conversationId: 'conv-id'   // from message_start / message_complete events
});
OptionTypeDefaultDescription
promptstring-The question (required)
streambooleantrueSSE stream vs JSON
videoIdstring-Scope to a single video
currentTimenumber-Playback position (with videoId)
conversationIdstring-Continue an existing conversation
collectionIdstring-Restrict context to a collection
tagsstring[]-Restrict context by tags
imagesImageInput[]-Attach images (e.g. homework review): File, Blob, or base64
signalAbortSignal-Cancel the request and response body

Plan availability

Library-wide chat (no videoId) is the AI Coach, available on Growth and Enterprise plans. Video-scoped chat works on every plan.

Stopping an answer

From @boldvideo/bold-js 3.3.1, pass signal to chat, ask, coach, or search to stop a request, in streaming or JSON mode.

import { createClient } from '@boldvideo/bold-js';

// Server only. Keep your API key out of browser code.
const bold = createClient(process.env.BOLD_API_KEY!);
const controller = new AbortController();
// Call controller.abort() from your cancellation handler.

try {
  const stream = await bold.ai.chat({
    prompt: 'Explain pricing',
    signal: controller.signal
  });
  for await (const event of stream) {
    if (event.type === 'text_delta') console.log(event.delta);
  }
} catch (error) {
  if (!(error instanceof DOMException && error.name === 'AbortError')) throw error;
}

controller.abort() rejects pending requests or reads with the platform's AbortError, not AIAPIError. Catch around both the call and the loop, as above.

Leaving the for await loop with break (or returning after an event) also cancels the response body, without throwing. Use a signal to cancel before iteration starts or while a read is pending. On a server, you can pass the incoming request's signal to stop the upstream request when it aborts.

ai.search(options)

Semantic search with a short AI-written summary of the results.

const stream = await bold.ai.search({ prompt: 'pricing strategies', limit: 10 });
for await (const event of stream) {
  if (event.type === 'sources') console.log(`Found ${event.sources.length} clips`);
  if (event.type === 'text_delta') process.stdout.write(event.delta);
}
OptionTypeDefaultDescription
promptstring-Search query (required)
streambooleantrueSSE stream vs JSON
limitnumber-Max results
collectionId / tags / videoId--Scope the search
contextAIContextMessage[]-Previous turns, for follow-up queries
signalAbortSignal-Cancel the request and response body

ai.recommendations(options)

Topic-based recommendations, ideal for learning paths and "what should I watch next."

const stream = await bold.ai.recommendations({
  topics: ['contract law', 'ethics', 'client management']
});

for await (const event of stream) {
  if (event.type === 'recommendations') {
    for (const rec of event.recommendations) {
      console.log(rec.topic, rec.videos.map(v => v.title));
    }
  }
  if (event.type === 'text_delta') process.stdout.write(event.delta); // AI guidance
}
OptionTypeDefaultDescription
topicsstring[]-Topics to cover (required)
limitnumber5Max videos per topic (max 20)
includeGuidancebooleantrueNarrative learning-path text
collectionId / tags--Scope the pool
contextAIContextMessage[]-Previous turns
streambooleantrueSSE stream vs JSON

ai.getConversation(id)

const conversation = await bold.ai.getConversation('conv-id');
for (const message of conversation.messages) {
  console.log(`${message.role}: ${message.content}`);
}

ai.listConversations(options)

Build a viewer's history list with their library and video conversations, newest first, within your credential's visibility. Available from @boldvideo/bold-js 3.3.1.

Call this on your server. Derive viewer from your authenticated session, not a request parameter, and keep the API key out of browser code. This Next.js route uses your app's auth() helper; the session's user ID must be the viewer's external ID in Bold (or their Bold viewer UUID).

app/api/conversations/route.ts
import { createClient } from '@boldvideo/bold-js';
import { auth } from '@/auth'; // Your app's server-side session helper.

const bold = createClient(process.env.BOLD_API_KEY!);

export async function GET(request: Request) {
  const session = await auth();
  if (!session?.user?.id) {
    return new Response('Unauthorized', { status: 401 });
  }

  const viewer = session.user.id;
  const requestedOffset = Number(
    new URL(request.url).searchParams.get('offset') ?? 0
  );
  const offset = Number.isSafeInteger(requestedOffset) && requestedOffset >= 0
    ? requestedOffset
    : 0;
  const page = await bold.ai.listConversations({ viewer, limit: 20, offset });
  return Response.json(page);
}
OptionTypeDefaultDescription
viewerstringrequiredViewer UUID or external ID
limitnumber20Page size; the server clamps it to 1–100
offsetnumber0Number of conversations to skip; minimum 0

Returns ConversationList: { conversations: ConversationSummary[], pagination: { limit, offset, hasMore } }. Each summary has these fields, without the message history:

FieldTypeDescription
conversationIdstringID for ai.getConversation or a follow-up chat
scope'library' | 'video' | nullConversation scope
title, previewstring | nullText for the history list
statusstringConversation status
messageCountnumberNumber of messages
videoConversationVideo | nullOnly populated for video-scoped conversations
createdAt, updatedAtstringCreation and update timestamps
channel'portal' | 'embed' | 'api' | 'mcp' | 'unknown'Where the conversation came from
clientstring | nullClient metadata

ConversationVideo has id and title strings, plus nullable thumbnailUrl and url strings. Response keys are camelCase; null values and the server's pagination values are preserved.

While pagination.hasMore is true, request the next page with ?offset= set to pagination.offset + pagination.limit.

HTTP failures throw AIAPIError, with status and code:

StatusCodeMeaning
400viewer_requiredSupply a viewer
404viewer_not_foundThe viewer was not found
403feature_disabledAI is disabled
403verified_ai_route_unsupportedVerified AI access keys cannot use this route

Multi-turn without conversations

Search and recommendations accept a context array instead of a conversation ID:

const first = await bold.ai.search({ prompt: 'How do indie designers find clients?', stream: false });
const followUp = await bold.ai.search({
  prompt: 'What about cold outreach specifically?',
  context: first.context,
  stream: false
});

Deprecated aliases

ai.ask(), ai.coach() → use ai.chat(). ai.recommend() → use ai.recommendations(). The old names still work but will be removed in v2.

On this page