Environment variables
Each Convex deployment has its own environment variables. Functions read them with process.env, or with Config in a function written with Effect, and auth.config.ts reads them to find its identity providers. A project also has defaults: values a new deployment of a given type starts with, which it then keeps as its own.
- API_URL
- staging.example.com
- RESEND_API_KEY
- set by Functions
Set variables on a deployment
Section titled “Set variables on a deployment”const secret = yield* Config.Redacted("RESEND_API_KEY");yield* Convex.Functions("Functions", { deployment, rootDir: ".", env: { RESEND_API_KEY: secret },});Alchemy sets env before the push, because auth.config.ts may read it. Values go through Convex’s API, so they stay out of argv.
Values from a secrets manager
Section titled “Values from a secrets manager”.env is only the default source for Config. A Stack can read its secrets from a secrets manager instead, chosen per stage:
import * as Convex from "@alchemy.run/convex";import * as Doppler from "@alchemy.run/doppler";import * as Alchemy from "alchemy";import * as Config from "effect/Config";import * as Effect from "effect/Effect";
export default Alchemy.Stack( "MyApp", { providers: Convex.providers(), state: Alchemy.localState(), secrets: ({ stage }) => stage === "prod" ? Doppler.Secrets({ project: "my-app", config: "prd" }) : Alchemy.Secrets.DotEnv(), }, Effect.gen(function* () { const project = yield* Convex.Project("App"); const deployment = yield* Convex.Deployment("Backend", { project, type: "prod" }); yield* Convex.Functions("Functions", { deployment, rootDir: ".", env: { RESEND_API_KEY: yield* Config.Redacted("RESEND_API_KEY") }, }); }),);The Config.Redacted(...) code doesn’t change. See Secret providers.
Remove a variable
Section titled “Remove a variable”Remove its name from env. Alchemy deletes it after the push succeeds, so one deploy can stop reading a variable in auth.config.ts and drop it. A variable set by hand and never listed is left alone.
If the pushed code still reads it, Convex refuses and the deploy fails with AuthConfigMissingEnvironmentVariable. The next deploy tries again.
Take over a variable set by hand
Section titled “Take over a variable set by hand”A name in env that already holds a different value, set in the dashboard or by another tool, fails the deploy with VariablesOwnedBySomeoneElse. A value the deployment took from the project defaults doesn’t count. Adopt it to overwrite it:
yield* Convex.Functions("Functions", { deployment, rootDir: ".", env: { AUTH_DOMAIN: "https://accounts.google.com" },}).pipe(adopt(true));alchemy deploy --adopt does the same for the whole Stack.
Set project defaults
Section titled “Set project defaults”New deployments of the listed types start with these, including previews that something else creates:
yield* Convex.DefaultEnvironmentVariables("Defaults", { project, deploymentTypes: ["preview"], env: { API_URL: "https://staging.example.com" },});Existing deployments keep their values.