Configure custom environment variables for Dify

Updated at:

This topic describes how to set or update custom environment variables for your Dify instance in the Alibaba Cloud DMS console to optimize performance, access policies, service URLs, and other configurations.

Notes

  • Service restart: Saving a change to an environment variable automatically restarts the Dify instance, causing a brief service interruption. Perform this operation during off-peak hours.

  • Whitelist restriction: For security, you can only modify environment variables on the whitelist. For the complete list, see Supported environment variables.

  • Formatting requirements: All parameters must be provided in the standard JSON key-value pair ("Key": "Value") format, and each Value must be a string.

Procedure

  1. Log in to the DMS console. In the top navigation bar, click Data + AI > Dify to open the Dify instance list page.

  2. In the Actions column for the target Dify instance, click Resource Management.

  3. On the resource management page, click Environment Parameters.

  4. In the Environment Parameter Configuration dialog box, modify or add environment variables.

    • Modify an existing parameter:

      • Edit the value directly in the input box.

      • To restore the default value, delete the key-value pair. The system automatically restores the default value when you save.

    • Add a new parameter:

      • Some whitelisted parameters are not displayed by default and must be added manually.

      • For example, to configure a custom domain name: In the editor, manually add the following key-value pair. You can replace my_web.com with your actual domain name.

        Note

        CONSOLE_API_URL, CONSOLE_WEB_URL, and APP_WEB_URL can only be modified in the Dify Account Edition or Enterprise Edition.

        {
          "HTTP_REQUEST_NODE_MAX_TEXT_SIZE": "1048576",
          ...
          "CONSOLE_API_URL": "http://my_web.com",
          "APP_API_URL": "http://my_web.com",
          "CONSOLE_WEB_URL": "http://my_web.com",
          "APP_WEB_URL": "http://my_web.com",
          "FILES_URL": "http://my_web.com"
        }
  5. After making your changes, click Save, and then click OK in the confirmation dialog box.

  6. After you save the settings, the system redeploys the instance.

    • Success status:

      If you see the messages Environment parameter validation successful, Environment parameter update successful, and Redeployment has started in the lower-right corner, the update was successful and the Dify instance is restarting.

    • Failure status:

      If the Env key 'xxxx' is invalid error occurs, it means that the corresponding key xxxx is invalid. Carefully check whether the key is in the whitelist and is spelled correctly.

      For example, the environment variable key UPLOAD_FILE__LIMIT (which is misspelled with a double underscore) will trigger this error message.

Supported environment variables

Parameter

Default

Description

CODE_MAX_STRING_LENGTH

800000

The maximum length of a string output from a code node.

TEMPLATE_TRANSFORM_MAX_LENGTH

800000

The maximum length of a string in a template transformation.

CODE_MAX_STRING_ARRAY_LENGTH

1000

The maximum number of elements in a string array output from a code node.

CODE_MAX_OBJECT_ARRAY_LENGTH

1000

The maximum number of elements in an object array output from a code node.

CODE_MAX_NUMBER_ARRAY_LENGTH

1000

The maximum number of elements in a number array output from a code node.

CODE_MAX_DEPTH

5

The maximum nesting depth for objects or arrays output from a code node.

CODE_MAX_PRECISION

20

The maximum precision (number of decimal places) for numbers in a code node.

SQLALCHEMY_POOL_SIZE

60

The size of the database connection pool (maximum number of connections).

SQLALCHEMY_POOL_RECYCLE

3600

The connection recycle timeout in seconds. Connections older than this time are recycled.

PLUGIN_MAX_PACKAGE_SIZE

52428800

The maximum allowed size for a plugin package in bytes.

GUNICORN_TIMEOUT

360

The maximum time in seconds to wait for a response. A request is terminated if it exceeds this timeout.

UPLOAD_FILE_SIZE_LIMIT

50

The maximum size of a single uploaded file in MB.

UPLOAD_FILE_BATCH_LIMIT

10

The maximum number of files in a single batch upload.

HTTP_REQUEST_NODE_MAX_TEXT_SIZE

1048576

The maximum size of a text response from an HTTP request node in bytes.

HTTP_REQUEST_NODE_MAX_BINARY_SIZE

10485760

The maximum size of a binary response from an HTTP request node in bytes.

CONSOLE_API_URL

  • For DMS account logon:

    https://dify-<region-id>-dms.aliyuncs.com

  • For Dify account logon or Dify Enterprise Edition:

    http://<your_alb_public_ip>

