Skip to main content
With embed view token authentication on, Bunny Player turns away any embed URL without a valid 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.
Put 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
For playback control, pass 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

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.
Last modified on October 6, 2026