token and expires. The key behind those tokens can sign every video in the library. Keep it on the server and send the browser a finished URL.
Next.js
A Server Component.
Nuxt
A server route and
useFetch.SvelteKit
A server
load function.Turn on token authentication
On your library’s Security page, enable Embed view token authentication and copy the key. Unsigned embeds start returning 403 straight away. Deploy the signing code first.Sign the URL
The token is a hex SHA-256 of the key, video ID, and expiry, joined with nothing between them. The expiry is Unix time in seconds.- Next.js
- Nuxt
- SvelteKit
Put For playback control, pass
BUNNY_STREAM_LIBRARY_ID and BUNNY_STREAM_TOKEN_AUTH_KEY in .env.local. The server-only import breaks the build if a Client Component ever pulls this file in.lib/bunny-stream.ts
await connection() makes the page render per request. Without it, Next.js can prerender a token at build time.app/videos/[id]/page.tsx
token and expires to the Next.js guide’s component through params.Choose an expiry
Anyone holding a signed URL can play it until it expires. We use an hour in the examples to make them easy to try. Production pages sign a fresh URL on every load, which makes a window of a few minutes painless.Troubleshooting
The iframe shows a 403
The iframe shows a 403
Check the inputs. The key comes from the Security page, and it’s a separate value from the API key. The video ID must match the URL, and
expires must be in seconds.With a good token, look at the library’s embedding restrictions.Every visitor gets the same expired link
Every visitor gets the same expired link
The page was rendered once and cached. Call
await connection() in Next.js, and check the route isn’t prerendered in Nuxt or SvelteKit.