W
Wasp6mo ago
Ghar

Github actions failing with "OpenAI API key not set"

Tests work in development but failing in Github. Checking doc to determine how to safely provide keys.
[WebServer] [app][err] [ Server!] OpenAI API key not set. Please set the OPENAI_API_KEY environment variable.
[WebServer] [app][err] [ Server!] /home/runner/work/mysponsorapp-wasp/mysponsorapp-wasp/app/src/server/actions.ts:76
[WebServer] [app][err] [ Server!] throw new HttpError(500, "OpenAI API key not set. Please set the OPENAI_API_KEY environment variable.");
[WebServer] [app][err] [ Server!] ^
[app][err] [ Server!]
[WebServer] [app][err] [ Server!]
[WebServer] [app][err] [ Server!] HttpError: OpenAI API key not set. Please set the OPENAI_API_KEY environment variable.
[WebServer] [app][err] [ Server!] at <anonymous> (/home/runner/work/mysponsorapp-wasp/mysponsorapp-wasp/app/src/server/actions.ts:76:9)
[WebServer] [app][err] [ Server!] at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
[WebServer] [app][err] [ Server!] at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
[WebServer] [app][err] [ Server!] at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5) {
[WebServer] [app][err] [ Server!] statusCode: 500
[WebServer] [app][err] [ Server!] OpenAI API key not set. Please set the OPENAI_API_KEY environment variable.
[WebServer] [app][err] [ Server!] /home/runner/work/mysponsorapp-wasp/mysponsorapp-wasp/app/src/server/actions.ts:76
[WebServer] [app][err] [ Server!] throw new HttpError(500, "OpenAI API key not set. Please set the OPENAI_API_KEY environment variable.");
[WebServer] [app][err] [ Server!] ^
[app][err] [ Server!]
[WebServer] [app][err] [ Server!]
[WebServer] [app][err] [ Server!] HttpError: OpenAI API key not set. Please set the OPENAI_API_KEY environment variable.
[WebServer] [app][err] [ Server!] at <anonymous> (/home/runner/work/mysponsorapp-wasp/mysponsorapp-wasp/app/src/server/actions.ts:76:9)
[WebServer] [app][err] [ Server!] at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
[WebServer] [app][err] [ Server!] at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
[WebServer] [app][err] [ Server!] at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5) {
[WebServer] [app][err] [ Server!] statusCode: 500
4 Replies
MEE6
MEE66mo ago
Wohooo @Ghar, you just became a Waspeteer level 1!
kapa.ai
kapa.ai6mo ago
Hi @Ghar. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The error message indicates that the OPENAI_API_KEY environment variable is not set. In Wasp, environment variables can be set in the .env.server file at the root of your project. Here is an example of how to set environment variables in Wasp:
OPENAI_API_KEY=your-openai-api-key
OPENAI_API_KEY=your-openai-api-key
Replace your-openai-api-key with your actual OpenAI API key. However, it's important to note that you should not commit sensitive data like API keys to your version control system. For GitHub Actions, you can set secrets in the repository settings. These secrets are encrypted and can be used in your GitHub Actions workflows. Once you've set the OPENAI_API_KEY secret in your GitHub repository settings, you can use it in your GitHub Actions workflow file like this:
steps:
- name: Run tests
run: npm test
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
steps:
- name: Run tests
run: npm test
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
This way, the OPENAI_API_KEY environment variable will be available to your tests when they run in GitHub Actions. Please note that the information provided is based on general knowledge and practices, as the provided knowledge sources do not contain specific information about setting environment variables in GitHub Actions for a Wasp project. For more information on how to use secrets in GitHub Actions, you can refer to the GitHub Actions documentation (https://docs.github.com/en/actions/reference/encrypted-secrets). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Ghar, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Vinny (@Wasp)
Vinny (@Wasp)6mo ago
Looks like the bot gave good tips. Did you get it working?
Ghar
GharOP6mo ago
Yes perfect - added secrets to github repo. Thanks for checking.
Want results from more Discord servers?
Add your server