docs/ai_builder/features/secrets.md
Store API keys, tokens, database URLs, and other sensitive configuration in Secrets instead of prompts or source files. Apps receive the values as environment variables at runtime.
import reflex as rx
rx.image(
src="https://web.reflex-assets.dev/docs-preview/ai-builder/platform/app_secret_create.webp",
alt="Adding app secrets in Reflex Build",
class_name="rounded-md h-auto mb-4",
border=f"0.81px solid {rx.color('slate', 5)}",
)
If an app secret and project secret use the same name, the app value overrides the project value for that app. Use project scope for shared development credentials and app scope for values that must differ between apps.
Integration credentials belong in the integration form rather than either general secret scope.
Select Add new variable, then enter an uppercase, descriptive name and its value. For example, use STRIPE_SECRET_KEY rather than KEY.
Tell the agent to read the variable by name without including its value:
Use the STRIPE_SECRET_KEY environment variable for server-side Stripe calls.
Do not expose it in client-side code or logs.
Backend Python code can read it with os.environ:
import os
stripe_secret_key = os.environ["STRIPE_SECRET_KEY"]
Do not read a secret in browser-executed code or send it to the frontend.
Use Raw editor to manage one NAME=VALUE pair per line:
DATABASE_URL=postgresql://user:pass@host:5432/db
STRIPE_SECRET_KEY=sk_test_xxxxx
OPENAI_API_KEY=sk-xxxxxx
rx.image(
src="https://web.reflex-assets.dev/docs-preview/ai-builder/platform/project_secrets_raw_editor.webp",
alt="Managing several secrets with the raw editor",
class_name="rounded-md h-auto mb-4",
border=f"0.81px solid {rx.color('slate', 5)}",
)
The raw editor replaces the complete secret set for the selected scope. Review every line before saving; removing a line deletes that variable from the scope.
Open a secret's action menu:
Project Secrets records rotation information. When the configured secret store supports versioning, Version history can restore an earlier project-secret set. Do not treat version history as a substitute for keeping the current credential in an approved secret manager.
After rotating or deleting a value, revoke the old credential at its provider when applicable and test every affected workflow.
Project permissions independently control who can see secret names, reveal values, and edit secrets. Use the lowest access needed and review Roles & permissions before sharing a project.