docs/hosting/secrets-environment-vars.md
Use environment variables for API keys, database URLs, tokens, and other values that must not be committed to source control.
import reflex as rx
Open Secrets in the project sidebar to add, edit, or remove project-level values. Access is controlled by project permissions:
An app can also open Secrets from its more menu to manage values for that app only. An app-level secret overrides a project secret with the same name. Store credentials in Secrets or an integration form, never in a prompt or source file.
For a deployed app, open Deployments, select the app, and go to Settings > Secrets. From this page you can:
NAME=value entries.Enable Sensitive when no team member should be able to view, edit, or delete the stored values. Sensitive mode availability and who can change it depend on the organization's plan and project permissions.
Never expose a real value while preparing screenshots or support material.
rx.image(
src="https://web.reflex-assets.dev/docs-preview/hosting/settings_secrets.webp",
alt="Hosted app secret settings with values concealed",
class_name="rounded-md h-auto mb-4",
border=f"0.81px solid {rx.color('slate', 5)}",
)
Pass a local environment file to the CLI:
reflex deploy --project <project-id> --envfile .env
Or pass an individual value:
reflex deploy --project <project-id> --env OPENAI_API_KEY=<value>
Repeat --env for multiple values. When both are provided, values from --envfile take precedence.
Backend Python code can read a value with os.environ:
import os
database_url = os.environ["ASYNC_DB_URL"]
Some SDKs read standard names automatically, such as OPENAI_API_KEY.
# Keep secrets out of source control
Do not commit `.env` files, paste credentials into Build prompts, or include real values in screenshots and logs.