
Parameter Name | Description |
Variable name | Required. It can only include uppercase and lowercase letters, digits, and special characters limited to @, ., -, ,. The length is restricted to 1 to 64 characters. The variable name cannot be duplicated and cannot be modified after creation. For example, keytest. |
Variable type | Required. It supports String, JSON and Secret types. String: After this option is selected, the input variable value content will be saved as a string. For specific usage, refer to the Edge Functions Referencing Environment Variables or Secret section for the variable type String. JSON: After this option is selected, the input variable value content will be saved as a JSON array. The edge functions will automatically parse the variable value into a JavaScript object without the need to manually call JSON.parse(). For specific usage, refer to the Edge Functions Referencing Environment Variables or Secret section for the variable type JSON. Secret: When this option is selected, the variable can be saved as either a JSON array or a string. Once saved, the variable value will no longer be visible—please keep it secure. For details, see the Edge Functions Referencing Environment Variables or Secret section, under the "Secret" variable type. |
Value | Required. It supports a maximum of 5 KB. For example, if the type is String, enter valuetest as the variable value. If the type is JSON, the variable value will be validated to check if the input content follows the JSON data structure. If it does not, there will be an exception prompt. |

@, ., -, ,, they can be referenced in the form of env.envname. For example, if the environment variable envname is keytest, the way to reference it in edge function code is env.keytest. For specific usage, refer to the section for the variable type String.@, ., -, ,, it can be referenced in the form of env['envname']. For example, if the environment variable envname is test-@.-a, the way to reference it in edge function code is env['test-@.-a'].testString with the value valuetest. The edge function reference is as follows:
// Entry functionaddEventListener('fetch', event => {event.respondWith(handleRequest(event.request));});// Function to handle requestsasync function handleRequest(request) {// Obtain a value from an environment variable, and this environment variable needs to be created and deployed in edge function environment Variables or Secret.const valueFromEnv = env.testString;// Create response.const response = new Response(valueFromEnv, {headers: {'Content-Type': 'text/plain' // Set the response Content-Type.}});// Return the response.return response;}

testJSON, as shown below:
// Entry functionaddEventListener('fetch', event => {event.respondWith(handleRequest(event.request));});async function handleRequest(request) {// Obtain a value from an environment variable, and this environment variable needs to be created and deployed in edge function environment Variables or Secret.const myJsonData = env.testJSON;// Create response body.const response = new Response(JSON.stringify(myJsonData), {headers: {'Content-Type': 'application/json'}});// Return the response.return response;}

testSecret, Note: The variable value will no longer be visible after saving, please keep it safe. As shown below:
// Entry functionaddEventListener('fetch', event => {event.respondWith(handleRequest(event.request));});async function handleRequest(request) {// Obtain a value from an environment variable, and this environment variable needs to be created and deployed in edge function environment Variables or Secret.const secretData = env.testSecret;// Create response body.const response = new Response(secretData, {headers: {'Content-Type': 'application/json'}});// Return the response.return response;}



Feedback