Skip to main content

Environment variables

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

System environment variables

The Actor's process has several environment variables set to provide it with context:

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. It's 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. See documentation for more information.
ACTOR_DEFAULT_DATASET_IDID of the dataset where you can push the data.
ACTOR_DEFAULT_KEY_VALUE_STORE_IDID of the key-value store where the Actor's input and output data are stored.
ACTOR_DEFAULT_REQUEST_QUEUE_IDID of the request queue that stores and handles requests that you enqueue.
ACTOR_INPUT_KEYThe key of the record in the default key-value store that holds the Actor input. Typically it's INPUT, but it might be something else.
ACTOR_MAX_PAID_DATASET_ITEMSIf the Actor is paid per result, this will contain the limit set by the user on how many results they want to return. Do not return them more results because they will be only charged for the limit they set, and you might start accumulating loss.
APIFY_HEADLESSIf set to 1, the web browsers inside the Actor should run in headless mode because there is no windowing system available.
APIFY_IS_AT_HOMEIs set to 1 if the Actor is running on Apify servers.
ACTOR_MEMORY_MBYTESIndicates the size of memory allocated for the Actor run, in megabytes. It can be used by Actors to optimize their memory usage.
APIFY_PROXY_PASSWORDThe Apify Proxy password of the user who started the Actor.
ACTOR_STARTED_ATDate when the Actor was started.
ACTOR_TIMEOUT_ATDate when the Actor will time out.
APIFY_TOKENThe API token of the user who started the Actor.
APIFY_USER_IDID of the user who started the Actor. Note that it might be different than the owner of the Actor.
ACTOR_WEB_SERVER_PORTTCP port on which the Actor can start an HTTP server to receive messages from the outside world.
ACTOR_WEB_SERVER_URLA unique public URL under which the Actor run web server is accessible from the outside world.

Dates are always in the UTC timezone and are represented in simplified extended ISO format (ISO 8601), e.g. 2022-07-13T14:23:37.281Z.

// To access environment variables in Node.js, use the process.env object

For convenience, rather than using environment vars directly, we provide a Configuration class that allows reading and updating the Actor configuration.

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

The Actor owner can specify custom environment variables that are set to the Actor's process during the run. Sensitive environment variables such as passwords or API tokens can be protected by setting the Secret option. With this option enabled, the value of the environment variable is encrypted, and it will not be visible in the app or APIs. In addition, the value is redacted from Actor logs to avoid the accidental leakage of sensitive data.

Custom environment variables

Note that the custom environment variables are fixed during the build of the Actor and cannot be changed later. See the Builds section for details.

The Actor runtime sets additional environment variables for the Actor process during the run. See Environment variables for details.

The environment variables can also be used for the build process. In this case, the variables are treated as Docker build arguments. This means that they should not be used for secrets and, in order to access them in Dockerfile, you have to use the ARG variable_name instruction.