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. Copy the key from the Token authentication key card below it. The field there is labelled API key, but it’s a different value from the library’s API key on the API page. The same key signs CDN token authentication URLs for the library, so resetting it breaks both. 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.
Check that the viewer may watch the video before you sign its URL. The page or route that signs is a public endpoint, so anyone can request it with any video ID from your library. Without that check, token authentication protects nothing. The comment in each example below marks where the check goes.
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() signs a fresh URL on every request. Without it, Next.js can prerender a token at build time. Call it, and read params, in a component inside <Suspense>. With Cache Components on, as in a new create-next-app project, request data outside <Suspense> fails the build.
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 Token authentication key card on the Security page, not the library’s API key on the API page. 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