Environment Variables
The SignalWire Server SDK reads environment variables for server configuration, authentication, SSL, logging, Relay/REST client credentials, and serverless platform detection. Constructor parameters take precedence over both environment variables and the config file, and the config file takes precedence over environment variables.
Use dotenv to load variables from a .env file during development:
Server
PORT
Server port. Used when no port argument is passed to the constructor.
Authentication
SWML_BASIC_AUTH_USER
Username for HTTP Basic Authentication on all agent webhook endpoints.
When a password is set without a user, the user is signalwire. When the
password is generated, the user falls back to the agent’s name.
SWML_BASIC_AUTH_PASSWORD
Password for HTTP Basic Authentication. Credentials resolve from the
constructor’s basicAuth, then the config file, then these variables. If none
is set, a random password is generated on each startup; it exists only in that
process, and the agent logs a warning.
SIGNALWIRE_SWAIG_SECRET
Secret that signs per-call SWAIG function tokens, used when the agent’s
swaigSecret option isn’t set. Set the same value on every replica, and keep
it across restarts, so a token issued by one process validates on another.
Treat it as a secret.
In production, always set SWML_BASIC_AUTH_PASSWORD explicitly. Auto-generated
passwords change on every restart, which will break SignalWire webhook callbacks
until you update the credentials in your SignalWire dashboard.
SSL / TLS
SWML_SSL_ENABLED
Enable HTTPS for serve() and AgentServer.run(). Accepts true, 1, or
yes. Webhook URLs then use https, on SWML_SSL_DOMAIN when it’s set. When
the certificate or key file is missing, the agent warns and serves HTTP.
SWML_SSL_CERT_PATH
Path to the SSL certificate file (.pem or .crt). Required when
SWML_SSL_ENABLED is set.
SWML_SSL_KEY_PATH
Path to the SSL private key file (.key). Required when
SWML_SSL_ENABLED is set.
SWML_SSL_DOMAIN
Domain name for HSTS headers and URL generation.
SWML_ENFORCE_HTTPS
Build webhook URLs with https even when the agent itself serves HTTP, as it
does behind a proxy that terminates TLS. Only the string "true" is accepted.
SWML_USE_HSTS
Send a Strict-Transport-Security header on HTTPS responses. Once the variable
is set, any value other than "true" turns the header off.
SWML_HSTS_MAX_AGE
max-age, in seconds, of the Strict-Transport-Security header. A value that
isn’t a number is ignored.
Proxy
SWML_PROXY_URL_BASE
Base URL when running behind a reverse proxy (e.g., https://my-agent.example.com).
The agent uses this URL to generate correct webhook URLs in SWML documents.
SWML_PROXY_DEBUG
Enable proxy request debug logging. Only the string "true" is accepted.
SWML_URL_FETCH_USE_PROXY
The SDK’s outbound URL fetches (the spider and web_search skills, for example)
connect directly, ignoring any environment proxy, so each connection can be
checked for private and internal addresses. When set, a request that Node’s
global fetch would send through a proxy goes through it instead, where that
check can’t apply. Use a proxy that restricts destinations itself. Accepts 1,
true, or yes.
SWML_ALLOW_PRIVATE_URLS
Let the SDK’s outbound URL fetches reach private and internal addresses, which
they otherwise refuse. Accepts 1, true, or yes. Set it only when a skill
must reach a host on your own network.
SWML_TRUST_PROXY_HEADERS
Trust proxy headers for auto-detection of the public URL (X-Forwarded-Host
with X-Forwarded-Proto, Forwarded, or X-Original-Host) and for the client
IP that rate limiting uses (X-Forwarded-For, then X-Real-IP). Only the string
"true" is accepted. Enable only when running behind a reverse proxy you
control.
Setting SWML_PROXY_URL_BASE overrides SSL configuration and port settings
for webhook URL generation.
Schema Validation
SWML_SKIP_SCHEMA_VALIDATION
Disable SWML document schema validation. Only the string "true" is accepted (strict equality check).
Useful for performance in production when you trust your SWML output.
Webhook signature validation
SIGNALWIRE_SIGNING_KEY
Your SignalWire Signing Key. When set (or when the signingKey constructor
option is passed), the agent validates the signature on every inbound
webhook and rejects unsigned or mis-signed requests with HTTP 403. Treat it
as a secret.
Security
SWML_ALLOWED_HOSTS
Comma-separated list of allowed Host header values. When unset, or when the
list includes *, no host check is applied. When set, requests with a Host header not in the list
are rejected with HTTP 403. Set to specific domain(s) in production
(e.g., "agent.example.com,api.example.com").
SWML_CORS_ORIGINS
Comma-separated list of allowed CORS origins. A list that includes * allows
every origin. Restrict to trusted origins in production.
SWML_CSRF_PROTECTION
When set to "true", POST requests whose Origin header is not in
SWML_CORS_ORIGINS are rejected with HTTP 403. A request with no Origin
header passes, and nothing is rejected while SWML_CORS_ORIGINS includes *.
Only the string "true" is accepted.
SWML_MAX_REQUEST_SIZE
Maximum request body size in bytes. Default is 1 MB. Requests exceeding this size are rejected with HTTP 413.
SWML_RATE_LIMIT
Rate limit in requests per minute per client. When unset, no rate limit
is applied. When set to a positive integer, clients exceeding the limit
receive HTTP 429. Each client is keyed by its connection address, by the
forwarded address when SWML_TRUST_PROXY_HEADERS is set, or on a serverless
platform by the address the platform reports.
Logging
SIGNALWIRE_LOG_MODE
Logging mode.
"auto"— automatic detection based on environment"off"— disable all logging"stderr"— log to stderr
SIGNALWIRE_LOG_LEVEL
Log level. Case-insensitive; an unrecognized value falls back to "info".
"debug"— verbose output for development and troubleshooting"info"— standard operational messages"warn"— potential issues that do not prevent operation"error"— failures that affect a specific operation
SIGNALWIRE_LOG_FORMAT
Log output format.
"text"— colored human-readable output (default)"json"— structured JSON log lines for log aggregation systems
SIGNALWIRE_LOG_COLOR
Force colored text output on ("true") or off ("false"). When unset, color
is enabled only when writing to a terminal.
AI Chat gateway
SIGNALWIRE_CHAT_GATEWAY_KEY
Publishable key a ChatGateway accepts from the browser widget, used when the
gateway’s key option isn’t set. Without either, the gateway generates a key,
which is only useful to a process that also serves the page.
SIGNALWIRE_CHAT_GATEWAY_SECRET
Key that signs a ChatGateway’s conversation handles, used when the gateway’s
secret option isn’t set. Without either, each process generates its own, and
outstanding handles stop working on restart and across replicas. Treat it as a
secret.
Skills
SIGNALWIRE_SKILL_PATHS
Colon-separated paths to directories containing custom skills. The skill
registry scans these paths in addition to the built-in skills directory, but
only when SWML_SKILL_DISCOVERY_ENABLED is "true".
SWML_SKILL_DISCOVERY_ENABLED
Allow the skill registry to import skills from directories, through
discoverFromDirectory() and the paths in
SIGNALWIRE_SKILL_PATHS. Without it, discovery logs a warning and registers
nothing. Only the string "true" is accepted.
SWML_ALLOW_CUSTOM_HANDLER_CODE
Allow the custom_skills skill to compile and run handler code
from its configuration. Without it, those tools return an error instead of
running. Only the string "true" is accepted.
Relay and REST Client
RelayClient, RestClient, and AIChatClient read these variables. The
three clients agree on the credential variables. RelayClient also reads
SIGNALWIRE_SPACE, so read the warning below before setting it in a process that
uses Relay.
SIGNALWIRE_PROJECT_ID
SignalWire project ID for authentication.
SIGNALWIRE_API_TOKEN
API token for authentication.
SIGNALWIRE_JWT_TOKEN
JWT token for Relay authentication. Alternative to project ID + API token.
SIGNALWIRE_SPACE
Your space hostname, for example your-space.signalwire.com. RestClient uses
it as the REST API host and throws when neither this variable, the host option,
nor SIGNALWIRE_REST_BASE_URL is set. AIChatClient reads the same variable and
accepts either the hostname or the bare space name, your-space, to which it
appends .signalwire.com.
RelayClient connects to relay.signalwire.com by default and needs no space
setting. When SIGNALWIRE_SPACE is set, it connects to that host instead. If
the same process uses REST and Relay, set SIGNALWIRE_RELAY_HOST=relay.signalwire.com
or pass host to RelayClient so the REST setting does not redirect the WebSocket
connection.
SIGNALWIRE_REST_BASE_URL
Full base URL for REST requests (e.g., https://your-space.signalwire.com).
Takes precedence over SIGNALWIRE_SPACE; the host constructor option
takes precedence over both.
SIGNALWIRE_REST_CA_FILE
Path to a PEM file of additional CA certificates trusted for REST connections. Adds trust; it never disables certificate verification.
SIGNALWIRE_RELAY_HOST
Override the Relay WebSocket host. Takes precedence over SIGNALWIRE_SPACE;
the host constructor option takes precedence over both.
SIGNALWIRE_RELAY_SCHEME
WebSocket scheme for the Relay connection, wss or ws.
SIGNALWIRE_RELAY_CA_FILE
Path to a PEM file of additional CA certificates trusted for the Relay WebSocket connection. Adds trust; it never disables certificate verification.
RELAY_MAX_ACTIVE_CALLS
Maximum concurrent calls per RelayClient instance.
RELAY_MAX_CONNECTIONS
Maximum concurrent RelayClient connections per process.
Serverless Platforms
The SDK auto-detects the execution environment from platform-specific variables. You typically do not set these manually — they are provided by the platform runtime.
AWS Lambda
AWS_LAMBDA_FUNCTION_NAME
Lambda function name. Used for URL construction and logging.
AWS_LAMBDA_FUNCTION_URL
Lambda function URL. If not set, constructed from region and function name.
AWS_REGION
AWS region for Lambda execution.
_HANDLER
Lambda environment detection variable. Set automatically by the Lambda runtime.
LAMBDA_TASK_ROOT
Lambda environment detection variable, read alongside
AWS_LAMBDA_FUNCTION_NAME. Set automatically by the Lambda runtime.
Google Cloud Functions
FUNCTION_URL
The function’s URL. When set, webhook URLs use it. Otherwise they are built as
https://<region>-<project>.cloudfunctions.net/<service> from the variables
below.
FUNCTION_TARGET
Cloud Function entry point name, set by the Functions Framework. Without it and
without FUNCTION_URL, the agent builds no Cloud Function URL. Cloud Run sets
K_SERVICE without FUNCTION_TARGET, so a server there isn’t taken for a Cloud
Function.
GOOGLE_CLOUD_PROJECT
Google Cloud project ID used in the built URL. GCP_PROJECT is read when it’s
unset. With neither, webhook URLs use https://localhost:8080.
GCP_PROJECT
Fallback for GOOGLE_CLOUD_PROJECT.
FUNCTION_REGION
Google Cloud region used in the built URL. GOOGLE_CLOUD_REGION is read when
it’s unset.
GOOGLE_CLOUD_REGION
Fallback for FUNCTION_REGION.
K_SERVICE
Service name used in the built URL. Falls back to FUNCTION_TARGET.
GCLOUD_PROJECT
Project ID read only by ServerlessAdapter’s generateUrl().
The agent’s own webhook URLs use GOOGLE_CLOUD_PROJECT.
Azure Functions
FUNCTIONS_WORKER_RUNTIME
Azure Functions environment detection variable.
AZURE_FUNCTIONS_ENVIRONMENT
Azure Functions environment name.
AZURE_FUNCTION_URL
The function’s URL. When set, webhook URLs use it.
WEBSITE_SITE_NAME
Function app name. With AZURE_FUNCTION_NAME, builds the webhook URL
https://<app>.azurewebsites.net/api/<function> when AZURE_FUNCTION_URL
isn’t set. AZURE_FUNCTIONS_APP_NAME is read when it’s unset.
AZURE_FUNCTIONS_APP_NAME
Fallback for WEBSITE_SITE_NAME.
AZURE_FUNCTION_NAME
Function name used in the built webhook URL.
CGI
GATEWAY_INTERFACE
CGI environment detection variable.