Layer LogoWAVS Docs
WAVS builders handbookComponents

Variables

Components can be configured with two types of variables:

Public variables

These variables can be used for non-sensitive information that can be viewed publicly. These variables are set in the config field of a service manifest. All config values are stored as strings, even for numbers.

To add public variables:

  1. Add the public variables to the config field in the service manifest:
"component": {
"config": {
"api_endpoint": "https://api.example.com", // accessible via host::config_var()
"max_retries": "3" // Config values are always strings
}
}
  1. Access them in the component using host::config_var():
let value = host::config_var("api_endpoint");

Environment keys

Environment keys are private and can be used for sensitive data like API keys. These variables are set by operators in their environment and are not viewable by anyone. These variables must be prefixed with WAVS_ENV_. Each operator must set these variables in their environment before deploying the service. WAVS validates that all environment variables are set before allowing the service to run.

To add private variables:

  1. Create a new .env file in WAVS template:
# copy the example file
cp .env.example .env

Variables can also be set in your ~/.bashrc, ~/.zshrc, or ~/.profile files.

  1. Set the environment variable in your .env file:
# .env file
WAVS_ENV_MY_API_KEY=your_secret_key_here
  1. Access the environment key from a component:
let api_key = std::env::var("WAVS_ENV_MY_API_KEY")?;
  1. Before deploying a service, add the environment key to the env_keys array in the service manifest:
"component": {
"env_keys": [
"WAVS_ENV_API_KEY" // Environment variables the component can access. Must be prefixed with WAVS_ENV_
]
}

Local Execution

When running components locally (raw), use the --config flag to set values in a KEY=VALUE format, comma-separated: --config a=1,b=2.

wavs-cli exec --component <COMPONENT> --input <INPUT> --config api_endpoint=https://api.example.com

Edit on GitHub

On this page