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. If you want to convert it to a secret and encrypt sensitive values, toggle the Secret switch
  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 - 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

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 button
  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.

If you need to update a secret value, you can do so by entering a new value and saving the changes. The new value will be encrypted and replace the old one.

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: If you lose a secret value, you must delete the variable and create a new one with the correct value.

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.