Environment variables

https://firebase.google.com/docs/functions/config-env?gen=2nd#env-variables

.env

OPENAI_API_KEY=xxx

or

firebase functions:secrets:set OPENAI_API_KEY

Read from Env

read from inside the cloud function

process.env

read from secret (callable)

const options: CallableOptions = {
    region: "europe-west1",
    secrets: ["OPENAI_API_KEY"],
}

 onCall<RequestPayload, Promise<ResponsePayload>>(
    options,
    async (request) => {
        const openaiKey = process.env.OPENAI_API_KEY

onRequest(
  { secrets: ["OPENAI_API_KEY"] },
  (req, res) => {
	process.env.

debug secrets

gcloud secrets list --project <PROJECT_ID>

deployment

the .env file is not versioned. At deployment, firebase sends the .env file to firebase servers.

v1 (deprecated)

Tell firebase to save a token/key on our behalf so that we can access it by reference in code, without writing the actual key in code and in git as a result.

firebase functions:config:set sendgrid.key="...." sendgrid.template="TEMP"

Read from Env

Firebase exposes the tokens/keys in an object we get through the config() method.

const API_KEY = functions.config().myKey
earlymorning logo

© 2025 - All rights reserved

Environment variables

https://firebase.google.com/docs/functions/config-env?gen=2nd#env-variables

.env

OPENAI_API_KEY=xxx

or

firebase functions:secrets:set OPENAI_API_KEY

Read from Env

read from inside the cloud function

process.env

read from secret (callable)

const options: CallableOptions = {
    region: "europe-west1",
    secrets: ["OPENAI_API_KEY"],
}

 onCall<RequestPayload, Promise<ResponsePayload>>(
    options,
    async (request) => {
        const openaiKey = process.env.OPENAI_API_KEY

onRequest(
  { secrets: ["OPENAI_API_KEY"] },
  (req, res) => {
	process.env.

debug secrets

gcloud secrets list --project <PROJECT_ID>

deployment

the .env file is not versioned. At deployment, firebase sends the .env file to firebase servers.

v1 (deprecated)

Tell firebase to save a token/key on our behalf so that we can access it by reference in code, without writing the actual key in code and in git as a result.

firebase functions:config:set sendgrid.key="...." sendgrid.template="TEMP"

Read from Env

Firebase exposes the tokens/keys in an object we get through the config() method.

const API_KEY = functions.config().myKey