Skip to main content
Version: Next

Configuration

Configuration is a value object holding the SDK configuration. We can use it in two ways:

  1. When using Actor class, we can get the instance configuration via sdk.configuration
    import { Actor } from 'apify';

    const sdk = new Actor({ token: '123' });
    console.log(sdk.configuration.token); // '123'
  2. To get the global configuration (singleton instance). It will respect the environment variables.
    import { Configuration } from 'apify';

    const config = Configuration.getGlobalConfiguration();
    console.log(config.headless);
    console.log(config.persistStateIntervalMillis);

Configuration is immutable — values are set via the constructor and cannot be changed afterwards. The priority order for resolving values is (highest to lowest):

constructor options > environment variables > crawlee.json > schema defaults

Supported Configuration Options

KeyEnvironment VariableDefault Value
memoryMbytesACTOR_MEMORY_MBYTES-
headlessAPIFY_HEADLESStrue
persistStateIntervalMillisAPIFY_PERSIST_STATE_INTERVAL_MILLIS60e3
tokenAPIFY_TOKEN-
isAtHomeAPIFY_IS_AT_HOME-
defaultDatasetIdACTOR_DEFAULT_DATASET_ID'default'
defaultKeyValueStoreIdACTOR_DEFAULT_KEY_VALUE_STORE_ID'default'
defaultRequestQueueIdACTOR_DEFAULT_REQUEST_QUEUE_ID'default'

Advanced Configuration Options

KeyEnvironment VariableDefault Value
actorEventsWsUrlACTOR_EVENTS_WEBSOCKET_URL-
actorIdACTOR_ID-
actorRunIdACTOR_RUN_ID-
actorTaskIdACTOR_TASK_ID-
apiBaseUrlAPIFY_API_BASE_URL'https://api.apify.com/'
containerPortACTOR_WEB_SERVER_PORT4321
containerUrlACTOR_WEB_SERVER_URL'http://localhost:4321'
inputKeyACTOR_INPUT_KEY'INPUT'
metamorphAfterSleepMillisAPIFY_METAMORPH_AFTER_SLEEP_MILLIS300e3
metaOriginAPIFY_META_ORIGIN-
proxyHostnameAPIFY_PROXY_HOSTNAME'proxy.apify.com'
proxyPasswordAPIFY_PROXY_PASSWORD-
proxyPortAPIFY_PROXY_PORT8000
proxyStatusUrlAPIFY_PROXY_STATUS_URL'http://proxy.apify.com'
userIdAPIFY_USER_ID-
xvfbAPIFY_XVFB-
standbyPortACTOR_STANDBY_PORT4321
standbyUrlACTOR_STANDBY_URL-
chromeExecutablePathAPIFY_CHROME_EXECUTABLE_PATH-
defaultBrowserPathAPIFY_DEFAULT_BROWSER_PATH-

Hierarchy

Index

Constructors

