Integration Examples
Learn how to integrate CleanScript API with popular tools and frameworks.
Integration Examples
These examples show how to integrate CleanScript API with popular LLM tools and frameworks. You'll need to install the appropriate dependencies for each example.
LangChain Integration
This example shows how to create a custom LangChain tool that fetches transcripts from CleanScript API and uses them with an agent.
LangChain Integration
1import { ChainTool } from "langchain/tools";
2import { ChatOpenAI } from "langchain/chat_models/openai";
3import { initializeAgentExecutorWithOptions } from "langchain/agents";
4
5// Create a tool to fetch transcripts
6const cleanscriptTool = new ChainTool({
7 name: "youtube_transcript",
8 description: "Get a clean transcript of a YouTube video.",
9 func: async (videoId) => {
10 const apiKey = process.env.CLEANSCRIPT_API_KEY;
11
12 try {
13 const response = await fetch(
14 `https://api.cleanscript.ai/v1/transcript?videoId=${videoId}`,
15 {
16 method: 'GET',
17 headers: {
18 'Authorization': `Bearer ${apiKey}`,
19 'Accept': 'application/json',
20 },
21 }
22 );
23
24 if (!response.ok) {
25 const errorData = await response.json();
26 throw new Error(`CleanScript API error: ${errorData.detail}`);
27 }
28
29 const data = await response.json();
30 if (data.length === 0 || !data[0].chapters || data[0].chapters.length === 0) {
31 return "No transcript found for this video.";
32 }
33
34 // Return just the transcript text from all chapters
35 const transcript = data[0].chapters
36 .map(chapter => chapter.subtitles.map(sub => sub.text).join("\n\n"))
37 .join("\n\n");
38 return transcript;
39 } catch (error) {
40 console.error('Error fetching transcript:', error);
41 return `Failed to get transcript: ${error.message}`;
42 }
43 }
44});
45
46// Create LLM and agent
47const llm = new ChatOpenAI({ temperature: 0 });
48const executor = await initializeAgentExecutorWithOptions(
49 [cleanscriptTool],
50 llm,
51 {
52 agentType: "chat-conversational-react-description",
53 verbose: true,
54 }
55);
56
57// Example usage
58const response = await executor.call({
59 input: "dQw4w9WgXcQ"
60});
61
62console.log(response.output);
Integration Tips
- Token Management: Be mindful of token limits when sending transcripts to LLMs. The API provides token counts that can help you manage context windows.
- Chunking: For longer videos, work with individual chapters or use the subtitles array to create custom chunks.
- Error Handling: Always implement proper error handling, especially for cases where transcripts might not be available.
- Semantic Search: The clean, well-formatted transcripts from CleanScript are ideal for semantic search applications with vector databases.
- Timestamps: Use the timestamp information to link back to specific parts of the video in your applications.
Low-Code Integrations
CleanScript API can also be used with no-code and low-code platforms.
Make.com (Integromat)
Create Make scenarios that fetch transcripts when new videos are uploaded to a channel, then process them with AI or store them in your database.
Zapier
Use Zapier's Webhook action to call CleanScript API and integrate with thousands of other apps.
Need a custom integration?
If you need help with custom integrations or have questions about using CleanScript with specific tools, email us at [email protected].