Skip to main content
Environment secrets are sensitive configuration settings, such as API keys, passwords, or tokens, that are securely stored and used by your script. They are kept hidden from source code to prevent unauthorized access and maintain the security of your system. Unlike environment variables, secrets cannot be viewed once they are set. You can only update or delete them. This ensures that sensitive values remain protected even from users with dashboard access.

Adding environment secrets

To add environment secrets to your script, follow these steps:
  1. Log in to the bunny.net dashboard.
  2. Select Edge Platform, click on Scripting, and select the script.
  1. Select Env Configuration and Environment Secrets, and fill in the details of the secret you want to create.
  1. Click Save Secret.

Using environment secrets

Environment secrets are accessed in the same way as environment variables, using either the Node.js process module or Deno.env.
import * as BunnySDK from "https://esm.sh/@bunny.net/[email protected]";
import process from "node:process";

BunnySDK.net.http.serve(async (request: Request): Response | Promise<Response> => {
  // Load secret named ApiKey
  const apiKey = process.env.ApiKey;

  // Use the secret in an API request
  const response = await fetch("https://api.example.com/data", {
    headers: {
      "Authorization": `Bearer ${apiKey}`
    }
  });

  return new Response(await response.text());
});
You can also use Deno.env.get():
const apiKey = Deno.env.get("ApiKey");
Names of environment variables and secrets on the same script must be unique. You cannot use the same name for both a variable and a secret.