YoutubeTranscriptReader 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 reader raises a blocked-request error, or says 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 a reader that returns Document objects for your node parsers and indexes, and tools a LlamaIndex agent can call. 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 reader and the tools
Each call 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. Besides llama-index-core, the only package you need is httpx.
importly_tools.py
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. Load transcripts as Documents
ImportlyTranscriptReader().load_data(ytlinks=[...]) takes the same argument as YoutubeTranscriptReader, so swapping it in is a one-line change. Parse and index the documents as before:
rag.py
VectorStoreIndex uses the embedding model in your Settings, as it did before. The reader raises when a transcript can’t be made, for example because the video is private, so a failed link never turns into an empty document in your index. If you need timestamps for citations, read result.data.segments from the same job: each segment has its start and end time.
4. Give the tools to an agent
FunctionAgent takes the three tools as they are. The tool names and descriptions come from the functions’ names and docstrings.
agent.py
transcribe_media, reads the transcript, and answers in its next step. Swap in any LLM LlamaIndex supports that can call tools.
These examples run on llama-index-core 0.14 with llama-index-llms-openai 0.9.
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 Python guide shows that flow in FastAPI. Using LangChain instead? See the LangChain guide.