Skip to main content
You give your agent a tool that reads a YouTube link. It works on your laptop. You deploy, and the same tool starts failing on links that worked an hour ago. This page starts from what you see in your logs and ends with a tool that works from your server.

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 handler

Mastra

createTool definitions for a Mastra agent

OpenAI Agents SDK

tool() definitions and a run() call

LangChain and LangGraph

Tools and a loader that replaces YoutubeLoader

LlamaIndex

A reader that replaces YoutubeTranscriptReader, plus agent tools

Python

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’s code and message. The message is written for people, so the model can pass it on to the user:
Then say in the tool’s description what to do with it, for example: “If ok is false, tell the user the message. Only call this tool again for the same link if retry is true.” Codes for media that can’t be fetched (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.

Check it before you ship

Run the tool once from the deployed app, not your laptop, with a link that has no captions. If you get a transcript back, both the cloud block and the missing-captions case are covered. A caption transcript costs $0.003 and speech-to-text $0.01 a minute. Importly is free to try, no card required. See Pricing & credits.