The access URL for the console backend API. Modifiable only in Dify Account Edition or Dify Enterprise Edition.

APP_API_URL

The access URL for the application API.

CONSOLE_WEB_URL

The access URL for the console frontend. Modifiable only in Dify Account Edition or Dify Enterprise Edition.

APP_WEB_URL

The access URL for the application frontend. Modifiable only in Dify Account Edition or Dify Enterprise Edition.

FILES_URL

The access URL for the file service.

DIFY_BACKWARDS_INVOCATION_WRITE_TIMEOUT

60000

The timeout, in milliseconds, for plugin backward invocation write operations.

DIFY_BACKWARDS_INVOCATION_READ_TIMEOUT

60000

The timeout, in milliseconds, for plugin backward invocation read operations.

PYTHON_ENV_INIT_TIMEOUT

320

The timeout in seconds for plugin Python environment initialization.

TOP_K_MAX_VALUE

50

The maximum allowed value for Top-K in knowledge base retrieval.

TEXT_GENERATION_TIMEOUT_MS

60000

The timeout in milliseconds for text generation requests.

LOOP_NODE_MAX_COUNT

100

The maximum number of iterations for a loop node.

MAX_TOOLS_NUM

10

The maximum number of tools an agent can use.

MAX_PARALLEL_LIMIT

10

The maximum number of concurrent executions for a parallel execution node.

MAX_ITERATIONS_NUM

99

The maximum number of iterations for an iteration node.

MAX_TREE_DEPTH

50

The longest path of nodes from start to end in a workflow.

SERVICE_API_URL

Empty

The access URL for the API service.

TRIGGER_URL

Empty

The callback URL for the workflow trigger.

FILES_ACCESS_TIMEOUT

300

The timeout in seconds for file access operations.

HTTP_REQUEST_MAX_CONNECT_TIMEOUT

300

The maximum timeout in seconds for establishing an HTTP connection.

HTTP_REQUEST_MAX_READ_TIMEOUT

600

The maximum timeout in seconds for reading an HTTP response.

HTTP_REQUEST_MAX_WRITE_TIMEOUT

600

The maximum timeout in seconds for writing HTTP request data.

CODE_EXECUTION_CONNECT_TIMEOUT

10

The timeout in seconds for connecting to the code execution service.

CODE_EXECUTION_READ_TIMEOUT

60

The timeout in seconds for reading code execution results.

CODE_EXECUTION_WRITE_TIMEOUT

10

The timeout in seconds for writing code execution data.

ACCESS_TOKEN_EXPIRE_MINUTES

60

The expiration time, in minutes, for an access token.

APP_MAX_ACTIVE_REQUESTS

0

The maximum number of concurrent requests the application can handle (0 means unlimited).

APP_MAX_EXECUTION_TIME

1200

The maximum execution time for a single application run in seconds.

ENABLE_SOCIAL_OAUTH_LOGIN

false

Specifies whether to enable social account OAuth login.

ALLOW_REGISTER

false

Specifies whether to allow user registration.

ALLOW_CREATE_WORKSPACE

false

Specifies whether to allow the creation of new workspaces.

GOOGLE_CLIENT_ID

Empty

The client ID for the Google OAuth application.

GOOGLE_CLIENT_SECRET

Empty

The client secret for the Google OAuth application.

GITHUB_CLIENT_ID

Empty

The client ID for the GitHub OAuth application.

GITHUB_CLIENT_SECRET

Empty

The client secret for the GitHub OAuth application.

ENABLE_EMAIL_PASSWORD_LOGIN

true

Specifies whether to allow login with an email and password.

ALLOWED_OAUTH_DOMAINS

Empty

A comma-separated list of domains allowed to log in via OAuth.

ARMS_ENABLE

false

Specifies whether to enable Application Real-Time Monitoring (ARMS).

ARMS_DIFY_API_APP_NAME

Empty

dify-api component application name on the ARMS monitoring platform

ARMS_DIFY_PLUGIN_APP_NAME

Empty

dify-plugin-daemon application name on the ARMS monitoring platform

ARMS_DIFY_SANDBOX_APP_NAME

Empty

dify-sandbox is the application name for the component on the ARMS monitoring platform

ARMS_REGION_ID

Empty

The region ID for ARMS monitoring (such as cn-hangzhou)

ARMS_LICENSE_KEY

Empty

The license key required for ARMS integration.