Docs
Skip to content

Functions

Environment variables_

Set environment variables for your Appwrite Functions to pass constants and secrets at build and runtime.

3 min read

Raw

Appwrite Functions can read environment variables at build and runtime. Use them to pass constants and secrets such as API keys, connection strings, and feature flags without hardcoding them in your source.

A function reads from three sources, in this order of precedence:

  1. Project variables are shared across every function and site in your project. Set them once and every function inherits them automatically. See project variables for the platform-wide reference.
  2. Function variables are scoped to a single function. Override a project variable for one function by setting the same key on the function itself.
  3. Appwrite-injected variables are set by Appwrite at execution time (for example, APPWRITE_FUNCTION_PROJECT_ID). These take final precedence and cannot be overridden.

Manage in the Console

  1. Navigate to your function in the Appwrite Console.
  2. Open the Settings tab > Environment variables section.
  3. Click Create variable and enter a key and value.
  4. Optionally select the Secret checkbox to prevent any team member from reading the value after creation.
  5. Click Create, then redeploy the function for the change to take effect.

Function environment variables
Function environment variables

You can also configure global variables that apply to all your functions from your project's Settings page. See project variables for details.

Manage with a Server SDK

You can also manage function variables programmatically using a Server SDK. Each call requires an API key with the functions.write scope to create, update, or delete variables, or the functions.read scope to list and read them.

Create a variable

List variables

Get a variable

Update a variable

You can change a variable's key, value, or secret flag. Marking a variable as secret is one-way. Once set, the value is no longer readable from the Console or API.

Delete a variable

Read variables in your function

Once a variable is set, you can read it inside your function using your runtime language's standard environment lookup.

Appwrite-injected variables

Appwrite passes the following environment variables into every function deployment by default. They take precedence over your own variables, so do not set keys with the APPWRITE_ prefix.

VariableDescriptionAvailable at Build and/or Run Time
APPWRITE_FUNCTION_API_ENDPOINTThe API endpoint of the running functionBoth
APPWRITE_VERSIONThe Appwrite version used to run the functionBoth
APPWRITE_REGIONThe region where the function will run fromBoth
APPWRITE_FUNCTION_API_KEYThe function API key used for server authenticationBuild time
APPWRITE_FUNCTION_IDThe ID of the running functionBoth
APPWRITE_FUNCTION_NAMEThe name of the running functionBoth
APPWRITE_FUNCTION_DEPLOYMENTThe deployment ID of the running functionBoth
APPWRITE_FUNCTION_PROJECT_IDThe project ID of the running functionBoth
APPWRITE_FUNCTION_RUNTIME_NAMEThe runtime of the running functionBoth
APPWRITE_FUNCTION_RUNTIME_VERSIONThe runtime version of the running functionBoth
APPWRITE_FUNCTION_CPUSThe CPU (runtime) specification of the running functionBoth
APPWRITE_FUNCTION_MEMORYThe memory (runtime) specification of the running functionBoth

During the build process, dynamic API keys are automatically provided as the environment variable APPWRITE_FUNCTION_API_KEY. This environment variable does not need to be initialized.

Secret variables

Mark a variable as Secret to hide its value from the Console and API after creation. Only the function runtime can read the value at build and runtime. Team members and external integrations cannot retrieve it after creation.

You can mark a variable as secret either when you create it or by updating an existing variable. Marking a variable as secret cannot be reversed. To replace a secret value, delete the variable and create a new one with the same key.

Limits

FieldLimit
Variable ID36 characters, a-z A-Z 0-9 . - _
Key255 characters
Value8192 characters

Was this page helpful?

Share what worked or what we should fix. Once approved, our agents automatically apply suggested updates to the docs.