Skip to main content
Environment variables let you configure your endpoints without hardcoding credentials or settings in your code. They’re ideal for managing API keys, service URLs, feature flags, and other configuration that changes between development and production.

How environment variables work

Environment variables are set in the Runpod console and are available to your handler at runtime through os.environ. Your handler can read these variables to configure its behavior.

Set environment variables

You can set environment variables in the Runpod console when creating or editing your endpoint:
  1. Navigate to your endpoint in the Runpod console.
  2. Click on the Settings tab.
  3. Scroll to the Environment Variables section.
  4. Add your variables as key-value pairs.
  5. Click Save to apply the changes.
These environment variables will be available to all workers running on your endpoint.

Access environment variables in your handler

You can access environment variables in your handler function at runtime using os.environ.get("VARIABLE_NAME"). For example:
handler.py

Build-time vs runtime variables

There are two types of environment variables:

Build-time variables

Build-time variables are set in your Dockerfile using the ENV instruction. These are baked into your Docker image during the build:
Dockerfile
Build-time variables are useful for setting default configuration values, values that rarely change, and non-sensitive information.

Runtime variables

Runtime variables are set in the Runpod console and can be changed without rebuilding your image. These override build-time variables with the same name: Runtime variables are useful for:
  • API keys and secrets.
  • Environment-specific configuration (dev, staging, prod).
  • Values that change frequently.
  • Sensitive information that shouldn’t be in your image.

Common use cases

API keys and secrets

Store sensitive credentials as runtime environment variables:
handler.py
Never hardcode API keys or secrets in your code. Always use environment variables to keep credentials secure.

S3 bucket configuration

Configure S3 or S3-compatible storage for uploading results:
handler.py
Set these variables in the Runpod console:
  • BUCKET_ENDPOINT_URL: Your bucket endpoint (e.g., https://your-bucket.s3.us-west-2.amazonaws.com)
  • BUCKET_ACCESS_KEY_ID: Your access key ID
  • BUCKET_SECRET_ACCESS_KEY: Your secret access key
The BUCKET_ENDPOINT_URL should include your bucket name in the URL.

Feature flags

Use environment variables to enable or disable features:
handler.py

Model configuration

Configure model parameters without changing code:
handler.py

Best practices

Use defaults

Always provide default values for non-critical environment variables:
handler.py

Validate on startup

Validate critical environment variables when your handler starts:
handler.py

Document your variables

Document the environment variables your handler expects in your README:
README.md

Separate secrets from config

Use different approaches for secrets vs configuration:
  • Secrets: Only set as runtime variables in the Runpod console.
  • Configuration: Can use build-time defaults with runtime overrides.