#Can Convex Workflows use Convex ENV vars?
3 messages · Page 1 of 1 (latest)
Hi @elder imp. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Yes, Convex Workflows can use Convex environment variables. Workflows in Convex are implemented as background functions (using the Workflow component), and these functions have access to environment variables via process.env, just like other Convex functions (queries, mutations, actions).
To access environment variables within a workflow handler or any step (such as when calling runAction or runQuery), you simply reference them using process.env.YOUR_ENV_VAR. For example:
export const exampleWorkflow = workflow.define({
args: { name: v.string() },
handler: async (step, args): Promise<string> => {
const apiKey = process.env.MY_API_KEY; // Access your env var here
// Use apiKey in your logic or pass it to actions/queries
const result = await step.runAction(internal.example.exampleAction, { apiKey });
return result;
},
});
This is consistent with how environment variables are accessed in all Convex functions, as described in the documentation: "You can access environment variables in Convex functions using process.env.KEY. If the variable is set it is a string, otherwise it is undefined" Environment Variables.