Skip to main content

Actor environment variables

Learn how to provide your Actor with context that determines its behavior through a plethora of pre-defined environment variables set by the Apify platform.


System environment variables

Apify sets several system environment variables for each Actor run. These variables provide essential context and information about the Actor's execution environment.

Here's a table of key system environment variables:

Environment VariableDescription
ACTOR_IDID of the Actor.
ACTOR_RUN_IDID of the Actor run.
ACTOR_BUILD_IDID of the Actor build used in the run.
ACTOR_BUILD_NUMBERBuild number of the Actor build used in the run.
ACTOR_TASK_IDID of the Actor task. Empty if Actor is run outside of any task, e.g. directly using the API.
ACTOR_EVENTS_WEBSOCKET_URLWebsocket URL where Actor may listen for events from Actor platform.
ACTOR_DEFAULT_DATASET_IDUnique identifier for the default dataset associated with the current Actor run.
ACTOR_DEFAULT_KEY_VALUE_STORE_IDUnique identifier for the default key-value store associated with the current Actor run.
ACTOR_DEFAULT_REQUEST_QUEUE_IDUnique identifier for the default request queue associated with the current Actor run.
ACTOR_INPUT_KEYKey of the record in the default key-value store that holds the Actor input.
ACTOR_MAX_PAID_DATASET_ITEMSFor paid-per-result Actors, the user-set limit on returned results. Do not exceed this limit.
APIFY_HEADLESSIf 1, web browsers inside the Actor should run in headless mode (no windowing system available).
APIFY_IS_AT_HOMEContains 1 if the Actor is running on Apify servers.
ACTOR_MEMORY_MBYTESSize of memory allocated for the Actor run, in megabytes. Can be used to optimize memory usage or finetuning of low-level external libraries.
APIFY_PROXY_PASSWORDPassword for accessing Apify Proxy services. This password enables the Actor to utilize proxy servers on behalf of the user who initiated the Actor run.
APIFY_PROXY_PORTTCP port number to be used for connecting to the Apify Proxy.
APIFY_PROXY_STATUS_URLURL for retrieving proxy status information. Appending ?format=json to this URL returns the data in JSON format for programmatic processing.
ACTOR_STANDBY_URLURL for accessing web servers of Actor runs in the Actor Standby mode.
ACTOR_STARTED_ATDate when the Actor was started.
ACTOR_TIMEOUT_ATDate when the Actor will time out.
APIFY_TOKENAPI token of the user who started the Actor.
APIFY_USER_IDID of the user who started the Actor. May differ from the Actor owner.
ACTOR_WEB_SERVER_PORTTCP port for the Actor to start an HTTP server on. This server can be used to receive external messages or expose monitoring and control interfaces. The server also receives messages from the Actor Standby mode.
ACTOR_WEB_SERVER_URLUnique public URL for accessing the Actor run web server from the outside world.
APIFY_API_PUBLIC_BASE_URLPublic URL of the Apify API. May be used to interact with the platform programmatically. Typically set to api.apify.com.
APIFY_DEDICATED_CPUSNumber of CPU cores reserved for the actor, based on allocated memory.
APIFY_DISABLE_OUTDATED_WARNINGControls the display of outdated version warnings. Set to 1 to suppress notifications about updates.
APIFY_WORKFLOW_KEYIdentifier used for grouping related runs and API calls together.
APIFY_META_ORIGINSpecifies how an Actor run was started. Possible values are here
APIFY_SDK_LATEST_VERSIONSpecifies the most recent release version of the Apify SDK for Javascript. Used for checking for updates.
APIFY_INPUT_SECRETS_KEY_FILEPath to the secret key used to decrypt Secret inputs.
APIFY_INPUT_SECRETS_KEY_PASSPHRASEPassphrase for the input secret key specified in APIFY_INPUT_SECRETS_KEY_FILE.
Date format

All date-related variables use the UTC timezone and are in ISO 8601 format (e.g., 2022-07-13T14:23:37.281Z).

Access environment variables

You can access environment variables in your code as follows:

In Node.js, use the process.env object:

console.log(process.env.APIFY_USER_ID);

Use the Configuration class

For more convenient access to Actor configuration, use the Configuration class

import { Actor } from 'apify';

await Actor.init();

// get current token
const token = Actor.config.get('token');
// use different token
Actor.config.set('token', 's0m3n3wt0k3n');

await Actor.exit();

Custom environment variables

Actor owners can define custom environment variables to pass additional configuration to their Actors. To set custom variables:

  1. Go to your Actor's Source page in the Apify Console

  2. Navigate to the Environment variables section.

  3. Add your custom variables.

For sensitive data like API keys or passwords, enable the Secret option. This encrypt the value and redacts it from logs to prevent accidental exposure.

Build-time variables

Custom environment variables are set during the Actor's build process and cannot be changed for existing builds. For more information, check out the Builds page.

Build-time environment variables

You can also use environment variables during the Actor's build process. In this case, they function as Docker build arguments. To use them in your Dockerfile, include ARG instruction:

ARG MY_BUILD_VARIABLE
RUN echo $MY_BUILD_VARIABLE
Insecure build variables

Build-time environment variables are not suitable for secrets, as they are not encrypted.

By leveraging environment variables effectively, you can create more flexible and configurable Actors that adapt to different execution contexts and user requirements.