A lot of AI apps I see have the same feature request sooner or later: the user pastes a YouTube or podcast link and wants a summary, notes or answers about it. With the Vercel AI SDK the model side of that is easy. The hard part is getting the media in.

Fetching it yourself usually works on your laptop and then breaks once the app is deployed. Sites block the datacenter IPs that Vercel, AWS and the like run on, and plenty of videos have no captions to fall back on. I built Importly for this - you send it the link and get back the transcript, the file or the video's details - so here's how I wire it into an AI SDK app as tools.

The only packages you need are ai and zod.

1. Keep the key on the server

# .env.local IMPORTLY_API_KEY=your_api_key 

The tools run in your route handler, so the key never reaches the browser.

2. Define the tools

Each tool starts a job and polls until it finishes. For a video with captions the transcript usually comes back in the first request, because wait holds it open for up to 30 seconds.

// lib/importly-tools.ts import { tool } from 'ai' import { z } from 'zod' const API = 'https://api.importly.io' type Job = { jobId: string, status: string, result?: Record<string, unknown> } const call = async (method: 'GET' | 'POST', path: string, body?: object): Promise<Job> => { const res = await fetch(API + path, { method, headers: { Authorization: `Bearer ${process.env.IMPORTLY_API_KEY}`, 'Content-Type': 'application/json', }, body: body ? JSON.stringify(body) : undefined, }) const json = await res.json() if (!json.success) throw new Error(`${json.code}: ${json.error}`) return json.data } // Start a job, then poll until it finishes (or give back the jobId after about 2 minutes) const runJob = async (path: string, body: object): Promise<Job> => { let job = await call('POST', path, body) for (let i = 0; i < 40 && job.status !== 'completed' && job.status !== 'failed'; i++) { await new Promise((resolve) => setTimeout(resolve, 3000)) job = await call('GET', `${path}/status?id=${job.jobId}`) } return job } export const transcribeMedia = tool({ description: 'Transcribe a video or audio link (YouTube, TikTok, X, Instagram, podcasts and 1,000+ other sites). ' + 'Returns the text and timestamped segments.', inputSchema: z.object({ url: z.string().describe('Public page URL of the video or audio'), language: z.string().optional().describe('Language hint, e.g. "en"'), }), execute: async ({ url, language }) => runJob('/transcribe', { url, language, mode: 'auto', wait: 30, maxCostDollars: 0.5 }), }) export const importMedia = tool({ description: 'Download the video or audio behind a link and return a download URL for the file, with its title.', inputSchema: z.object({ url: z.string().describe('Public page URL of the video or audio'), audioOnly: z.boolean().optional().describe('Download only the audio'), }), execute: async ({ url, audioOnly }) => runJob('/import', { url, includeVideo: !audioOnly, videoQuality: '720p', maxCostDollars: 1 }), }) export const getMediaDetails = tool({ description: 'Get the title, duration and thumbnail of a video or audio link.', inputSchema: z.object({ url: z.string().describe('Public page URL of the video or audio'), }), execute: async ({ url }) => runJob('/metadata/basic', { url }), }) 

Two things I'd keep even if you change everything else:

  • mode: 'auto' uses the video's captions when it has them and switches to speech-to-text when it doesn't, so the model isn't stuck on videos without subtitles.
  • maxCostDollars caps what a single tool call can spend. A model will happily ask for a three-hour video. If the job would cost more than the cap it fails with MAX_COST_EXCEEDED and the price, instead of running.

3. Give the tools to the model

A route handler that summarizes whatever link it gets:

// app/api/summarize/route.ts import { generateText, stepCountIs } from 'ai' import { transcribeMedia, importMedia, getMediaDetails } from '@/lib/importly-tools' export const maxDuration = 120 export const POST = async (req: Request) => { const { url } = await req.json() const { text } = await generateText({ model: 'openai/gpt-5-mini', tools: { transcribeMedia, importMedia, getMediaDetails }, stopWhen: stepCountIs(3), prompt: `Transcribe ${url} and summarize it in five bullet points.`, }) return Response.json({ summary: text }) } 

The model calls transcribeMedia, reads result.text and answers in the next step. stopWhen is what lets it take that second step; without it you get the tool call back and no summary. The same tools object works with streamText if you want a chat UI instead.

What I'd change for production

Polling inside a tool is fine for transcripts, which are quick. For file downloads I'd rather not hold a serverless function open: start the import from your route, store the jobId, and save the mediaUrl when the webhook arrives. A failed job (a private video, say) comes back with status: 'failed' and an error code the model can explain to the user.

On cost, a caption transcript is $0.003 and speech-to-text is $0.01 a minute, so a summarize button is cheap to leave on. Importly is free to try with no card if you want to run the code above as is: https://www.importly.io/?utm_source=devto&utm_medium=syndication&utm_campaign=ai-sdk-tools

The full guide, with what each tool returns, is in the docs: https://www.importly.io/docs/integrations/ai-sdk