Skip to content

Environment Variables

Environment variables allow you to configure your application with app-specific settings and secrets that can be accessed from your code at runtime.

You can manage environment variables through the CLI or the dashboard.

You can set environment variables using the FastAPI Cloud CLI. See the CLI documentation for detailed instructions.

To add environment variables through the web dashboard follow these steps:

  1. Navigate to your App Details view
  2. Select Environment Variables option from the sidebar
  3. Click Add Environment Variable
  4. Enter the variable name and the value
  5. For sensitive values, turn on the Secret switch before saving the new variable
  6. Click Add Environment Variable again to add more variables if needed
  7. To remove a variable, just click the trash icon next to it
  8. Choose how to save your changes:
    • Save Only (in the dropdown beside the save button) - Saves changes that will apply on the next deployment
    • Save and Redeploy - Saves and immediately redeploys your app with the new variables
Environment variable form with regular values, a masked secret, and the Save and Redeploy button Environment variable form with regular values, a masked secret, and the Save and Redeploy button

For a new variable with an empty value, click the wand icon in the value field to Generate value. This creates a random 64-character hexadecimal value. It works for both regular variables and secrets; turn on Secret if the value is sensitive.

The generator is available only for new, empty variables. Saved secrets remain masked and do not show the generator.

New environment variable with Secret enabled and a wand icon for generating its value New environment variable with Secret enabled and a wand icon for generating its value

Click Edit to update or remove saved variables. Add Environment Variable and Import .env also enter edit mode directly. Changes are applied only when you save; Cancel discards your edits.

Saved variables are listed alphabetically by name, with integration-managed variables grouped first. New rows stay at the bottom while you edit and are sorted after saving. Hover over the clock icon to see when a saved variable was last updated.

You can bulk-import environment variables from .env files instead of adding them one by one. This is particularly useful when migrating existing applications or setting up multiple variables at once.

  1. Navigate to your App Details view
  2. Click Environment Variables option
  3. Click Import .env
  4. Paste your environment variables in .env format into the text area
  5. The dialog will show a count of parsed variables (e.g., “Import (3)”)
  6. Click the Import button to add the variables to your form
  7. Review the imported variables and make any needed adjustments
  8. Click Save Only or Save and Redeploy to persist your changes
Import Environment Variables dialog with three parsed variables and an Import (3) button
Import Environment Variables dialog with three parsed variables and an Import (3) button

The import feature supports standard .env file format:

Basic format:

Terminal window
API_KEY=your_api_key_here
DATABASE_URL=postgresql://localhost/mydb
DEBUG=true

Quoted values:

Terminal window
API_KEY="value with spaces"
DATABASE_URL='single quoted value'

Comments:

Terminal window
# Database configuration
DATABASE_URL=postgresql://localhost/mydb
# API settings
API_KEY=your_api_key_here
  • Comments are ignored: Lines starting with # are skipped
  • Quotes are removed: Both single and double quotes around values are automatically stripped
  • Validation applies: All imported variables must follow the naming rules (see Important Notes below)
  • Integration with existing variables: Imported variables appear as new additions alongside your existing variables
  • Secrets must be marked manually: Imported variables are not marked as secrets by default. Toggle the secret switch for sensitive values after importing

Secrets are encrypted environment variables designed for sensitive data like API keys, database passwords, and authentication tokens.

When you mark a variable as a secret the value will be encrypted immediately after saving. This value won’t be visible in the dashboard for security reasons but your application can still access it at runtime.

To replace a secret, click Edit, enter a new value, and save. Leaving its value unchanged preserves the existing secret; the masked field does not mean the secret is empty.

You can also identify secrets by the lock icon in the input field.

  • Always use secrets for sensitive data: Mark API keys, database passwords, and other sensitive information as secrets to ensure they’re encrypted.
  • Use UPPERCASE_WITH_UNDERSCORES: Follow the standard convention (e.g., DATABASE_URL, API_KEY).
  • Secrets are immutable type: Variables can only be marked as secrets during creation. You cannot convert existing regular variables to secrets or vice versa.
  • No secret visibility: Secret values cannot be viewed after creation for security reasons.
  • Lost secrets must be replaced: Enter a new value for the existing secret and save it. The previous value cannot be recovered.

FastAPI Cloud automatically sets certain environment variables at runtime, such as platform-specific identifiers and useful framework defaults. All system environment variables can be overridden by custom environment variables.

FASTAPICLOUD_DEPLOYMENT_ID=67afec54-c752-4b8f-8cdf-d67dee077e42

The universally unique identifier of your FastAPI Cloud deployment. Useful for debugging and identifying your deployment in observability tools.

FASTAPI_PUBLIC_URL=https://myapp.fastapicloud.dev

This environment variable is used by FastAPI to generate the server and docs URLs on startup. FastAPI Cloud sets this variable to a URL based on the default app domain or the first configured custom domain, if any.