> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Video tools that work locally and fail once deployed

> Your agent's transcript or video tool works on your laptop and fails on Vercel, Lambda or Cloud Run: what each error means, and how to fix it by calling the API from the tool.

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

| What you see in production | What it means for you |
| - | - |
| `RequestBlocked` or `IpBlocked` from a transcript library | YouTube refuses requests from cloud IPs. Your laptop's home connection isn't blocked; Vercel, Lambda, Cloud Run, Fly and most other hosts are. |
| "Sign in to confirm you're not a bot" | The same block, shown as a bot check. Cookies from your own account can get past it for a while, and they tend to get that account flagged. |
| An empty list, or "Transcript is disabled on this video", for a video that has captions | The block again, reported as missing captions. LangChain's `YoutubeLoader` fails this way. |
| An empty result for a video that really has no captions | Many videos have none. A captions-only tool can't help, on any host. |
| `HTTP Error 403: Forbidden`, or a download that stops partway | The site let the page load and refused the media. |
| The agent calls the tool again and again | The tool threw an error the model can't read, so it tries again. See [Return failures the agent can act on](#return-failures-the-agent-can-act-on). |

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.

```ts theme={null}
const res = await fetch('https://api.importly.io/transcribe', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.IMPORTLY_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ url, mode: 'auto', wait: true, maxCostDollars: 0.5 }),
})
const { data } = await res.json()
// data.status is "completed" (data.result.text), "failed" (data.code), or still running (poll data.jobId)
```

`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`](/docs/endpoints/transcribe-status) or to collect by [webhook](/docs/webhooks.md).

Full tool definitions for your framework:

> [card] [Vercel AI SDK](/docs/integrations/ai-sdk.md)
>
> `tool()` definitions and a Next.js route handler

> [card] [Mastra](/docs/integrations/mastra.md)
>
> `createTool` definitions for a Mastra agent

> [card] [OpenAI Agents SDK](/docs/integrations/openai-agents.md)
>
> `tool()` definitions and a `run()` call

> [card] [LangChain and LangGraph](/docs/integrations/langchain.md)
>
> Tools and a loader that replaces `YoutubeLoader`

> [card] [LlamaIndex](/docs/integrations/llamaindex.md)
>
> A reader that replaces `YoutubeTranscriptReader`, plus agent tools

> [card] [Python](/docs/integrations/python.md)
>
> 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:

```ts theme={null}
if (data.status === 'failed') {
  return {
    ok: false,
    code: data.code,       // e.g. VIDEO_PRIVATE, GEO_BLOCKED, SOURCE_THROTTLED
    message: data.message, // safe to show the user
    retry: data.code === 'SOURCE_THROTTLED' || data.code === 'SOURCE_UNREACHABLE',
  }
}
```

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](/docs/errors/media-unavailable)) give the same answer every time. [`SOURCE_THROTTLED`](/docs/errors/source-throttled) and [`SOURCE_UNREACHABLE`](/docs/errors/source-unreachable) usually succeed a little later. All codes: [Error handling](/docs/error-handling.md).

## 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](/docs/billing.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.