constructor

  • Parameters

    • options: FieldsInput<{ actorEventsWsUrl: ConfigField<ZodOptional<ZodString>>; actorId: ConfigField<ZodOptional<ZodString>>; actorPermissionLevel: ConfigField<ZodOptional<ZodString>>; actorPricingInfo: ConfigField<ZodOptional<ZodString>>; actorRunId: ConfigField<ZodOptional<ZodString>>; actorStoragesJson: ConfigField<ZodOptional<ZodString>>; actorTaskId: ConfigField<ZodOptional<ZodString>>; apiBaseUrl: ConfigField<ZodDefault<ZodString>>; apiPublicBaseUrl: ConfigField<ZodDefault<ZodString>>; availableMemoryRatio: ConfigField<ZodDefault<ZodPreprocess<ZodNumber, unknown>>>; chargedEventCounts: ConfigField<ZodOptional<ZodString>>; chromeExecutablePath: ConfigField<ZodOptional<ZodString>>; containerized: ConfigField<ZodOptional<ZodPreprocess<ZodBoolean, unknown>>>; containerPort: ConfigField<ZodDefault<ZodPreprocess<ZodNumber, unknown>>>; containerUrl: ConfigField<ZodDefault<ZodString>>; defaultBrowserPath: ConfigField<ZodOptional<ZodString>>; defaultDatasetId: ConfigField<ZodDefault<ZodString>>; defaultKeyValueStoreId: ConfigField<ZodDefault<ZodString>>; defaultRequestQueueId: ConfigField<ZodDefault<ZodString>>; disableBrowserSandbox: ConfigField<ZodDefault<ZodPreprocess<ZodBoolean, unknown>>>; headless: ConfigField<ZodDefault<ZodPreprocess<ZodBoolean, unknown>>>; inputKey: ConfigField<ZodDefault<ZodString>>; inputSecretsPrivateKeyFile: ConfigField<ZodOptional<ZodString>>; inputSecretsPrivateKeyPassphrase: ConfigField<ZodOptional<ZodString>>; internalTimeoutMillis: ConfigField<ZodOptional<ZodPreprocess<ZodNumber, unknown>>>; isAtHome: ConfigField<ZodDefault<ZodPreprocess<ZodBoolean, unknown>>>; logLevel: ConfigField<ZodOptional<ZodPreprocess<ZodEnum<typeof LogLevel>, unknown>>>; maxTotalChargeUsd: ConfigField<ZodDefault<ZodPipe<ZodPreprocess<ZodNumber, unknown>, ZodTransform<number, number>>>>; maxUsedCpuRatio: ConfigField<ZodDefault<ZodPreprocess<ZodNumber, unknown>>>; memoryMbytes: ConfigField<ZodOptional<ZodPreprocess<ZodNumber, unknown>>>; metamorphAfterSleepMillis: ConfigField<ZodDefault<ZodPreprocess<ZodNumber, unknown>>>; metaOrigin: ConfigField<ZodOptional<ZodString>>; persistStateIntervalMillis: ConfigField<ZodDefault<ZodPreprocess<ZodNumber, unknown>>>; persistStorage: ConfigField<ZodDefault<ZodPreprocess<ZodBoolean, unknown>>>; proxyHostname: ConfigField<ZodDefault<ZodString>>; proxyPassword: ConfigField<ZodOptional<ZodString>>; proxyPort: ConfigField<ZodDefault<ZodPreprocess<ZodNumber, unknown>>>; proxyStatusUrl: ConfigField<ZodDefault<ZodString>>; purgeOnStart: ConfigField<ZodDefault<ZodPreprocess<ZodBoolean, unknown>>>; standbyPort: ConfigField<ZodDefault<ZodPreprocess<ZodNumber, unknown>>>; standbyUrl: ConfigField<ZodOptional<ZodString>>; storageClientOptions: ConfigField<ZodOptional<ZodRecord<ZodString, ZodUnknown>>>; storageDir: ConfigField<ZodDefault<ZodString>>; systemInfoIntervalMillis: ConfigField<ZodDefault<ZodPreprocess<ZodNumber, unknown>>>; testPayPerEvent: ConfigField<ZodDefault<ZodPreprocess<ZodBoolean, unknown>>>; token: ConfigField<ZodOptional<ZodString>>; useChargingLogDataset: ConfigField<ZodDefault<ZodPreprocess<ZodBoolean, unknown>>>; userId: ConfigField<ZodOptional<ZodString>>; userIsPaying: ConfigField<ZodOptional<ZodString>>; xvfb: ConfigField<ZodDefault<ZodPreprocess<ZodBoolean, unknown>>> }> = {}

    Returns Configuration

Properties

inheritedactorEventsWsUrl

actorEventsWsUrl: undefined | string = ...

inheritedactorId

actorId: undefined | string = ...

inheritedactorPermissionLevel

actorPermissionLevel: undefined | string = ...

inheritedactorPricingInfo

actorPricingInfo: undefined | string = ...

inheritedactorRunId

actorRunId: undefined | string = ...

