Secrets
A runtime gets a secret value one of two ways. Read it with Config.Redacted during construction: the value comes from your .env or a secrets manager when you deploy, and reaches the runtime as an encrypted secret. Or keep it in a DigitalOcean Secret, a set of key-value pairs stored on the team, and read it with ReadSecret.
Read a value with Config
Section titled “Read a value with Config”import * as DigitalOcean from "@alchemy.run/digitalocean";import * as Config from "effect/Config";import * as Effect from "effect/Effect";import * as HttpServerResponse from "effect/http/HttpServerResponse";import * as Redacted from "effect/Redacted";
export default class Api extends DigitalOcean.App<Api>()( "Api", { main: import.meta.url }, Effect.gen(function* () { const stripeKey = yield* Config.Redacted("STRIPE_KEY"); return { fetch: Effect.sync(() => HttpServerResponse.text(Redacted.value(stripeKey).slice(0, 7)), ), }; }),) {}At deploy the value comes from .env and becomes an App Platform SECRET variable, encrypted and hidden in the control panel. On a Function it becomes a default parameter callers can’t override. See Secrets for how Config travels from deploy to run time.
Values from a secrets manager
Section titled “Values from a secrets manager”.env is only the default. A Stack’s secrets option reads the same Config values from a secrets manager instead, like Doppler or Infisical, so production keys never sit in a file on anyone’s machine. Pick the source per stage:
import * as DigitalOcean from "@alchemy.run/digitalocean";import * as Doppler from "@alchemy.run/doppler";import * as Alchemy from "alchemy";import * as Effect from "effect/Effect";import Api from "./src/api.ts";
export default Alchemy.Stack( "MyApp", { providers: DigitalOcean.providers(), state: Alchemy.localState(), secrets: ({ stage }) => stage === "prod" ? Doppler.Secrets({ project: "my-app", config: "prd" }) : Alchemy.Secrets.DotEnv(), }, Effect.gen(function* () { const api = yield* Api; return { url: api.url }; }),);Your code doesn’t change: Config.Redacted("STRIPE_KEY") reads from whichever source the stage uses. See Secret providers.
Keep shared values in a DigitalOcean Secret
Section titled “Keep shared values in a DigitalOcean Secret”A Secret is a named set of key-value pairs on the team. Use one for values several runtimes share, or that someone changes in the control panel:
import * as DigitalOcean from "@alchemy.run/digitalocean";import * as Redacted from "effect/Redacted";
export const Stripe = DigitalOcean.Security.Secret("Stripe", { values: { STRIPE_KEY: Redacted.make("sk_test_...") },});Read it from a runtime
Section titled “Read it from a runtime”const stripe = yield* DigitalOcean.Security.ReadSecret(Stripe);const key = yield* stripe.get("STRIPE_KEY");Provide DigitalOcean.Security.ReadSecretHttp. The values reach the runtime as secrets when it deploys, so it holds no DigitalOcean token; changing them redeploys the runtimes bound to the Secret.
Tokens a runtime needs
Section titled “Tokens a runtime needs”DigitalOcean signs no identity for a running App or Function, so some bindings take a token you create and pass as Config.Redacted: a model access key for Serverless Inference, and a scoped token for Sandboxes, Agent sessions and Insights queries. Create each with only the scopes it needs.