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.
Adding Environment Variables
Section titled “Adding Environment Variables”You can manage environment variables through the CLI or the dashboard.
Using the CLI
Section titled “Using the CLI”You can set environment variables using the FastAPI Cloud CLI. See the CLI documentation for detailed instructions.
Using the Dashboard
Section titled “Using the Dashboard”To add environment variables through the web dashboard follow these steps:
- Navigate to your App Details view
- Select Environment Variables option from the sidebar
- Click Add Environment Variable
- Enter the variable name and the value
- For sensitive values, turn on the Secret switch before saving the new variable
- Click Add Environment Variable again to add more variables if needed
- To remove a variable, just click the trash icon next to it
- 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
Generating a Value
Section titled “Generating a Value”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.
Editing Environment Variables
Section titled “Editing Environment Variables”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.
Importing Environment Variables
Section titled “Importing Environment Variables”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.
How to Import
Section titled “How to Import”- Navigate to your App Details view
- Click Environment Variables option
- Click Import .env
- Paste your environment variables in
.envformat into the text area - The dialog will show a count of parsed variables (e.g., “Import (3)”)
- Click the Import button to add the variables to your form
- Review the imported variables and make any needed adjustments
- Click Save Only or Save and Redeploy to persist your changes
Supported Format
Section titled “Supported Format”The import feature supports standard .env file format:
Basic format:
API_KEY=your_api_key_hereDATABASE_URL=postgresql://localhost/mydbDEBUG=trueQuoted values:
API_KEY="value with spaces"DATABASE_URL='single quoted value'Comments:
# Database configurationDATABASE_URL=postgresql://localhost/mydb# API settingsAPI_KEY=your_api_key_hereImport Behavior
Section titled “Import Behavior”- 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
Section titled “Secrets”Secrets are encrypted environment variables designed for sensitive data like API keys, database passwords, and authentication tokens.
How Secrets Work
Section titled “How Secrets Work”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.
Important Notes
Section titled “Important Notes”- 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.
System environment variables
Section titled “System environment variables”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
Section titled “FASTAPICLOUD_DEPLOYMENT_ID”FASTAPICLOUD_DEPLOYMENT_ID=67afec54-c752-4b8f-8cdf-d67dee077e42The universally unique identifier of your FastAPI Cloud deployment. Useful for debugging and identifying your deployment in observability tools.
FASTAPI_PUBLIC_URL
Section titled “FASTAPI_PUBLIC_URL”FASTAPI_PUBLIC_URL=https://myapp.fastapicloud.devThis 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.