Skip to main content
Environment variables allow you to configure your Edge Compute functions without modifying code. They’re ideal for non-sensitive configuration values like API endpoints, feature flags, and performance settings that you want to manage alongside your function code.

Overview

Environment variables in Edge Compute are:
  • Declared in configuration — Defined in your function’s func.toml
  • Injected at deployment — Available when your function starts
  • Function-scoped — Specific to each function
  • Version controlled — Part of your function’s configuration

Defining Environment Variables

Define environment variables in your func.toml under the [env_vars] section:
[edge_compute]
func_id = "your-function-id"
func_name = "my-function"

[env_vars]
SERVICE_NAME = "data-processor"
VERSION = "1.0.0"
LOG_LEVEL = "info"
DEBUG = "false"
MAX_FILE_SIZE = "10485760"
CACHE_TTL = "3600"
API_BASE_URL = "https://api.example.com"
All values are stored as strings. Parse them to the appropriate type in your code.

Accessing Environment Variables

import os

class Function:
    def __init__(self):
        # Access environment variables
        self.service_name = os.getenv("SERVICE_NAME", "unknown-service")
        self.api_url = os.environ.get("API_BASE_URL")
        self.debug = os.environ.get("DEBUG", "false").lower() == "true"
        self.cache_ttl = int(os.environ.get("CACHE_TTL", "300"))
        self.max_file_size = int(os.getenv("MAX_FILE_SIZE", "10485760"))

    async def handler(self, request):
        return {
            "service": self.service_name,
            "api_configured": bool(self.api_url),
            "cache_ttl": self.cache_ttl,
            "debug": self.debug
        }

Environment Variables vs Secrets

Use environment variables for non-sensitive configuration. For sensitive data like API keys and passwords, use Secrets instead.
FeatureEnvironment VariablesSecrets
StoragePlain text in func.tomlEncrypted in Telnyx infrastructure
ScopeFunction-specificOrganization-wide
Version Control✅ Yes (in git)❌ No (separate secure storage)
Use CaseConfiguration, feature flagsAPI keys, passwords, tokens

When to Use Each

Perfect for non-sensitive configuration:
  • Application settingsLOG_LEVEL, DEBUG_MODE, PORT
  • Feature flagsENABLE_CACHING, MAINTENANCE_MODE
  • Performance tuningMAX_FILE_SIZE, BATCH_SIZE, TIMEOUT
  • Public endpointsAPI_BASE_URL, CDN_URL, WEBHOOK_URL
  • Environment identifiersENVIRONMENT, VERSION, SERVICE_NAME

CLI Management

Manage environment variables by editing your func.toml file directly, then redeploy:
# Edit func.toml to add/update env_vars
vim func.toml

# Deploy function with updated environment variables
telnyx-edge ship
Environment variable changes take effect on the next deployment.

Best Practices

Naming Conventions

Use UPPER_SNAKE_CASE for consistency with standard environment variable conventions:
[env_vars]
# ✅ Good: Descriptive and consistent
SERVICE_NAME = "data-processor"
MAX_FILE_SIZE = "10485760"
DATABASE_TIMEOUT = "30"
ENABLE_CACHING = "true"

# ❌ Avoid: Vague or inconsistent naming
name = "processor"
maxsize = "10485760"

Type Safety

Store all values as strings and parse them in your code:
[env_vars]
MAX_CONNECTIONS = "100"
TIMEOUT_SECONDS = "30"
ENABLE_FEATURE = "true"

Validation and Defaults

Always validate environment variables and provide sensible defaults:
import os

def get_config():
    return {
        'max_file_size': int(os.getenv('MAX_FILE_SIZE', '10485760')),
        'batch_size': max(1, int(os.getenv('BATCH_SIZE', '100'))),
        'timeout': max(1, int(os.getenv('TIMEOUT', '30'))),
        'debug': os.getenv('DEBUG', 'false').lower() == 'true',
    }

Environment-Specific Values

Use descriptive variable names and document expected values:
[env_vars]
# Environment identification
ENVIRONMENT = "production"  # development, staging, production
LOG_LEVEL = "warn"          # debug, info, warn, error

# Feature flags
DEBUG_MODE = "false"
METRICS_ENABLED = "true"

Common Patterns

Feature Flags

[env_vars]
ENABLE_NEW_PROCESSING = "true"
ENABLE_BULK_OPERATIONS = "false"
ENABLE_ADVANCED_LOGGING = "true"
BETA_FEATURES_ENABLED = "false"

Service Configuration

[env_vars]
SERVICE_NAME = "user-auth-service"
SERVICE_VERSION = "2.1.0"
ENVIRONMENT = "production"

API_BASE_URL = "https://api.telnyx.com"
CDN_BASE_URL = "https://cdn.telnyx.com"

Performance Tuning

[env_vars]
MAX_CONNECTIONS = "100"
CONNECTION_TIMEOUT = "30"
READ_TIMEOUT = "60"

BATCH_SIZE = "50"
MAX_RETRIES = "3"
RETRY_DELAY_MS = "1000"

Debugging

Print environment variables for debugging during development:
import os

def debug_env_vars():
    """Print all environment variables for debugging"""
    print("=== Environment Variables ===")
    for key in ['SERVICE_NAME', 'API_BASE_URL', 'DEBUG', 'LOG_LEVEL']:
        value = os.getenv(key, '(not set)')
        print(f"{key} = {value}")
Remove debug logging before deploying to production to avoid exposing configuration details.

Limits

Environment variables are subject to the following constraints:
  • Variable names must contain only letters, numbers, and underscores
  • Variable names are case-sensitive
  • All values are stored and retrieved as strings
For specific size limits on variable names and values, refer to the Edge Compute limits documentation.