Environment variables

Environment variables are per-function configuration values. Unlike secrets (which are organization-wide), env vars are scoped to a specific function and are useful for function-level settings like feature flags, API endpoints, or mode toggles.

How they differ from secrets

Secrets Environment variables
Scope Organization-wide Per-function
Encrypted at rest Yes (AES-GCM) Yes (if encryption key set)
Visible in API Never (names only) Preview only (val****)
Injected at Deploy time Deploy time
Use case API keys, tokens, passwords Config values, endpoints, flags

Both are injected as bindings and accessible via env.NAME in your function code.

Setting an env var (POST /env-vars)

curl -X POST https://api.fold.run/env-vars \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "function_id": "fn_abc123",
    "name": "API_ENDPOINT",
    "value": "https://api.example.com/v2"
  }'
Field Type Required Description
function_id string Yes Function to set the variable on
name string Yes Variable name (max 256 chars)
value string Yes Variable value (max 64 KB)

Setting an env var with the same name overwrites the existing value.

Listing env vars (GET /env-vars/:function_id)

curl "https://api.fold.run/env-vars/fn_abc123" \
  -H "Authorization: Bearer YOUR_TOKEN"

Response:

{
  "env_vars": [
    {
      "name": "API_ENDPOINT",
      "value_preview": "http****",
      "created_at": "2026-03-14T12:00:00Z"
    }
  ]
}

Full values are never returned by the API — only a masked preview.

Deleting an env var

curl -X DELETE "https://api.fold.run/env-vars/fn_abc123/API_ENDPOINT" \
  -H "Authorization: Bearer YOUR_TOKEN"

The variable is removed on the next deploy.

Using in your code

Env vars are available on the env parameter, just like secrets:

export default {
  async fetch(request: Request, env: Record<string, string>) {
    const endpoint = env.API_ENDPOINT;
    const res = await fetch(endpoint + "/data");
    return new Response(await res.text());
  }
};

Managing via CLI

# Set an env var
fold env set fn_abc123 API_ENDPOINT "https://api.example.com/v2"

# List env vars
fold env list fn_abc123

# Delete an env var
fold env delete fn_abc123 API_ENDPOINT

Important

Env vars take effect on the next deploy. If you change an env var, redeploy the function to pick up the new value.