What you see, and what it means
None of this shows up in local testing, which is why it tends to surface right after launch.
The fix: call the API from the tool
Keep the tool, and swap its body for a call to Importly. The tool sends the link from your server, and gets back the transcript (from captions, or speech-to-text when there are none), a download link for the file, or the video’s details. The same call works on YouTube, TikTok, X, Instagram, podcasts and 1,000+ other sites, from any host.mode: 'auto' uses captions when the video has them and speech-to-text when it doesn’t. wait: true holds the request for up to 30 seconds, so a captioned video usually comes back in this one call. Longer jobs return a jobId to poll at GET /transcribe/status or to collect by webhook.
Full tool definitions for your framework:
Vercel AI SDK
tool() definitions and a Next.js route handlerMastra
createTool definitions for a Mastra agentOpenAI Agents SDK
tool() definitions and a run() callLangChain and LangGraph
Tools and a loader that replaces
YoutubeLoaderLlamaIndex
A reader that replaces
YoutubeTranscriptReader, plus agent toolsPython
Plain HTTP calls from FastAPI, Flask or a worker
Return failures the agent can act on
Some links fail for reasons no retry will fix: the video is private, removed, age-restricted or blocked in a region. If your tool throws, many frameworks hand the model a stack trace or a generic error, and the model calls the tool again. Return the failure as a normal result instead, with Importly’scode and message. The message is written for people, so the model can pass it on to the user:
VIDEO_PRIVATE, AGE_RESTRICTED, GEO_BLOCKED and others) give the same answer every time. SOURCE_THROTTLED and SOURCE_UNREACHABLE usually succeed a little later. All codes: Error handling.