YoutubeLoader tends to work on your laptop and fail once the app is deployed. On Lambda, Cloud Run, Vercel or any other cloud host, YouTube blocks the server’s IP, so the loader returns an empty list or reports that the video has no transcript, even when it does. Videos that really have no captions fail the same way, and other sites aren’t covered at all.
This page swaps it for Importly. You get tools a LangChain or LangGraph agent can call, and a small loader that returns Document objects for your splitters and vector stores. Both call the REST API from your server, work for YouTube, TikTok, X, podcasts and 1,000+ other sites, and fall back to speech-to-text when a video has no captions.
1. Store your key
Create your key on the API key page (it is shown once) and add it to your server environment, next to your model provider’s key:.env
2. Define the tools and the loader
Each tool starts an Importly job and polls its status until it finishes. A transcript of a video with captions usually comes back within the first request, becausewait holds it open for up to 30 seconds. The only packages you need are LangChain itself and zod (TypeScript) or httpx (Python).
maxCostDollars caps what one call can spend. If a job would cost more, it fails with MAX_COST_EXCEEDED and the price instead of running. Raise the caps to suit your app. mode: 'auto' uses the video’s captions when it has them and speech-to-text when it doesn’t.
3. Give the tools to an agent
createAgent (TypeScript) and create_agent (Python) build a LangGraph agent, so the same tools work in a custom LangGraph graph through a ToolNode too.
transcribe_media, reads the transcript, and answers in its next step. Swap in any chat model LangChain supports.
4. Load transcripts as Documents
Where you usedYoutubeLoader to feed a RAG pipeline, load the transcript as a Document and split it as before:
result.data.segments from the same job: each segment has its start and end time.
These examples typecheck against langchain 1.6 and @langchain/core 1.5 (TypeScript), and run on langchain 1.5 with langchain-core 1.8 (Python).
What each tool returns
The tools hand the job back to the agent as JSON:
A job that can’t finish comes back with
status: 'failed' and a code the agent can explain to the user (error codes). A long download may still be running when the tool stops polling. For files, a webhook is the better fit in production: start the import from your backend, store the jobId, and save mediaUrl when the webhook arrives. The Next.js guide shows that flow, and the Python guide shows it in FastAPI.