Skip to main content
When someone pastes a video link into your app, the first thing to show is a preview card: the title, a thumbnail and how long it is. In a Lovable or Bolt app that usually starts as a fetch of the page from the browser, which most video sites block, or a scraper in an Edge Function that gets a bot check instead of the page once it runs on a server. Send the link to Importly’s basic metadata endpoint instead, and keep the answer in a table. This recipe is one Edge Function and one table:
  • link-preview takes a link from a signed-in user, returns the preview from the link_previews table if anyone has pasted that link before, and otherwise looks it up and saves it.
  • link_previews holds one row per link. Only the function reads and writes it, so it needs no policies.
Your frontend never sees your Importly key. For the same preview on a Node or Python server, see Video link previews in Node. To go on and save the video file or a transcript, see Save videos to Supabase Storage and Save transcripts to Supabase.

1. Add your key as a secret

Create your key on the API key page (it is shown once) and store it as an Edge Function secret:
SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY are already available inside every Edge Function. For supabase functions serve, put IMPORTLY_API_KEY in supabase/functions/.env and keep that file out of git.

2. The table

Run this in the SQL editor or add it as a migration. RLS is on with no policies, so the browser can’t read or write it directly; the function uses the service role key.
The same link always gives the same preview, so the link itself is the key. duration is numeric because some sites report fractions of a second.

3. The function

supabase/functions/link-preview/index.ts
Deploy it with supabase functions deploy link-preview. Supabase checks the user’s JWT before the function runs, and the getUser call makes sure it belongs to a real signed-in user, so people can’t spend your credits from outside your app. The function waits up to 30 seconds for a new link. Most previews come back in a few seconds, well inside the Edge Function limits (see Edge Function limits). A link already in the table comes back straight away.

4. Call it from your app

supabase.functions.invoke sends the signed-in user’s session for you. In our test on a Supabase project, a Vimeo link came back in about 8 seconds the first time and under half a second from the table after that:
duration is in seconds. A live stream that hasn’t ended has is_live: true and no duration, so show a “Live” badge instead of a length. It can’t be downloaded or transcribed until the stream ends. Using Lovable, Bolt or Cursor to build the screen? Give it the function’s request and response above and ask for a preview card under the link input that shows the thumbnail, the title and the length as m:ss.

Errors to handle

supabase.functions.invoke puts any non-2xx answer in error. These are the ones to expect: Every Importly error has a documentationUrl with the fix. See Error handling.

In production

  • Some sites’ thumbnails expire. TikTok’s thumbnail links are signed and stop working after a while (ours carried an x-expires about two days out). If cards stay on screen for longer, copy the image into a Storage bucket when you save the row, or look the link up again when the thumbnail fails to load.
  • Check the length before a bigger job: reject anything over your limit before you pay to download or transcribe it.
  • For the description, uploader, upload date or view counts, call POST /metadata instead. It costs the same and returns everything the source exposes.
  • Saving previews in the background (a feed, a bulk import)? Pass a webhookUrl and save the row when Importly calls you back, the way Save transcripts to Supabase does. See Webhooks.
A preview costs $0.003 per link the first time, and status checks are free. Links already in your table cost nothing. Try it free, no card required. See Pricing & credits.
Using Claude Code, Cursor or Lovable’s chat on this project? Connect the MCP server and ask it to add link previews with Importly: it reads the same integration guide and can test with a real link first. See Build with your agent.