inheritedactorStoragesJson

actorStoragesJson: undefined | string = ...

inheritedactorTaskId

actorTaskId: undefined | string = ...

inheritedapiBaseUrl

apiBaseUrl: string = ...

inheritedapiPublicBaseUrl

apiPublicBaseUrl: string = ...

externalinheritedavailableMemoryRatio

availableMemoryRatio: number = 0.25

inheritedchargedEventCounts

chargedEventCounts: undefined | string = ...

externalinheritedchromeExecutablePath

chromeExecutablePath: undefined | string

externalinheritedcontainerized

containerized: undefined | boolean

inheritedcontainerPort

containerPort: number = ...

inheritedcontainerUrl

containerUrl: string = ...

externalinheriteddefaultBrowserPath

defaultBrowserPath: undefined | string

inheriteddefaultDatasetId

defaultDatasetId: string = ...

inheriteddefaultKeyValueStoreId

defaultKeyValueStoreId: string = ...

inheriteddefaultRequestQueueId

defaultRequestQueueId: string = ...

externalinheriteddisableBrowserSandbox

disableBrowserSandbox: boolean = false

externalinheritedheadless

headless: boolean = true

inheritedinputKey

inputKey: string = ...

inheritedinputSecretsPrivateKeyFile

inputSecretsPrivateKeyFile: undefined | string = ...

inheritedinputSecretsPrivateKeyPassphrase

inputSecretsPrivateKeyPassphrase: undefined | string = ...

externalinheritedinternalTimeoutMillis

internalTimeoutMillis: undefined | number

Internal safety-net timeout for a single request, in milliseconds. When unset the crawler derives it from the request handler timeout (twice it, and never below 5 minutes).

inheritedisAtHome

isAtHome: boolean = ...

externalinheritedlogLevel

logLevel: undefined | OFF | ERROR | SOFT_FAIL | WARNING | INFO | DEBUG | PERF

inheritedmaxTotalChargeUsd

maxTotalChargeUsd: number = ...

externalinheritedmaxUsedCpuRatio

maxUsedCpuRatio: number = 0.95

externalinheritedmemoryMbytes

memoryMbytes: undefined | number

inheritedmetamorphAfterSleepMillis

metamorphAfterSleepMillis: number = ...

inheritedmetaOrigin

metaOrigin: undefined | string = ...

externalinheritedpersistStateIntervalMillis

persistStateIntervalMillis: number = 60_000

externalinheritedpersistStorage

persistStorage: boolean = true

inheritedproxyHostname

proxyHostname: string = ...

inheritedproxyPassword

proxyPassword: undefined | string = ...

inheritedproxyPort

proxyPort: number = ...

inheritedproxyStatusUrl

proxyStatusUrl: string = ...

externalinheritedpurgeOnStart

purgeOnStart: boolean = true

inheritedstandbyPort

standbyPort: number = ...

Deprecated - use containerPort instead

inheritedstandbyUrl

standbyUrl: undefined | string = ...

inheritedstorageClientOptions

storageClientOptions: undefined | Record<string, unknown> = ...

externalinheritedstorageDir

storageDir: string = ’./storage’

externalinheritedsystemInfoIntervalMillis

systemInfoIntervalMillis: number = 1_000

inheritedtestPayPerEvent

testPayPerEvent: boolean = ...

inheritedtoken

token: undefined | string = ...

inheriteduseChargingLogDataset

useChargingLogDataset: boolean = ...

inheriteduserId

userId: undefined | string = ...

inheriteduserIsPaying

userIsPaying: undefined | string = ...

externalinheritedxvfb

xvfb: boolean = false

Methods

staticgetGlobalConfiguration


  • Returns Configuration

    the SDK's global Configuration singleton (an Apify-typed default that parses APIFY_* env vars). During an Actor run the active configuration is held by crawlee's serviceLocator, which is what crawlee internals resolve against; this singleton is only the fallback for code reaching for a configuration without an explicit one.